Skip to main content

itzma for Python

Python bindings for Itzma, vector search with an object store as the only durable state. Itzma runs inside your process: open a namespace once and keep the handle warm in memory, while S3, GCS, Azure or a local directory holds the data.

Install

pip install itzma               # or: uv add itzma
pip install "itzma[pyarrow]"    # Arrow input and output through pyarrow

Wheels cover macOS (Apple silicon and Intel) and Linux (x86_64 and aarch64, glibc and musl), Python 3.10 and later. Elsewhere pip builds from the source distribution, which needs Rust.

Install from source

You need Rust (see rust-version in the root Cargo.toml) and uv.

make py-dev      # creates py-itzma/.venv and builds the extension into it
make py-test     # runs the Python tests

To use it from another project, build a wheel with uv run --project py-itzma maturin build --release and install that.

Quick start

import numpy as np
import itzma
from itzma import attr

# or "file:///var/lib/itzma", "s3://bucket/prefix", "gs://bucket/prefix", "az://container/prefix"
store = itzma.Store("memory://")
schema = itzma.Schema(
    dim=4,
    metric=itzma.Metric.COSINE,
    attrs={"tag": itzma.AttrType.STRING, "year": itzma.AttrType.NUMBER},
)
ns = itzma.Namespace.create(store, "docs", schema)

ns.upsert(
    [
        {"id": "a", "vector": [1, 0, 0, 0], "attrs": {"tag": "news", "year": 2024}},
        {"id": "b", "vector": [0, 1, 0, 0], "attrs": {"tag": "blog", "year": 2021}},
    ]
)

hits = ns.query([0.9, 0.1, 0, 0], top_k=5, filter=attr("year") >= 2022)
print(hits.ids, hits.distances)
print(hits.to_polars())  # id, distance, then one typed column per declared attribute

More runnable scripts are in examples/.

Writes take three shapes:

ns.upsert(rows)  # list of dicts
ns.upsert(ids=ids, vectors=matrix, attrs=attr_dicts)  # numpy (any float dtype)
ns.upsert(df)  # pyarrow, Polars or DuckDB table

A big unkeyed write is split into batches. If one fails, the exception's last_seq tells you how far it got. Pass key="..." to make a write idempotent; a retry passes the same key and retry_from= the sequence number it started from. A key names one batch: reusing it for different documents raises KeyConflict, even when the batch is the same size.

Filters are built from attr(name), with comparison operators or the matching methods:

(attr("tag") == "news") & (attr("year") >= 2022)
attr("tag").isin(["news", "blog"]) | attr("tag").starts_with("dev")
~(attr("year") < 2000)
attr("year").between(2020, 2024)  # a chained 2020 <= attr("year") <= 2024 raises
attr("tag") == None  # is_null()

Wrap each comparison in parentheses: & and | bind tighter than == and >=. Leaving them out raises a TypeError that says so. A comparison with a missing or null field is false, and ~ flips it, so ~(attr("tag") == "x") also matches documents with no tag.

ns.filter(where, limit=100, after=None) pages through matching documents in id order with no vector. ns.query_sparse(terms, top_k) ranks by the dot product of sparse (term id, weight) vectors.

Keeping it compacted and indexed

Writes land in a log that queries also read. Something has to fold it into segments and build indexes, and by default the handle does it for you: open and create start a background loop that runs maintain and the index builds every minute.

If several processes open the same namespace, only one of them does the work. A small lease object in the namespace says which; the others check it every 15 seconds, and if the one working goes away, another takes over within about a minute. The first run comes a full minute after a loop takes the lease, so a short script that opens, writes and exits never pays for a compaction.

To change the settings, pass your own:

from datetime import timedelta

ns = itzma.Namespace.open(
    store,
    "docs",
    maintenance=itzma.Maintenance(every=timedelta(minutes=5), tail_objects=128),
)
ns.maintainer.role  # "leader" or "follower"

To turn it off, pass maintenance=None. Do that if you already run maintain from cron or a job of your own: two maintainers waste work, though they never damage anything.

You can still call ns.maintain(), ns.compact(), ns.index() and ns.gc() yourself, or start a loop by hand, which takes no lease and runs its first pass at once:

m = ns.start_maintenance(timedelta(seconds=60))  # replaces the automatic loop
...
m.stop()  # or ns.close()

