Skip to main content

Zova Python Bindings

This package contains the source-first Python bindings for Zova.

It is a PyO3/maturin extension backed by the safe Rust zova binding. It does not wrap the C ABI directly with ctypes or cffi. The native build still uses Zova's C ABI underneath through the Rust zova-sys crate, so Python gets the same records/objects/vectors foundation without reimplementing the ABI ownership rules.

Contents

  1. How It Fits
  2. Install
  3. Local Development
  4. What It Covers
  5. Savepoints
  6. Operational Safety
  7. Extensions
  8. App Events
  9. Objects
  10. Vectors
  11. Graphs
  12. Bound Stores
  13. SQL-Native Vector Search

How It Fits

Python users import zova. The extension is built with PyO3 and reuses the safe Rust binding, which in turn links Zova's C ABI.

flowchart LR
    App["Python app"]
    PyPkg["zova Python package"]
    PyO3["PyO3 extension"]
    Rust["Rust zova crate"]
    CABI["libzova_c.a"]
    File["local .zova file"]

    App --> PyPkg
    PyPkg --> PyO3
    PyO3 --> Rust
    Rust --> CABI
    CABI --> File

Install

After the Python package is published to PyPI:

python -m pip install zova

The v0.21 Python package is source-first. It builds the PyO3 extension locally through maturin and Cargo, and the Rust crates zova and zova-sys must be available on crates.io first. Users need Python 3.10 or newer, Rust/Cargo, and a working C compiler/linker. Zig is only needed when developing Zova itself or regenerating the bundled native snapshot.

No official platform wheel matrix is promised in v0.21.

Local Development

From bindings/python:

uv run --isolated --with maturin --with pytest maturin develop
uv run --isolated --with pytest python -m pytest

The native build uses maturin, Cargo, and the Rust zova crate. Users do not need to locate a shared C library manually.

The Python API is pre-1.0 and may still change alongside the Rust binding.

What It Covers

The Python package exposes database lifecycle, conversion, prepared SQL statements, transactions, explicit vacuum, backup/compact/restore, objects, streaming object writes, vectors, SQL-native vector search, graphs, bundled extension lifecycle, same-process app events, context managers, and Zova status exceptions.

One Python Database object owns one native handle. The native C ABI serializes calls on that handle, so one handle is safe but not parallel. Open additional database handles when an application needs independent concurrent connections; SQLite locking rules still apply across handles. PyO3 classes remain unsendable in this release even though the native C ABI serializes its own calls.

Use Database.open(path, read_only=True) for read-only handles, and Database.set_busy_timeout(milliseconds) when an application wants SQLite to wait briefly on cross-handle contention. No nonzero timeout is installed by default.

Use Database.last_insert_rowid(), Database.changes(), Database.total_changes(), and Statement.column_name(index) for normal application SQL record helpers. They do not expose or stabilize Zova's private _zova_* tables.

Savepoints

Use explicit savepoints for partial rollback inside one database connection:

with zova.Database.open("app.zova") as db:
    db.begin_immediate()
    db.savepoint("attach_file")
    db.exec("insert into attachments(filename) values ('draft.txt')")
    db.rollback_to_savepoint("attach_file")
    db.release_savepoint("attach_file")
    db.commit()

Savepoint names are strict ASCII identifiers: 1-64 bytes, first byte [A-Za-z_], remaining bytes [A-Za-z0-9_], and no case-insensitive _zova_ prefix. rollback_to_savepoint() keeps the savepoint active; release_savepoint() removes it. An inner released savepoint can still be undone by rolling back an outer transaction or savepoint.

Use savepoint_context() when you want rollback cleanup tied to a with block:

with db.savepoint_context("attach_file") as scoped_db:
    scoped_db.exec("insert into attachments(filename) values ('draft.txt')")

On normal exit the context releases the savepoint. On exception it rolls back, releases, and then re-raises the original exception when cleanup succeeds.

Operational Safety

Use backup_to() for a faithful snapshot, compact_to() for a space-reclaiming copy, and restore_backup() to copy a backup into a new destination file. Destinations must be .zova paths and are never overwritten.

with zova.Database.open("app.zova") as db:
    db.backup_to("app.backup.zova")
    db.compact_to("app.compact.zova")

zova.restore_backup("app.backup.zova", "app.restored.zova")

By default, each operation verifies the destination after copying. Pass verify=False only when you will verify separately, for example with zova check --deep.

Diagnostic recovery commands such as zova doctor, zova salvage --dry-run, and zova salvage <source> <destination> are CLI-first. In v0.21, CLI salvage copies valid core data and uses extension salvage hooks for extension-owned storage. The Python package does not expose typed doctor/salvage report APIs yet, and library code should not parse the human text output as a stable binding contract.

