Skip to main content

Python bindings for Uni Graph Database (default — all 11 providers, CPU)

Project description

uni-db: Python Bindings for Uni Graph Database

PyPI License

Python bindings for the Uni embedded graph database.

Part of The Rustic Initiative by Dragonscale Industries Inc.

Installation

pip install uni-db

Quick Start

import uni_db

# Open or create a database
db = uni_db.Database("./my_graph")

# Define schema
db.create_label("Person")
db.add_property("Person", "name", "string", False)
db.add_property("Person", "age", "int64", True)
db.create_scalar_index("Person", "name", "btree")

# Write data
db.execute("CREATE (p:Person {name: 'Alice', age: 30})")
db.execute("CREATE (p:Person {name: 'Bob', age: 25})")
db.flush()

# Query
results = db.query(
    "MATCH (p:Person) WHERE p.age > $min RETURN p.name",
    {"min": 28},
)
print(results)  # [{'p.name': 'Alice'}]

Schema Operations

# Labels and edge types
db.create_label("Person")
db.create_edge_type("KNOWS", ["Person"], ["Person"])
db.add_property("Person", "name", "string", False)   # nullable=False
db.add_property("Person", "age",  "int64",  True)    # nullable=True

# Indexes
db.create_scalar_index("Person", "name", "btree")
db.create_vector_index("Person", "embedding", "cosine")  # or "l2"

# Introspection
db.list_labels()         # ['Person', ...]
db.list_edge_types()     # ['KNOWS', ...]
db.get_label_info("Person")
db.get_schema()

Transactions

txn = db.begin()
txn.execute("CREATE (p:Person {name: 'Charlie'})")
txn.commit()   # or txn.rollback()

Bulk Loading

writer = db.bulk_writer()
writer.insert_vertices("Person", [
    {"name": "Alice", "age": 30},
    {"name": "Bob",   "age": 25},
])
writer.insert_edges("KNOWS", [
    (person_vids[0], person_vids[1], {}),   # (src_vid, dst_vid, properties)
])
writer.commit()

Vector Search

# Create a vector index
db.create_label("Document")
db.add_property("Document", "text",      "string",     False)
db.add_property("Document", "embedding", "vector[128]", True)
db.create_vector_index("Document", "embedding", "cosine")

db.execute("CREATE (d:Document {text: 'hello world', embedding: [0.1, 0.2, 0.3]})")
db.flush()

# K-NN search
results = db.query("""
    CALL uni.vector.query('Document', 'embedding', $vec, 10)
    YIELD vid, distance
    RETURN vid, distance
    ORDER BY distance
""", {"vec": my_embedding})

# K-NN with pre-filter (SQL WHERE expression)
results = db.query("""
    CALL uni.vector.query('Document', 'embedding', $vec, 10, 'category = "tech"')
    YIELD vid, distance
    RETURN vid, distance
""", {"vec": my_embedding})

# K-NN with distance threshold
results = db.query("""
    CALL uni.vector.query('Document', 'embedding', $vec, 10, NULL, 0.5)
    YIELD vid, distance
    RETURN vid, distance
""", {"vec": my_embedding})

YIELD columns: vid (integer vertex ID), distance (float).

Async API

import uni_db

# Open
db = await uni_db.AsyncDatabase.open("./my_graph")
# or: db = await uni_db.AsyncDatabase.temporary()

await db.execute("CREATE (p:Person {name: 'Alice', age: 30})")
results = await db.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uni_db-2.2.5.tar.gz (4.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

uni_db-2.2.5-cp310-abi3-win_amd64.whl (144.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

uni_db-2.2.5-cp310-abi3-manylinux_2_28_x86_64.whl (165.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

uni_db-2.2.5-cp310-abi3-manylinux_2_28_aarch64.whl (166.7 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

uni_db-2.2.5-cp310-abi3-macosx_11_0_arm64.whl (145.6 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file uni_db-2.2.5.tar.gz.

File metadata

  • Download URL: uni_db-2.2.5.tar.gz
  • Upload date:
  • Size: 4.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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

Hashes for uni_db-2.2.5.tar.gz
Algorithm Hash digest
SHA256 e8e6649fbfb09c2a044fc49d3ef02a986aef9e0c31d62b06024464170c34bc8b
MD5 7f7558375fa4f57d2f7b65d4878f618c
BLAKE2b-256 1609a27edc959e967fcd44c1995cf02c75ffa55a51ca9fcda0605afed0999d3e

See more details on using hashes here.

File details

Details for the file uni_db-2.2.5-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: uni_db-2.2.5-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 144.2 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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

Hashes for uni_db-2.2.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8e2e877fc5f9481f432b832705778f65cac2221541778c98e473c7b7220e6149
MD5 a6a06b3f13f9b9cbdc7c4a4f8685302b
BLAKE2b-256 d0479ac33ce1d819ef6db59646d0851a8628b73e67e5f4562fd88e24c4589372

See more details on using hashes here.

File details

Details for the file uni_db-2.2.5-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: uni_db-2.2.5-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 165.1 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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

Hashes for uni_db-2.2.5-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 81c26b366b004b167c670e63768c65a1f2505356ab9c2afee3d2e93b78a33eb8
MD5 d9d68ae72aa2a20bbcebf91237071143
BLAKE2b-256 3a80d214302d38f26abedf0c0b4db7f1f0159a67dfd3394c4116a9a065488ae7

See more details on using hashes here.

File details

Details for the file uni_db-2.2.5-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: uni_db-2.2.5-cp310-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 166.7 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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

Hashes for uni_db-2.2.5-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4714b8346b2a192dda05e36e57976b2da11ec14817b31d6ecf2f19b34396d7a6
MD5 9752430a34218d40d64920d727694ca8
BLAKE2b-256 b08ea80ac74fe72edfecf2d7894453877cad8db5b69afb60cd1e94e682d43415

See more details on using hashes here.

File details

Details for the file uni_db-2.2.5-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: uni_db-2.2.5-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 145.6 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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

Hashes for uni_db-2.2.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3cd70acf7e86e6dd0d7b1a4d8ef7adc5a5664bb70a9cf50446a154ae8abef719
MD5 9d40add262a5feaa9d0f98599d814707
BLAKE2b-256 b6215e3bddcc677d880e9152812876fcbf646a72448382504637ae59a1fef4ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page