ns.index() builds HNSW by default; pass kind="sq8" for SQ8, which reads only the partitions a query probes and suits uncached reads. ns.index_sparse() builds the sparse inverted index.

Errors are logged to the itzma.maintenance logger and kept in last_error; the loop keeps going. A file:// store has no conditional update, so compaction and indexing fail there with StoreError, and the automatic loop logs that once and stops. Use S3, GCS, Azure or memory:// for maintenance.

In a web server

Open each namespace once per process and share the handle across requests. Every call releases the GIL, and the async methods never block the event loop.

FastAPI:

from contextlib import asynccontextmanager
from fastapi import FastAPI
import itzma


@asynccontextmanager
async def lifespan(app: FastAPI):
    store = itzma.Store("s3://my-bucket/itzma", region="us-east-1")
    # Maintenance starts on its own; see "Keeping it compacted and indexed".
    app.state.ns = await itzma.AsyncNamespace.open(
        store, "docs", cache=itzma.Cache(ram_bytes=2 << 30)
    )
    yield
    app.state.ns.close()


app = FastAPI(lifespan=lifespan)


@app.post("/search")
async def search(vector: list[float]):
    hits = await app.state.ns.query(vector, top_k=10)
    return [{"id": h.id, "distance": h.distance} for h in hits]

Django or Flask under gunicorn: open the namespace in each worker, not in the master. With --preload, open it in a post_fork hook or lazily on first use:

# gunicorn.conf.py
def post_fork(server, worker):
    import myapp.search

    myapp.search.ns = itzma.Namespace.open(itzma.Store("s3://my-bucket/itzma"), "docs")

A handle opened before a fork refuses to work in the child and says so. Itzma keeps one tokio runtime per process and builds a fresh one in each child.

Settings

  • S3. Region and credentials come from the AWS SDK's usual chain: AWS_* environment variables, ~/.aws profiles, web identity, then the container or instance role. The region falls back to us-east-1. Keywords override them: region, endpoint, access_key_id, secret_access_key, session_token, allow_http (for a local MinIO). env=False ignores the environment and profiles; with no keys it then uses the instance role. Reading a missing object needs s3:ListBucket, or S3 answers 403 instead of 404.
  • GCS. gs://bucket/prefix uses Google's default credentials (Workload Identity on GKE and Cloud Run, or gcloud auth application-default login). For an emulator, pass endpoint and control_endpoint (the gRPC one) together, and anonymous=True to send no credentials.
  • Azure. az://container/prefix with account. credential picks how to sign in: "managed_identity" (the default), "workload_identity", "developer_tools" (az login) or "anonymous"; or pass sas_token instead. endpoint overrides https://<account>.blob.core.windows.net; token credentials need https, so an emulator such as Azurite takes a SAS token.
  • Each keyword is refused on a URL whose scheme does not use it.
  • Cache. itzma.Cache(ram_bytes=..., nvme_dir=..., nvme_bytes=...) keeps segment and index bytes in RAM and optionally on a local disk. The manifest is never cached, so a write is visible to the next query either way.
  • Large loads. An Arrow table or stream (pyarrow, Polars, DuckDB, anything with __arrow_c_stream__) is read one record batch at a time and written in chunks of about target_bytes (32 MiB by default), with depth (2) encoded chunks waiting at most, so a load of any size runs in bounded memory. If it fails part way, the error carries first_seq, last_seq and rows_written; resume an unkeyed load from rows_written. With key=, chunk n is written under "<key>#<n>", so the key can be at most 107 bytes, and a retry with retry_from=e.first_seq writes only the missing chunks. Don't give a plain keyed write a key of the form <load key>#<number>: chunk keys share that space. A NaN in an Arrow number column raises InvalidAttrs. target_bytes and depth are checked for every input (0 is refused) but only Arrow input uses them.
  • Staleness. staleness= (seconds or a timedelta) on create and open lets queries use a view of the namespace up to that old, so a warm query skips the manifest read and the WAL listing. The handle's own writes are always visible; other writers' writes show up within the bound. None, the default, reads the manifest on every query, and so does 0.
  • IO gate. itzma.Store(url, gate=itzma.Gate()) bounds the reads in flight through the store: one gate for queries (64 MiB and 256 requests by default) and a smaller one for maintenance (16 MiB), shared by every namespace opened from that Store, so a merge cannot take the reads queries need. Writes and listings are not gated. There is no gate unless you pass one, and the defaults are starting points, not measurements.
  • Read budget. read_budget= caps the bytes one query or compaction may read (1 GiB by default). Going over raises ReadBudgetExceeded.
  • Threads. itzma.configure(worker_threads=n) sets the runtime's thread count; call it before anything else. itzma.configure(cpu_threads=n, maintenance_cpu_threads=m) sizes the two compute pools that queries, decoding and index builds run on (default every core for queries, a quarter of them for maintenance); call it before the first query or build.

Errors

Everything raises a subclass of itzma.ItzmaError: InvalidInput (and its subclasses InvalidVector, InvalidAttrs, InvalidQuery, BatchTooLarge), NamespaceExists, NamespaceNotFound, ReadBudgetExceeded, KeyConflict, Contention, FormatTooNew, FormatTooOld, Corrupt and StoreError. The useful details are attributes, for example e.expected and e.got on InvalidVector.

Metadata

Release files for itzma 0.3.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 itzma 0.3.1
File Size Uploaded Provenance Actions
itzma-0.3.1.tar.gz 718.9 kB With provenance Details for itzma-0.3.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for itzma 0.3.1
File Actions
itzma-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for itzma-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl
itzma-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for itzma-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl
itzma-0.3.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for itzma-0.3.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
itzma-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for itzma-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
itzma-0.3.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for itzma-0.3.1-cp310-abi3-macosx_11_0_arm64.whl
itzma-0.3.1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for itzma-0.3.1-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 94.7 MB

Release files / itzma-0.3.1.tar.gz

Download URL itzma-0.3.1.tar.gz
Size 718.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f4015f89efcd33adf9bb5ef7bcdb8e958e09da5979a13cd48e8cde65ee9e518a
BLAKE2b-256 checksum
How to use checksums
82b28033d732c899ddcbe5d3f6dcf204f6f86605121e20203fe3ad5306fc996b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / itzma-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL itzma-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 16.5 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
26ce3ec4ba178df7ede12ded50cc4de9fbd8b9bbcd79310c4c9b8f41ddebe2d4
BLAKE2b-256 checksum
How to use checksums
9b5ceecd67dfbb8969c5033af9a0d17dddd742281f2d31940d1cf41168075488
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / itzma-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL itzma-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 16.0 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
05e72b332ed67de56164dd356da663423071886b2da983622a6004c028d3f1ec
BLAKE2b-256 checksum
How to use checksums
a742583d587c23d91ce7fdd4a9e9f3c2baec2a2ed3cd57b0f53d6f9e8dc48530
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / itzma-0.3.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL itzma-0.3.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 16.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
cbe38bccbffc43b5fe16bdc4dffad6c7966744c2a34f234bd0a1714fa11544fa
BLAKE2b-256 checksum
How to use checksums
350f872a4597105ac40fe9d63449392bb3f8bd5ef7481c140d3d5932a4e97dec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / itzma-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL itzma-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 15.8 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
c22dcffae36d434bffc2e5371944a051fbc8a811fc365831fa1875bf84a07281
BLAKE2b-256 checksum
How to use checksums
52647a08dd3ebf15fa93181b12173a46dde4de7a4c0c01688e80b3b5e8930213
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / itzma-0.3.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL itzma-0.3.1-cp310-abi3-macosx_11_0_arm64.whl
Size 14.2 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c247b5ba1eced681df4ee97854480c440b4f62b89fe5144428b424117cd7790b
BLAKE2b-256 checksum
How to use checksums
185253fb0431826a4825c722b7c2565e339efeaeb69b833123267da58627e65b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / itzma-0.3.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL itzma-0.3.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 15.4 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
7d5b7025919905f1cff7e695d6b4685795afd6fb0a1a1781905cfd4172fae33f
BLAKE2b-256 checksum
How to use checksums
f9e5bd4bee4a6bd00db1900888846ac0bd579f2488b6d8ab3c066df10c9b50d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for itzma 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 7 files in this release have been uploaded with provenance metadata.

Select from 7 files

Attestation for itzma-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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