Extensions

Python exposes lifecycle methods for extensions already present in the current process registry. The default registry includes bundled extensions such as trgm, so Python applications can install, list, check, and drop trgm directly. App-registered extension authoring and dynamic .zovaext loading remain native Zig/CLI-only in v0.21.

See ../../docs/extensions.md for the current host contract and trust model. A fuller records/objects/vectors/graphs example lives in examples/extensions.py.

with zova.Database.open("app.zova") as db:
    db.install_extension("trgm")
    info = db.extension_info("trgm")
    assert info.storage_prefix == "_zova_ext_trgm_"
    db.check_extensions()

    with db.prepare(
        "select zova_trgm_put('messages', ?1, 'record', 'messages', ?2, ?3)"
    ) as stmt:
        stmt.bind_text(1, "message:123")
        stmt.bind_text(2, "123")
        stmt.bind_text(3, "attachment upload failed")
        assert stmt.step() == zova.Step.ROW

    with db.prepare(
        """
        select document_id, score
        from zova_trgm_search
        where index_name = 'messages'
          and query = ?1
          and "limit" = 10
        order by rank
        """
    ) as stmt:
        stmt.bind_text(1, "attachement failed")

App Events

Use listen / notify for same-process storage workflow notifications. They are explicit, in-memory, local to one open Database handle, and delivered only after the surrounding Zova transaction commits. Rollback discards pending notifications.

with zova.Database.open("app.zova") as db:
    with db.listen("message:123:attachments") as sub:
        db.begin_immediate()
        db.exec("insert into attachments(message_id, name) values (123, 'photo.jpg')")
        db.notify("message:123:attachments", "changed")
        db.commit()

        note = sub.try_receive()
        if note is not None:
            print(note.channel, note.payload)

SQL zova_notify(...) follows the same transaction rules when the surrounding transaction/savepoint was opened through Zova helpers; raw SQL transaction scopes are rejected because Zova cannot track their notification lifetime.

Event delivery is queue-only in v0.18: no callbacks, no blocking receive, no cross-process delivery, no replay after restart, and no automatic logging of SQL, object, vector, or graph mutations. Each subscription queue holds 1024 notifications and drops the oldest entries on overflow; the next received notification reports how many were dropped before it.

Objects

The Python binding exposes Zova objects as content-addressed byte values while keeping application metadata in normal SQL tables.

import zova

with zova.Database.create("app.zova") as db:
    db.exec(
        "create table attachments("
        "id integer primary key, "
        "filename text not null, "
        "object_id blob not null)"
    )

    object_id = db.put_object(b"hello from Zova")

    with db.prepare("insert into attachments(filename, object_id) values (?1, ?2)") as stmt:
        stmt.bind_text(1, "hello.txt")
        stmt.bind_blob(2, bytes(object_id))
        stmt.step()

    assert db.read_object_range(object_id, 0, 5) == b"hello"

For large inputs, use ObjectWriter so the full object does not have to be held in memory by the caller:

with db.object_writer() as writer:
    writer.write(b"chunk one")
    writer.write(b"chunk two")
    object_id = writer.finish()

If a writer leaves the context without finish(), it is cancelled and any unreferenced chunks written by that writer are cleaned up. Writer operations follow Zova's object transaction policy in single-file mode. When an object store is bound, object writes participate in the same Zova transaction/savepoint scope through SQLite ATTACH.

Loose chunks and assembly are also exposed for receive-side workflows: applications track transfer state in their own SQL tables, call put_object_chunk() for verified chunks, then call assemble_object_from_chunks() when the manifest is complete.

Vectors

The Python binding exposes Zova vectors with the same model as the Rust binding: Zova stores numeric vectors in named collections, while application metadata stays in normal SQL tables.

import zova

with zova.Database.create("vectors.zova") as db:
    db.exec(
        "create table chunks("
        "id text primary key, "
        "document_id text not null, "
        "text text not null, "
        "vector_id text not null)"
    )

    db.create_vector_collection(
        "chunks",
        zova.VectorCollectionOptions(2, zova.VectorMetric.L2),
    )
    db.put_vectors(
        "chunks",
        [
            zova.VectorInput("chunk:1", [0.0, 0.0]),
            zova.VectorInput("chunk:2", [1.0, 0.0]),
        ],
    )

    db.exec(
        "insert into chunks(id, document_id, text, vector_id) values "
        "('c1', 'doc-a', 'first chunk', 'chunk:1'), "
        "('c2', 'doc-a', 'near chunk', 'chunk:2')"
    )

    results = db.search_vectors_in(
        "chunks",
        [0.0, 0.0],
        ["chunk:1", "chunk:2"],
        2,
    )
    for result in results:
        with db.prepare("select text from chunks where vector_id = ?1") as stmt:
            stmt.bind_text(1, result.id)
            stmt.step()
            print(result.id, result.distance, stmt.column_text(0))

