uni-db: Python Bindings for Uni Graph Database
Python bindings for the Uni embedded graph database.
Part of The Rustic Initiative by Dragonscale Industries Inc.
Installation
pip install uni-db
Quick Start
from uni_db import Uni
# Open or create a database (`Uni.in_memory()` for an ephemeral one)
db = Uni.open("./my_graph")
# Define schema
db.schema() \
.label("Person") \
.property("name", "string") \
.property_nullable("age", "int64") \
.index("name", "btree") \
.apply()
# Write data. `Uni` is lifecycle and admin only: reads go through a Session,
# writes through a transaction on one.
session = db.session()
tx = session.tx()
tx.execute("CREATE (p:Person {name: 'Alice', age: 30})")
tx.execute("CREATE (p:Person {name: 'Bob', age: 25})")
tx.commit()
# Query (read-only)
results = session.query(
"MATCH (p:Person) WHERE p.age > $min RETURN p.name",
{"min": 28},
)
print(results) # [{'p.name': 'Alice'}]
Schema Operations
# Labels, edge types, properties and indexes are all declared through the
# schema builder and committed together by a single `.apply()`.
db.schema() \
.label("Person") \
.property("name", "string") \
.property_nullable("age", "int64") \
.vector("embedding", 384) \
.index("name", "btree") \
.index("embedding", {"type": "vector", "metric": "cosine"}) \
.done() \
.edge_type("KNOWS", ["Person"], ["Person"]) \
.property_nullable("since", "date") \
.apply()
# Introspection
db.schema().current() # dict view of the whole schema
db.schema().current_typed() # typed `Schema` object
Transactions
tx = db.session().tx()
tx.execute("CREATE (p:Person {name: 'Charlie'})")
tx.commit() # or tx.rollback()
Bulk Loading
The bulk writer is built from a transaction.
tx = db.session().tx()
writer = tx.bulk_writer().build()
vids = writer.insert_vertices("Person", [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25},
])
writer.insert_edges("KNOWS", [
(vids[0], vids[1], {}), # (src_vid, dst_vid, properties)
])
writer.commit()
tx.commit()
Vector Search
# Declare the vector column and its index
db.schema() \
.label("Document") \
.property("text", "string") \
.vector("embedding", 128) \
.index("embedding", {"type": "vector", "metric": "cosine"}) \
.apply()
session = db.session()
tx = session.tx()
tx.execute("CREATE (d:Document {text: 'hello world', embedding: $v})", {"v": my_embedding})
tx.commit()
db.flush()
# K-NN search. `k` is required.
results = session.query('''
CALL uni.vector.query('Document', 'embedding', $vec, 10)
YIELD node, score
RETURN node.text AS text, score
ORDER BY score DESC
''', {"vec": my_embedding})
# K-NN with pre-filter (SQL WHERE expression)
results = session.query('''
CALL uni.vector.query('Document', 'embedding', $vec, 10, 'category = "tech"')
YIELD node, score
RETURN node.text AS text, score
''', {"vec": my_embedding})
# K-NN with a similarity floor. `threshold` is a MINIMUM SIMILARITY on the
# same scale as `score` (larger is a better match), not a maximum distance.
results = session.query('''
CALL uni.vector.query('Document', 'embedding', $vec, 10, NULL, 0.8)
YIELD node, score
RETURN node.text AS text, score
''', {"vec": my_embedding})
YIELD columns: node (the matched vertex), score (similarity, larger is better) and distance (the raw metric distance).
Async API
from uni_db import AsyncUni
db = await AsyncUni.open("./my_graph")
# or: db = await AsyncUni.temporary()
session = db.session()
tx = await session.tx()
await tx.execute("CREATE (p:Person {name: 'Alice', age: 30})")
await tx.commit()
results = await session.query("MATCH (p:Person) RETURN p.name")
await db.flush()
Forks
Named, durable, isolated branches of the graph. A fork lets a session reason about an alternate version of the database — what-if analysis, audit hold, scenario sandboxing — that survives across restarts.
import uni_db
from datetime import timedelta
db = uni_db.Uni.builder().build()
db.schema().label("Person").property("name", "string").apply()
primary = db.session()
# Open or create a fork (Phase 2: writable; Phase 3: nestable;
# Phase 4a: TTL + tags + budget).
fork = primary.fork("scenario_1").ttl(timedelta(hours=1)).build()
tx = fork.tx()
tx.execute("CREATE (:Person {name: 'fork-only'})")
tx.commit()
# Fork sees primary state + its own writes; primary unchanged.
print(fork.query("MATCH (p:Person) RETURN count(p) AS n"))
# Pin a Lance tag for audit retention; the tag survives the drop.
db.tag_fork("scenario_1", "audit-2026-q1")
del fork
db.drop_fork("scenario_1")
print(db.list_fork_tags("scenario_1")) # tag still resolvable
The async surface mirrors this exactly through AsyncUni /
AsyncSession. See examples/fork_quickstart.py and
examples/fork_audit.py for runnable demos, and the full
Python API reference
for every method, type, and error variant.
Query Utilities
# Parameterized queries
results = db.query(
"MATCH (p:Person) WHERE p.name = $name RETURN p",
{"name": "Alice"},
)
# Explain / profile
plan = db.explain("MATCH (p:Person) RETURN p")
results, stats = db.profile("MATCH (p:Person) RETURN p")
Development
git clone https://github.com/rustic-ai/uni-db
cd uni-db/bindings/uni-db
uv sync --group dev
uv run maturin develop # builds and installs the extension module
uv run pytest # run tests
Links
License
Apache 2.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 uni_db-3.4.0.tar.gz.
File metadata
- Download URL: uni_db-3.4.0.tar.gz
- Upload date:
- Size: 5.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8afdf2f886c072ef256c0ee5c318c2d26acd4cc5b77af375eed05cb723f2a97c
|
|
| MD5 |
7f96de0eef5d742ce0037ed9588f79f9
|
|
| BLAKE2b-256 |
c576313ac1f9852b8d7486e8cc0566f66307dc4974ece6bb04f9e31e2c1467d4
|
File details
Details for the file uni_db-3.4.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: uni_db-3.4.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 90.6 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e99eb0038da986d46f6d5c953e295099f4729fce312d9011a59faad603d5a39
|
|
| MD5 |
feae1bff338bcfca2bca47d4f40780a5
|
|
| BLAKE2b-256 |
9c24a74f027051922206fe3a76c6e3aea8fc93669705892567ab775ca0e137ec
|
File details
Details for the file uni_db-3.4.0-cp310-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: uni_db-3.4.0-cp310-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 88.9 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1706ce13a45b2b0929dd3067a1a04d7d4afd5f0ecf621b2bede1f00059b02935
|
|
| MD5 |
d552fd8c8c3ca1092f124857ebc04186
|
|
| BLAKE2b-256 |
00e4d1d2db1e866e343bafbfdae7e4e1a090ac9b57fd15d12ce14cf29651a7c2
|
File details
Details for the file uni_db-3.4.0-cp310-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: uni_db-3.4.0-cp310-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 84.8 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b3d0296c15eccbab6f2af7388752409985cbdff2e2da3380371dc9b7bb7b9f4
|
|
| MD5 |
cd2e7d1faf17ebceea30b63715ec2941
|
|
| BLAKE2b-256 |
8446c5302937e9962f87d3a8c5a08e5ec5b1cad1343e2b70d86e678e117c5f90
|
File details
Details for the file uni_db-3.4.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: uni_db-3.4.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 77.1 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab764b1607631536e336f6fc7f611e68921484afb6c796b75e3a2cf1bc88d38f
|
|
| MD5 |
7047eb32ed32d1b692aa34d14c8de922
|
|
| BLAKE2b-256 |
cfd28cd3641d34a3b9d346677cade0b309c971141dc04d2d997667b371260606
|