Kanta database
Kanta is a small embedded NoSQL store for async Python apps. It keeps live state in memory, writes transactional diffs to an append-only log, and supports versioned schema migrations.
Why Kanta
- Fast synchronous reads and modifications on native Python objects
- Durable writes with append-only file and periodic snapshots
- Transaction semantics with rollback on failure
- Explicit schema evolution via
migrate_vNfunctions - Line-based JSON or binary MessagePack, or bring your own serializer
- Even in JSON we can use non-string keys, bytes, datetimes, UUID and other types
This design is often preferable when you want low-latency local persistence without operating a separate database service. You get straightforward deployment, auditable history, and deterministic replay while keeping application state ergonomic to work with.
Queries and updates on native data are far faster than over an SQL server connection, and we can can provide fully synchronous operation. The limitation is that you can only use the same database within a single process at a time, but this is well suited for async programming.
Quick Start
import asyncio
import msgspec
from uuid import UUID, uuid7
from kanta import Kanta
class User(msgspec.Struct):
name: str = ""
email: str | None = None
class Data(msgspec.Struct):
users: dict[UUID, User] = {}
async def main() -> None:
async with Kanta("data.kantadb", Data()) as kanta:
user_id = uuid7()
with kanta.transaction(action="create_user") as data:
data.users[user_id] = User(name="Alice")
asyncio.run(main())
Core Concepts
- Define your schema as a
msgspec.Structroot object. - Mutate data inside
with kanta.transaction(...):. - Let Kanta flush queued changes to disk in the background.
- Use snapshots and replay for fast startup and full history.
Documentation
- Usage patterns — opening, data ownership, and lifecycle patterns
- Bootstrap and open modes — seeding new databases, strict and read-only opens
- Validation —
@kanta.validateintegrity checks on open and transactions - Migrations — versioned schema evolution with
migrate_vN - Retention and rotation — bounding history to a time window
- Fatal error handlers — observing background write failures
- On-disk format — record layout and invariants
Kanta in JSON mode (default) stores newline-delimited records, so transaction history is viewable in any text editor; MsgPack mode uses binary records with length and checksum to guard against corruption.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kanta-0.9.1.tar.gz.
File metadata
- Download URL: kanta-0.9.1.tar.gz
- Upload date:
- Size: 91.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a2a165c066deb99a4694b4f885f1c64ef775d7cc9c3434c76030aed18a00ed
|
|
| MD5 |
c8af4f0a70431b090a32bbf6fae1349f
|
|
| BLAKE2b-256 |
61a13fe52db23b214bb87adeaee0a693f06571374400bd0ce055eb1f37e6971a
|
File details
Details for the file kanta-0.9.1-py3-none-any.whl.
File metadata
- Download URL: kanta-0.9.1-py3-none-any.whl
- Upload date:
- Size: 65.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c229c310ca806554e28dd6bd8a942025d4739d591334af57f064d052cd8f60a3
|
|
| MD5 |
d0469e3bad10bd940a7cfe997bd03345
|
|
| BLAKE2b-256 |
7509f842e999e32357561199967bd5ec6f1fe641eba12fe25281877a05742a34
|