Search is exact and lower distance is better. Candidate-filtered searches skip missing ids and deduplicate duplicate candidates. Search-by-id excludes the source vector. Threshold variants are inclusive, and dot-product thresholds may be negative because dot distance is -dot_product.

Deleting a vector collection removes Zova's private vector rows only. User SQL metadata rows that reference vector ids are application-owned and remain in place.

Graphs

Graphs store relationship topology while application metadata stays in SQL tables, objects, and vectors. Apps provide stable node IDs and can point nodes at records, objects, object chunks, vectors, entities, facts, concepts, or external references.

db.create_graph(zova.DEFAULT_GRAPH_NAME)
db.put_graph_node(
    zova.GraphNodeInput(
        zova.DEFAULT_GRAPH_NAME,
        "message:1",
        "message",
        zova.GraphTargetType.RECORD,
        "messages",
        "1",
    )
)
db.put_graph_node(
    zova.GraphNodeInput(
        zova.DEFAULT_GRAPH_NAME,
        "entity:zova",
        "entity",
        zova.GraphTargetType.ENTITY,
        None,
        "zova",
    )
)
db.put_graph_edge(
    zova.GraphEdgeInput(
        zova.DEFAULT_GRAPH_NAME,
        "message:1",
        "mentions",
        "entity:zova",
    )
)

Use graph_neighbors() for one-hop expansion and graph_walk() for bounded directed walks. Zova validates object, chunk, and vector targets it owns, but arbitrary SQL row existence remains the application's job. Node IDs may contain sensitive app identifiers, so choose export-safe IDs when files may leave the app.

SQL-native graph helpers are available through ordinary prepared statements:

with db.prepare(
    "select m.body "
    "from zova_graph_neighbors as g "
    "join messages as m on m.graph_node_id = g.node_id "
    "where g.graph_name = 'default' "
    "and g.source_node_id = 'message:1' "
    'and g."limit" = 20 '
    "order by g.rank"
) as stmt:
    ...

Use zova_graph_neighbors for one-hop joins and zova_graph_walk for bounded directed walks with depth, predecessor_node_id, and edge_type columns.

Bound Stores

In v0.21, a .zova file may be bound to one object store and one vector store through the native Zig API or CLI. The Python object and vector methods above transparently use those stores after Database.open. Store create/bind/unbind/split management is not exposed as a Python API yet.

Zova registers SQL vector functions and the zova_vector_search virtual table on Zova database connections. Bind query vectors as little-endian f32 blobs with encode_f32_le():

query = zova.encode_f32_le([0.0, 0.0])

with db.prepare(
    "select c.id, zova_vector_distance('chunks', c.vector_id, ?1) as distance "
    "from chunks as c "
    "where c.document_id = 'doc-a' "
    "order by distance "
    "limit 10"
) as stmt:
    stmt.bind_blob(1, query)

Row-to-row distances use zova_vector_distance_by_id(collection, vector_id, source_vector_id). Collection-wide SQL search uses zova_vector_search:

with db.prepare(
    "select c.text, s.distance "
    "from zova_vector_search as s "
    "join chunks as c on c.vector_id = s.vector_id "
    "where s.collection = 'chunks' "
    "and s.query_vector = ?1 "
    "and s.top_k = 10 "
    "order by s.rank"
) as stmt:
    stmt.bind_blob(1, query)

Python's built-in sqlite3 module opens an ordinary SQLite connection and does not automatically register Zova's SQL functions or virtual table. Use zova.Database for SQL-native vector search in this binding. A future SQLite loadable extension may make the SQL surface available to external SQLite connections.

Metadata

Release files for zova 0.21.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zova 0.21.1
File Size Uploaded
zova-0.21.1.tar.gz 4.3 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for zova 0.21.1
File
zova-0.21.1-cp312-cp312-manylinux_2_36_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.36+ x86-64 Details
zova-0.21.1-cp312-cp312-manylinux_2_36_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.36+ ARM64 Details
zova-0.21.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
zova-0.21.1-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details
zova-0.21.1-cp310-cp310-manylinux_2_36_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.36+ x86-64 Details
zova-0.21.1-cp310-cp310-manylinux_2_36_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.36+ ARM64 Details
zova-0.21.1-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
zova-0.21.1-cp310-cp310-macosx_10_12_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.12+ x86-64 Details

