Skip to main content Switch to mobile version Pre-release This release is a pre-release and may not be stable for production use.
Kerno: an embedded database of units, revisions and relations, for AI memory
pip install kernodb==1.0.0a5 Copy PIP instructions
Python bindings for Kerno: an embedded, local-first database of units (typed records), their revisions (every change is kept), the relations between them, and queries over all three. It runs inside your process and keeps its data in a directory on disk. There is no server.
The package is kernodb; the module you import is kerno.
Alpha (1.0.0a5). It does not open a database written by 1.0.0a4 or any earlier alpha (see Upgrading), and the keyword index is opt-in per type. The on-disk format is frozen, the API is not. Expect breaking changes between alpha releases. See the changelog.
Guides: Kerno as a revisioned history next to another database, one unit per entity, keyed by a logical key, and the coverage of the kerno facade in the Python and Node bindings.
pip install --pre kernodb # --pre: only alpha versions exist so far The package is named kernodb but the module you import is kerno (import kerno); import kernodb raises ModuleNotFoundError.
Wheels are published for CPython 3.9+ (one abi3 wheel per platform) on Linux x86_64 and aarch64 (glibc; musl from the next release), macOS x86_64 and arm64, and Windows x86_64. On any other platform pip builds from the source distribution, which needs a Rust toolchain.
Durable commits are verified on Linux (ext4, xfs) only; elsewhere the database works but that guarantee is not verified (see Durability).
import kerno with kerno.open("./memory-db") as db: # creates the directory if needed note = db.store("note", "Rust has no GC") # (unit_type, payload) -> id topic = db.store("topic", b"memory") # str is stored as UTF-8, bytes as they are db.relate(note, topic, "about") # (from, to, relation_type) -> relation id print([r.to_id for r in db.related(note)]) # outgoing relations db.update(note, "Rust has no garbage collector") # a new revision; the old one is kept for rev in db.history(note, with_payload=True): # newest first print(rev.revision, rev.kind, rev.payload) print([u.id for u in db.query("note")]) # every active unit of a type Leaving the with block closes the database; without it, call db.close().
Keyword index: off by default; set_fulltext(type, True) turns it on for one type.
Unit: a record with an id (32 hex digits), a unit_type (1–64 bytes), a payload (up to 1 MiB of bytes) and a lifecycle: active, archived or deleted.
Revision: every write to a unit (create, update, archive, unarchive, delete, restore) adds one. Nothing is overwritten. A delete leaves a tombstone, and the history stays readable.
Relation: a directed, typed edge between two units. Parallel relations and self-loops are allowed unless you ask for unique=True.
Change set: one atomic commit. commit(ops) puts many writes in one change set (at most 10,000 operations). A reader sees all of them or none, and a crash keeps all or none.
Commit sequence: every change set has a number that only grows. read_as_of(id, seq) reads a unit as it was right after commit seq. last_commit_seq() is "now".
Write many things at once (and fast)
out = db.commit( [ ("store", "symbol", payload_a), # op 0 ("store", "symbol", payload_b), # op 1 ("relate", 0, 1, "calls"), # an end is the position of an earlier "store" or "upsert" op ("relate", existing_id, 0, "calls"), # ... or an existing unit id ("update_if_changed", other_id, new), # writes nothing if the payload is the same ("delete_cascade", old_id), # removes its relations too ], reason="index run 42", actor="indexer", # recorded with every revision detailed=True, ) out["units"], out["relations"], out["unchanged"], out["upserts"], out["commit_seq"] All batch ops: ("store", type, payload), ("update", id, payload), ("update_if_changed", id, payload), ("delete", id), ("delete_cascade", id), ("unrelate", relation_id), ("relate", from, to, type), ("relate_unique", from, to, type), ("archive", id), ("unarchive", id), ("restore", id, revision), ("upsert", type, field, document) (see below; its result is in out["upserts"], not units).
Keep one unit per natural key (upsert)
Ids are random, so a logical key (an email, a path) needs a lookup. Declare the field unique and upsert does it for you: it revises the active unit that holds the same value, or stores a new one.
db.define_schema("user", [{"name": "email", "type": "text", "unique": True}, {"name": "name", "type": "text"}]) r = db.upsert("user", "email", {"email": "a@example.com", "name": "Ada"}) r # {"id": "...", "outcome": "created"} db.upsert("user", "email", {"email": "a@example.com", "name": "Ada"})["outcome"] # "unchanged": no revision db.upsert("user", "email", {"email": "a@example.com", "name": "Ada L."})["outcome"] # "updated": a new revision db.history(r["id"], order="asc") # create, update In commit, ("upsert", type, field, document) runs in the same change set as the other ops, and several upserts of one key in a batch make one unit (the last document wins). A field that is not declared unique raises NotUniqueError; a document without a value in it raises SchemaError. Only active units hold a key: an archived or deleted one does not.
Look things up by a field
Range lookups and query plans work on the same indexed fields:
db.find_range("user", "age", 18, 65) # both ends included; None leaves an end open db.find_range("user", "age", low=65) # age >= 65, ordered by age; `limit=` caps it db.explain("FIND user AS u WHERE u.age > 30") # how `execute` would run it, without running it # {"candidates": [{"access": "type_scan", ...}, {"access": "field_index", "field": "age", "cost": ...}], # "chosen": 1, "joins": [], ...} Search by keyword, vector and relations
db.set_fulltext("note", True) # keyword (BM25) search finds only these types hits = db.hybrid_search( "garbage collector", # keyword signal vector=query_vec, vectors={uid: vec, ...}, # vector signal: your vectors, searched exactly seeds=[topic_id], # relation signal: units near these seeds ) hits[0].id, hits[0].score # best first; score = sum of the signal scores hits[0].keyword_score, hits[0].vector_score, hits[0].relation_score # None: the signal missed it Kerno does not store vectors: you pass the {unit id: vector} dict you keep in step with your units, as in the Rust API. Signals are fused by weighted reciprocal rank fusion; each adds weight / (rrf_k + rank). Only active units are hits. Types you did not enable with set_fulltext never match the keyword signal. text_types=["note"] narrows the keyword signal to some unit types.
hits = db.search_text("garbage collector", limit=10) # TextHit(id, score), best first notes = db.search_text("garbage collector", types=["note", "memo"]) # only those unit types search_text raises instead of returning [] when it could never match: NotIndexedError (no type, or a requested type, is keyword-indexed), UnknownTypeError (a type no unit, schema or set_fulltext ever named), InvalidArgumentError (limit below 1, a query with no word, an empty types). A search that can match and finds nothing returns []. A unit scores the same with or without types.
seq = db.last_commit_seq() db.update_document(uid, {"email": "a@example.com", "age": 32}) db.read_as_of(uid, seq).payload # the payload before the update (raw document bytes) db.history(uid, limit=10) # newest first; NotFoundError for an id no unit ever had # Page through a long history: [from_revision, to_revision), newest first or order="asc" page = db.history(uid, limit=50) older = db.history(uid, limit=50, to_revision=page[-1].revision) diff = db.compare(uid, 1, 3) # both revisions with payloads: diff.a, diff.b, diff.same_content db.read(uid).oldest_revision # the oldest revision still kept; asking for an older one # raises PrunedError Archived and deleted units stay out of query() unless you ask: db.query("note", lifecycle="archived") (or "deleted", or "all"). A deleted unit comes back with payload=None; read its history to see what it held. find and find_range see only active units.
report = db.verify() report["clean"] # False if anything is wrong report["findings"] # what is wrong (ids and counts, never content) Damage in the storage files (a block that fails its checksum) is reported as report["storage_error"]. Reads that touch a damaged block raise kerno.CorruptionError and never return wrong data.
Type stubs ship with the package (py.typed).
Retention and the oldest revision
Retention (dropping old revisions) is a call, not a setting: db.run_retention(by_type={"note": {"keep_last": 5}}) prunes now, and the policy is not stored, so pass it each time you prune. Afterwards read_as_of, history(from_revision=) and compare raise PrunedError for a pruned revision. Before reading an old revision, compare it with db.read(id).oldest_revision, or catch PrunedError. A unit that was never pruned has oldest_revision == 1.
Engine failures raise kerno.KernoError or one of its subclasses:
Every argument refusal is a KernoError: a malformed id, direction, order, lifecycle, metric, retention rule or batch op (a tuple that names no op or has the wrong number of items), or a vector without vectors (or the reverse), raises InvalidArgumentError, which is also a ValueError; a call on a closed database raises ClosedError, also a ValueError. kerno.__version__ is the installed version. An argument of the wrong Python type (None or an int for a str, a list for a payload), or a str with a lone surrogate, which has no UTF-8 form, raises InvalidArgumentError (never a bare TypeError or UnicodeEncodeError). A payload or document bytes value is bytes, bytearray or a memoryview, never a list of ints.
These numbers are from one Linux machine (ext4), with every commit synced to disk, comparing Kerno 1.0.0a2 to SQLite in WAL mode with synchronous=FULL storing the same data (with a revision table). The full method is in docs/testing/python-vs-sqlite.md.
What makes the most difference:
Batch your writes. One commit([...]) is about 10x faster than the same writes one by one, because each commit syncs to disk.
The keyword index is opt-in. Since 1.0.0-alpha.2 no type is indexed for keyword search (BM25) unless you call db.set_fulltext("my_type", True). Indexing costs writes several times over and about 3.5x the disk, so turn it on only for the types you search by text. The setting is stored in the database, and switching a type that already has units indexes (or clears) them in the same commit.
Read relations in bulk with relations(type) instead of related(id) per unit.
Mind the batch limit. A commit holds 10,000 operations by default. Split larger work, or open with max_batch_ops= when it must be atomic.
kerno.open asks for synchronous commits by default: when a commit returns, it is on stable storage. With durability="buffered" a commit does not wait for stable storage (no fsync per commit, like SQLite's synchronous=NORMAL in WAL mode): after a power cut the last commits may be missing, never torn, and close() still makes everything durable. The synchronous guarantee is verified on Linux (ext4, xfs) only. On other platforms the database opens and works without that verification. In our tests, killing the process with kill -9 in the middle of a stream of commits never lost an acknowledged commit and never left half a batch.
One read-write Database holds a database directory at a time: a second read-write open raises LockedError. A read-only open takes no lock, so readers run beside the writer, in other processes or in the same one. Inside the process, a Database can be shared between threads. Calls release the GIL while they touch disk, any number of readers run while one writer commits, and a read never sees half of a change set.
Payload: 1 MiB. Unit and relation type: 1–64 bytes (no NUL in a relation type).
One change set: a unit is written by at most one operation of it (a second update, delete, archive, ... of the same unit is InvalidArgumentError; relations to it are not limited). It holds 10,000 operations by default (kerno.open(path, max_batch_ops=...) changes it, up to 2^20); the engine also limits the bytes of one commit.
find and find_range return active units only. The Rust API has no index of archived or deleted units, so query(lifecycle=...) reads every unit's head instead of looking one up.
Deleting a unit keeps its revisions' history entries; compact() drops the payloads of deleted units (an as-of read of one of their old revisions is then no longer possible) and gives their space back. Until you call it, deletes do not shrink the store.
An indexed text or bytes value holds at most 254 bytes (a 0x00 byte counts twice).
Integers in documents are 64-bit (-263 to 263 - 1); a counter or revision argument is a whole number from 0 to 2**64 - 1 (limit and keep_last from 1).
Upgrading from an earlier alpha
This build does not open a database written by 1.0.0-alpha.4 or any earlier alpha. Their units layer is 9 or below (alpha.1: 1 to 6) and this build needs 12 (a database that uses a covering field is at 13). Opening one fails with an error whose message says the database's layer_version predates the format of this build and to export and import it (LayerTooOld; from Python a KernoError). Nothing in the directory changes. To carry it over, export it with the command-line tool of the build that wrote it and import it with the one of this build:
kerno old-db export old.kexp # kerno CLI of the build that wrote old-db kerno import old.kexp new-db # kerno CLI of this build Then turn on the keyword index of every type you search by text (it is off by default since 1.0.0-alpha.2), and define again the schemas and indexes: an export holds neither.
cd bindings/python python3 -m venv .venv && . .venv/bin/activate pip install maturin pytest hypothesis maturin develop --release pytest The crate is excluded from the cargo workspace (it carries its own Cargo.lock and is built by maturin). Check it on its own with cargo clippy --all-targets -- -D warnings.
Released: Nov 28, 2026
All 8 files in this release have provenance metadata.
View provenance details
MIT OR Apache-2.0 View SPDX License List
database embedded memory ai storage
Development Status 3 - Alpha
Intended Audience Developers
Operating System MacOS
Microsoft :: Windows
Programming Language Python :: 3
Python :: Implementation :: CPython
Release files for kernodb 1.0.0a5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distributions (wheels)
Total release size: 15.3 MB
Release files / kernodb-1.0.0a5.tar.gz
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.
Release files / kernodb-1.0.0a5-cp39-abi3-win_amd64.whl
Security for kernodb 1.0.0a5
All 8 files in this release have been uploaded with provenance metadata.
With provenance kernodb-1.0.0a5.tar.gz Nov 28, 2026
With provenance kernodb-1.0.0a5-cp39-abi3-win_amd64.whl Nov 28, 2026
Attestation for kernodb-1.0.0a5.tar.gz
Attestation for kernodb-1.0.0a5-cp39-abi3-win_amd64.whl
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.
Release history Release notifications | RSS feed
1.0.0a5 This release
Nov 28, 2026 8 release files Full provenance
Nov 26, 2026 8 release files Full provenance
Nov 22, 2026 8 release files Full provenance
Nov 21, 2026 8 release files Full provenance
Nov 20, 2026 6 release files Full provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from fc0d8e6











