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.

See also: SQL, NoSQL, and why I started Kanta DB

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.4

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.4
File Size Uploaded
kanta-0.9.4.tar.gz 110.0 kB Details

Built distribution (wheel)

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

Total release size: 184.0 kB

Release files / kanta-0.9.4.tar.gz

Download URL kanta-0.9.4.tar.gz
Size 110.0 kB
Tags Source
SHA-256 checksum
How to use checksums
22a96e6ff5cffd2537201b55b2548498fc549b4161eca66bda5e68d1b7a4321e
BLAKE2b-256 checksum
How to use checksums
474eced17c6cea10462eb3d5d035fe710c0bb5de6545a031ec34b7611754c274
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.4-py3-none-any.whl

Download URL kanta-0.9.4-py3-none-any.whl
Size 74.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ef2867ebdeea4f32c665ae3bc7a4e79c4f422e718064da16c98049f30ef0314
BLAKE2b-256 checksum
How to use checksums
42fbe7a169cd7f7c2d56c81a5526a6fe6816fbfd6d5f7563ae113dc1872880bd
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

This release

0.9.4 This release

2 release files

0.9.3

2 release files

0.9.2

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