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-0.2.0.tar.gz (2.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-0.2.0-cp310-abi3-win_amd64.whl (78.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

uni_db-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl (89.1 MB view details)

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

uni_db-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl (86.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

uni_db-0.2.0-cp310-abi3-macosx_11_0_arm64.whl (77.5 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

uni_db-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl (82.0 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: uni_db-0.2.0.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a488c2ea1ee7e4d88db1c741468a83b0934ce2ae77461a53240ee53effa664d8
MD5 3a5f2c49c9b8baf134ec7335206ca059
BLAKE2b-256 f5a453864d438149479f5cd6014575c6225c723df94513df5d3620831c6166b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.2.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 78.4 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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-0.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c82162c6e1cf586ea936cb4b529948aca039396605b7e7b794f9857a98df91ce
MD5 faa8787537617924d31593bef1280990
BLAKE2b-256 d0d9f39dcee8ad49728d385d13d8e4b6ce54d0fadc3e5409e3e7fcd3ebbe6de1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 89.1 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f04a2c6a19f3ce5202af7fc6c26feb6e55d03d2eb64a7dc3561d82b85005a51e
MD5 5bae394a6c57794b3c781bf8b3099740
BLAKE2b-256 29e9520601fb5c928fc19fa816f4fa1146fc32d26ab839bb26588d5490540e74

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 86.9 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 02e31258bb2d2b3f3101821f7eedf549bbcdd2d30d43fc6b7ee999561b904665
MD5 d04a0d489d30cff7f40282dc7258a5dc
BLAKE2b-256 26c52938623f54a07178f30f4daa688de3da5344a280aee76ca44a6cbdfd4b03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 77.5 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8b92a9fc341174a17e9eee8dd4d74f182146740fd5b0e491e4018890155b604c
MD5 3d749f434bbb68a704ebbe8c1ae6d363
BLAKE2b-256 a0ec205e0009719cd7110541965c27efc25b338fa2801307918cc9591ef4c0fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 82.0 MB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 717177b1971eb2aac23133105464035fdf79c15fcdd96b51a0d736b6b8286175
MD5 0cb9c9994c0bfaa9ceb99d5c0dfecb53
BLAKE2b-256 f978c37796a7c0d5e9b83e9093131a4c9c2f413d7d4435cb96fb3020d15dbdda

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