Total release size: 20.1 MB

Release files / zova-0.21.1.tar.gz

Download URL zova-0.21.1.tar.gz
Size 4.3 MB
Tags Source
SHA-256 checksum
How to use checksums
ec10a9076ce547a9b3da432481b6636652acff7ef06655bcf458daa701cdf27d
BLAKE2b-256 checksum
How to use checksums
7eb1e8347c04030ef6270a1a441a41ccfc9f8df89a288abd35070bd92bed0eb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zova-0.21.1-cp312-cp312-manylinux_2_36_x86_64.whl

Download URL zova-0.21.1-cp312-cp312-manylinux_2_36_x86_64.whl
Size 2.1 MB
Tags CPython 3.12 Linux glibc 2.36+ x86-64
SHA-256 checksum
How to use checksums
a74f7c5c2c850505d9465a8790c21acc7dca3ec6c72848941dcc7bee2ce3d8f5
BLAKE2b-256 checksum
How to use checksums
d707c2c9ccdeeaaa305b57e462c49de7f63960e49f8ea3591dd2fa7e513835d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zova-0.21.1-cp312-cp312-manylinux_2_36_aarch64.whl

Download URL zova-0.21.1-cp312-cp312-manylinux_2_36_aarch64.whl
Size 2.0 MB
Tags CPython 3.12 Linux glibc 2.36+ ARM64
SHA-256 checksum
How to use checksums
5ba328cb81b41cb9a8ee6770fe0487fb07469d01652fb1c3c4f4b2227850d98e
BLAKE2b-256 checksum
How to use checksums
0e80e0efe5afb32ef07cd367c80120c53250b01900de2e17033c079961547c3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zova-0.21.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL zova-0.21.1-cp312-cp312-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7065cf7400b04040cf45eb8fceb296c536e154ff792eb0c4a01d741940a6f9ba
BLAKE2b-256 checksum
How to use checksums
1aefbf9a9d8763038833d302a597c7d7abef5561ca4b46ddc904059f46c870b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zova-0.21.1-cp312-cp312-macosx_10_12_x86_64.whl

Download URL zova-0.21.1-cp312-cp312-macosx_10_12_x86_64.whl
Size 1.9 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a37eb12888cafb573a95340fcabdacbea710c88c2b9c29c0eda9dbda91a6f9b4
BLAKE2b-256 checksum
How to use checksums
67c55e1b5e56267278ba3a80bce5e95eb99f66f740a8b6ce1877179226bb1a1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zova-0.21.1-cp310-cp310-manylinux_2_36_x86_64.whl

Download URL zova-0.21.1-cp310-cp310-manylinux_2_36_x86_64.whl
Size 2.1 MB
Tags CPython 3.10 Linux glibc 2.36+ x86-64
SHA-256 checksum
How to use checksums
e08d939a2c062c33829b07aaa26d8563ad63f16a23befa38e5d930db5ed92d64
BLAKE2b-256 checksum
How to use checksums
1c3529218dca3e818f580f0eb0f451f09b9b20a80c1bd7b606a281b16130aa35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zova-0.21.1-cp310-cp310-manylinux_2_36_aarch64.whl

Download URL zova-0.21.1-cp310-cp310-manylinux_2_36_aarch64.whl
Size 2.0 MB
Tags CPython 3.10 Linux glibc 2.36+ ARM64
SHA-256 checksum
How to use checksums
d22d8d5bcd86761a57301c1919f8fa7944f47f7657b56a5c76f42d7cafae6c2d
BLAKE2b-256 checksum
How to use checksums
420fd72a222d2a6b0c7cd4f338ec4465d92847fe72b4564b47c5d3e62eaf009d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zova-0.21.1-cp310-cp310-macosx_11_0_arm64.whl

Download URL zova-0.21.1-cp310-cp310-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a5ef4e1d1fcb0b3a34bb8295ef5ff8a43bbf8577391012462fd91ee0f44099d2
BLAKE2b-256 checksum
How to use checksums
dba56760d38634ae281e4cc940265ba1c42a12c31bdeafee993e8cf471ca20c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / zova-0.21.1-cp310-cp310-macosx_10_12_x86_64.whl

Download URL zova-0.21.1-cp310-cp310-macosx_10_12_x86_64.whl
Size 1.9 MB
Tags CPython 3.10 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9ea8176ac16d5367c487e108051b70a0f0d86999eaec80d480db466995bb925c
BLAKE2b-256 checksum
How to use checksums
bf391282bcd9c44172e752c3998d9754a8e4d2b8ecda62a8ae304f73d56eaa77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page