Skip to main content

akar-python — Python bindings (PyO3)

Python bindings for Akar — a pure Rust embedded graph database for AI agent memory.

Provides a drop-in replacement for KuzuDB in the Kairos project via a Cypher-to-SQL translation layer, or direct Akar API access.

Quick start

import akar

db = akar.Database("/path/to/db")
conn = akar.Connection(db)

# Execute Cypher queries
conn.query("""
    CREATE NODE TABLE Memory(id INT64, content STRING, embedding FLOAT[],
    PRIMARY KEY(id))
""")

# Parameterized queries
result = conn.execute(
    "MATCH (m:Memory {id: $id}) RETURN m.content",
    {"id": 42},
)

while result.has_next():
    print(result.get_next())

# Get all results as list of dicts
rows = result.get_all()

db.close()

API surface

Database(path: str)

  • close() — release file lock, drop all connections
  • __repr__() — display path

Connection(database: Database)

  • query(cypher: str) -> QueryResult — execute Cypher, no parameters
  • execute(cypher: str, params: dict = None) -> QueryResult — execute Cypher with $param interpolation
  • close() — drop connection (DB stays open)

QueryResult

  • has_next() -> bool — check for more rows
  • get_next() -> dict | list | scalar — fetch next row (returns dict when rows_as_dict=True, default)
  • get_all() -> list — fetch all rows
  • get_column_names() -> list[str] — column names
  • rows_as_dict(state: bool) — toggle dict vs tuple mode
  • __iter__() / __len__() / __bool__() — iteration and checks
  • close() — drop result

Kairos compatibility shim

For drop-in replacement of KuzuDB in Kairos, use the shim at kairos/kuzu.py:

# In Kairos codebase:
import kuzu  # transparently becomes `import akar`

db = kuzu.Database("/path/to/db")
conn = kuzu.Connection(db)

The shim registers a sys.modules alias for the kuzu package (ladybug alias was removed in 0.1.1 — Kairos imports akar directly).

Supported Cypher features

  • DDL: CREATE NODE TABLE, CREATE REL TABLE, DROP TABLE, ALTER TABLE, CREATE/DROP INDEX
  • DML: MATCH, WHERE, RETURN, CREATE, SET, DELETE, MERGE (ON CREATE/ON MATCH)
  • Composition: WITH, ORDER BY, LIMIT, SKIP, UNION ALL, UNWIND, OPTIONAL MATCH, FOREACH
  • Data loading: COPY FROM (CSV, Parquet), COPY TO, EXPORT DATABASE, IMPORT DATABASE
  • Parameters: $param interpolation (string, int, float, bool, list, dict, null)
  • Translation: Kuzu syntax auto-converted to Akar SQL (IF NOT EXISTS, FLOAT[n] → FLOAT[], INSTALL/LOAD EXTENSION no-op, vector index calls)

Build from source

This crate is a standalone workspace (not a member of akar-core's workspace), so it does not affect the test [akar-core] gate or CI.

Prerequisites

  • Rust toolchain (stable)
  • Python >= 3.9
  • maturin >= 1.7

Development build

cd akar-core/akar-python

python -m venv .venv
.venv/Scripts/python -m pip install maturin pytest
$env:PYO3_PYTHON = ".venv\Scripts\python.exe"   # Windows PowerShell
# export PYO3_PYTHON=".venv/bin/python"           # Linux/macOS

.venv/Scripts/maturin develop    # build + install into venv
.venv/Scripts/python -c "import akar; print(akar.__name__)"

Release build (wheel)

.venv/Scripts/maturin build --release
# Output: target/wheels/akar-0.1.0-cp39-abi3-<platform>.whl

Source distribution

.venv/Scripts/maturin sdist
# Output: target/wheels/akar-0.1.0.tar.gz

Publishing to PyPI

akar 0.1.3 is live on PyPI (wheel cp39-abi3 + sdist, published 2026-08-24). Procedure:

  1. Build artifacts (do NOT use maturin publish — it rebuilds the whole workspace from scratch, ~10 min, and can exceed tool timeouts):
    .venv/Scripts/maturin build --release
    .venv/Scripts/maturin sdist
    
  2. Upload with twine (installed via uv tool install twine). Create an API token at https://pypi.org/manage/account/token/ ("Entire account"); it shows once — store it in a file outside the repo.
    # TestPyPI first (optional but recommended)
    twine upload --repository testpypi target/wheels/*.whl target/wheels/*.tar.gz
    
    # PyPI production
    twine upload --repository pypi target/wheels/*.whl target/wheels/*.tar.gz
    
    Token supplied via env: TWINE_USERNAME=__token__, TWINE_PASSWORD=<token>. Add --skip-existing when re-uploading after a metadata-only change.
  3. Verify: pip install akar==<version> in a clean venv, then smoke test Database/Connection/Cypher. Run the compat harness (tests/test_kuzu_compat.py) against the installed wheel.
  4. Bump version in pyproject.toml ([project].version) before each new release — PyPI rejects re-upload of an existing version.
  5. Record the release in ../CHANGELOG.md under ## [Unreleased] (Keep a Changelog).

Tests

Rust unit tests (cargo)

cd akar-core/akar-python
cargo test --lib

39 tests covering: translation layer, parameter interpolation, value conversion, schema bootstrap, vector index / kNN, community detection (Louvain), LSTM bindings, spread activation, lock management, connection lifecycle.

Python compatibility harness (pytest)

cd akar-core/akar-python
.venv/Scripts/pytest tests/test_kuzu_compat.py -v

53 tests validating drop-in replacement against real Kairos KuzuDBStore / KuzuDBDreamBackend methods (schema bootstrap, store, search, connections, export/repair, CHECKPOINT).

Project structure

akar-core/akar-python/
├── Cargo.toml          # pyo3 0.29.2 (abi3-py39), standalone workspace
├── pyproject.toml      # maturin build config
├── src/
│   ├── lib.rs          # PyO3 module: Database, Connection, QueryResult
│   ├── translation.rs  # Kuzu Cypher → Akar SQL translation
│   └── param_interp.rs # $param → literal interpolation
└── tests/
    ├── conftest.py     # pytest fixtures + gap-report hooks
    └── test_kuzu_compat.py  # 53 Kairos drop-in tests

License

GPL-3.0-or-later

Metadata

Release files for akar 0.1.14

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

Built distributions (wheels)

Table of built distributions (wheels) for akar 0.1.14
File Interpreter ABI Platform
akar-0.1.14-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
akar-0.1.14-cp39-abi3-manylinux_2_34_x86_64.whl CPython 3.9 abi3 Linux glibc 2.34+ x86-64 Details

Total release size: 12.4 MB

Release files / akar-0.1.14-cp39-abi3-win_amd64.whl

Download URL akar-0.1.14-cp39-abi3-win_amd64.whl
Size 6.4 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
90eb5ad8f5f433a482eacda25d73bd3b1e7ac364b542990bad0a31e5f1962a0a
BLAKE2b-256 checksum
How to use checksums
fd25be751d12c00e9fe2a4df38db4eb857f7e4b2938ad8d211439ebaa2f00ad3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / akar-0.1.14-cp39-abi3-manylinux_2_34_x86_64.whl

Download URL akar-0.1.14-cp39-abi3-manylinux_2_34_x86_64.whl
Size 6.0 MB
Tags CPython 3.9 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
e97a1ba0c68aba862f630f7f2fd47d5df5e1ba63323569ea233ed03dec153297
BLAKE2b-256 checksum
How to use checksums
28f08bff80446f4ee669d4e8acbcc57a01be4b4d3d2368b0dfd23e92f833c986
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for akar 0.1.14

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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