Python bindings for mnem: git for knowledge graphs, agent memory under a token budget.
Project description
mnem (Python)
Python bindings for mnem - git for knowledge graphs, with retrieval under a token budget.
pip install mnem-py
import pymnem
# In-memory (tests, notebooks, agent sessions without persistence)
repo = pymnem.Repo.init_memory
# Or on-disk via the embedded redb backend
# repo = pymnem.Repo.open_or_init("/path/to/repo.redb")
# Write one node at a time
repo.commit_node(
author="alice@example.com",
message="seed",
ntype="Memory",
summary="Alice lives in Berlin and works at Globex",
props={"name": "Alice", "city": "Berlin"},
)
# Or batch with a transaction (context-manager commits on clean exit)
with repo.transaction(author="alice@example.com", message="seed batch") as tx:
tx.add_node(ntype="Memory", summary="Alice's hobby is climbing")
tx.add_node(ntype="Memory", summary="Bob moved to Paris last month")
# Retrieve under a token budget - dense vector + optional learned-sparse, RRF-fused
result = repo.retrieve(
text="Alice Berlin",
token_budget=500,
limit=10,
)
for item in result:
print(f"{item.score:.3f} [{item.tokens}t] {item.summary}")
print(f"used {result.tokens_used}/{result.tokens_budget} tokens,",
f"{result.dropped} dropped of {result.candidates_seen} candidates")
What you get from Python
pymnem.Repo- the repository handle, withinit_memory,open_or_init,op_id,head_commit_cid,commit_node,transaction,retrieve,query.pymnem.Transaction- a context manager for batched writes. Commits on clean exit, abandons on exception. Supportsadd_nodeandadd_embedding_f32.pymnem.RetrievalResult/pymnem.RetrievedItem- plain dataclass-shaped results withnode_id,ntype,summary,rendered,tokens,scoreplus cost metadata.pymnem.MnemError- the exception base class every mnem error inherits from.
What's deferred
The v1 Python surface deliberately leaves out:
- Signing and verification. Callers that need Ed25519 signatures build their signer in their own tooling; the Rust side remains the source of truth.
- CAS on refs, diff, merge. These are powerful but rarely touched from Python; open an issue with a concrete use case if you need them.
- Structured Edge writes.
add_edgelands once the first Python caller asks for it. - MCP server bindings. The
mnem mcpbinary is already Python-host-friendly (it speaks JSON-RPC 2.0 over stdio); no need to rewrap it.
Build from source
If you want to develop the bindings locally:
pip install maturin
cd crates/mnem-py
maturin develop --release # installs into your active venv
python -c "import pymnem; print(pymnem.__version__)"
Publishing wheels:
maturin build --release --strip
# Upload target/wheels/mnem_py-*.whl to PyPI with `twine upload`.
Pre-release verification (manual step before tagging 0.1.0)
cargo test -p mnem-py --lib covers the Rust-side parser and gate unit
tests, but the PyO3 ABI layer is only exercised through a real Python
interpreter. Before cutting a release tag, run the Python-linked
regression once on the target platform:
cd crates/mnem-py
maturin develop
pytest tests/
The pytest suite includes tests/test_mnem_bench_gate.py which pins
the MNEM_BENCH coercion behaviour across Repo.commit_node,
Transaction.add_node, Repo.retrieve, and Repo.query. Skipping this
step means shipping the pyo3 bindings without having loaded them.
Performance envelope
The Python wrapper is a thin pyo3 layer; retrieval throughput is what the Rust core measures in docs/benchmarks/ai-native.md. At 1000 Doc nodes on laptop hardware:
retrieve(text=...)fresh-index end-to-end: ~6 ms (in-memory) / ~14 ms (redb)- Amortised text search (pre-built index held for a session): ~11 µs (memory) / ~21 µs (redb)
- Fused text + vector retrieve: ~10 ms (memory) / ~21 ms (redb)
The Python-to-Rust boundary costs <50 µs per call in practice, well below the retrieval work.
License
Apache-2.0, same as the core crate. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
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 mnem_py-0.1.0-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: mnem_py-0.1.0-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06b3490b9ecb71bc9f752619934cce62fd71178328d05b27030c6ccf09e6a3f9
|
|
| MD5 |
d51deb30dc776cc29ca3824774ac99aa
|
|
| BLAKE2b-256 |
0b96aeef8b3a1578a453803f66acebff36b3258f0cfd45121abd18eda8ac96d4
|
Provenance
The following attestation bundles were made for mnem_py-0.1.0-cp39-abi3-win_amd64.whl:
Publisher:
release.yml on Uranid/mnem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnem_py-0.1.0-cp39-abi3-win_amd64.whl -
Subject digest:
06b3490b9ecb71bc9f752619934cce62fd71178328d05b27030c6ccf09e6a3f9 - Sigstore transparency entry: 1432547878
- Sigstore integration time:
-
Permalink:
Uranid/mnem@38c99bea4bddf4515fc5eefc77b7b66a07a6990f -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Uranid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38c99bea4bddf4515fc5eefc77b7b66a07a6990f -
Trigger Event:
push
-
Statement type:
File details
Details for the file mnem_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mnem_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d843fb5a9aa45ba60a8ab320af5d5367fdd8de3af5b8cbd5e4f175d41c15ec9c
|
|
| MD5 |
b472ee669c7dadf2f6673db923705491
|
|
| BLAKE2b-256 |
794681c94977287af339458bd0e27090269907dea14ea30e2a92f2c1ee39ae7b
|
Provenance
The following attestation bundles were made for mnem_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on Uranid/mnem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnem_py-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
d843fb5a9aa45ba60a8ab320af5d5367fdd8de3af5b8cbd5e4f175d41c15ec9c - Sigstore transparency entry: 1432547470
- Sigstore integration time:
-
Permalink:
Uranid/mnem@38c99bea4bddf4515fc5eefc77b7b66a07a6990f -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Uranid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38c99bea4bddf4515fc5eefc77b7b66a07a6990f -
Trigger Event:
push
-
Statement type:
File details
Details for the file mnem_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: mnem_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5805b4f0dd25dd7ccc3db22c01b5a63abecdb24555055c6b83c49ec5a3f2ce9
|
|
| MD5 |
2ff1237f356ae76d4938421155b446da
|
|
| BLAKE2b-256 |
8294e091b6fe79421531b2276a23a5a936b2820e6f8935aff30a58242433710f
|
Provenance
The following attestation bundles were made for mnem_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on Uranid/mnem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnem_py-0.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
f5805b4f0dd25dd7ccc3db22c01b5a63abecdb24555055c6b83c49ec5a3f2ce9 - Sigstore transparency entry: 1432547347
- Sigstore integration time:
-
Permalink:
Uranid/mnem@38c99bea4bddf4515fc5eefc77b7b66a07a6990f -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Uranid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38c99bea4bddf4515fc5eefc77b7b66a07a6990f -
Trigger Event:
push
-
Statement type:
File details
Details for the file mnem_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: mnem_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc6ea57425e9eec0172d9a78935c3ed59f7afbe8456ce09e0a73f374ce86e2cf
|
|
| MD5 |
7126c194e8fed10f31cdd60198bb0b01
|
|
| BLAKE2b-256 |
02c876e97d1e0555c1d356222fb3e7eb1c14e401d7a1ce3c5d6361fc348891a6
|
Provenance
The following attestation bundles were made for mnem_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on Uranid/mnem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnem_py-0.1.0-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
fc6ea57425e9eec0172d9a78935c3ed59f7afbe8456ce09e0a73f374ce86e2cf - Sigstore transparency entry: 1432547720
- Sigstore integration time:
-
Permalink:
Uranid/mnem@38c99bea4bddf4515fc5eefc77b7b66a07a6990f -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Uranid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@38c99bea4bddf4515fc5eefc77b7b66a07a6990f -
Trigger Event:
push
-
Statement type: