Skip to main content

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_vN functions
  • 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

  1. Define your schema as a msgspec.Struct root object.
  2. Mutate data inside with kanta.transaction(...):.
  3. Let Kanta flush queued changes to disk in the background.
  4. Use snapshots and replay for fast startup and full history.

Documentation

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.

Metadata

Release files for kanta 0.9.2

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

Source distribution (sdist)

Source distribution for kanta 0.9.2
File Size Uploaded
kanta-0.9.2.tar.gz 92.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kanta 0.9.2
File Interpreter ABI Platform
kanta-0.9.2-py3-none-any.whl Python 3 none any Details

Total release size: 158.2 kB

Release files / kanta-0.9.2.tar.gz

Download URL kanta-0.9.2.tar.gz
Size 92.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d12f67d88d0e45a284b6715d80a8e2af2316f103a12754500278630aaa7e2be3
BLAKE2b-256 checksum
How to use checksums
d9513c6b4d6d6370ca1c9a61b1bc72f658c435d347ecb429ef3b6888436e44c6
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / kanta-0.9.2-py3-none-any.whl

Download URL kanta-0.9.2-py3-none-any.whl
Size 65.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5a3f38ed32d61917c93f85f121e468ae1dd4eee0073db2d1b3dc434707eb0c4
BLAKE2b-256 checksum
How to use checksums
0095f9788c528baf1b8934937d9e0dc21e3fc0efec34defac4ad27597d812f3f
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

0.9.4

2 release files

0.9.3

2 release files

This release

0.9.2 This release

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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