Skip to main content

Python bindings for Uni Graph Database

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()

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-1.0.2.tar.gz (2.6 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-1.0.2-cp310-abi3-win_amd64.whl (82.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

uni_db-1.0.2-cp310-abi3-manylinux_2_28_x86_64.whl (93.6 MB view details)

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

uni_db-1.0.2-cp310-abi3-manylinux_2_28_aarch64.whl (92.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

uni_db-1.0.2-cp310-abi3-macosx_11_0_arm64.whl (82.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

uni_db-1.0.2-cp310-abi3-macosx_10_12_x86_64.whl (86.7 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: uni_db-1.0.2.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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-1.0.2.tar.gz
Algorithm Hash digest
SHA256 669d78655c6fd77adf63ec3910ce307ff96b5fabc6249e135f2b18f4a9c94c26
MD5 d344366929c0230ac9e24c4923daa66c
BLAKE2b-256 b06148218b5be056fba94d7e417ef68e3840a6856b3f936ebe78e5ab286c2962

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.0.2-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 82.2 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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-1.0.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2ccbb0005a4dcfa37be360b0b8d115b615f84e3eb81145f513a4eef3d7675798
MD5 042b30cd8f0220a2693163a6b9b51dbd
BLAKE2b-256 96246e67ee75539ca5665066228b095939515c6800b3cf0dbdd3f01d0f60377e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.0.2-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 93.6 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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-1.0.2-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 36bac9bd9d90292a9cc3beeca2f5efc9348e7ed006beaa9e7c01628daf622e99
MD5 a0150a609945a6abc75cf9b948c92abc
BLAKE2b-256 5ed87ea6127218e9f5d649e0eac1e6e3a76b5e06c503a9bc5da154b4748e0d25

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.0.2-cp310-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 92.1 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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-1.0.2-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cfd0b5a223aa02eaae3f0f8f7d33218a423149fd31dd849dfa2bfaca5402a111
MD5 7f76e6576c2c661554cb9d97e25ca85b
BLAKE2b-256 be6c0384a2d31119daebccc0fcb44ab4639291d3ab2217f62f31de44ab3bc831

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.0.2-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 82.4 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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-1.0.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cf6f1a45c63b2599bbb5b55bc2f524536e5159904d2ac3030e075171d7b638ea
MD5 bddf55f89c6df9bda95c50d68f835224
BLAKE2b-256 85c2336dffc38629e6c28329e8e165629746894ca9ea81a1fb784c998443730b

See more details on using hashes here.

File details

Details for the file uni_db-1.0.2-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: uni_db-1.0.2-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 86.7 MB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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-1.0.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 eacae1427f58e0d7df107aaea1709690211da1fe1f452e34ae878e06555fb247
MD5 18f17fdd951018720a778436e5e76858
BLAKE2b-256 98e694428fd3d84e9d738a647ad4880175b56f321f394d9a73ec888fcf753642

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