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.1.6.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.1.6-cp310-abi3-win_amd64.whl (76.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

uni_db-0.1.6-cp310-abi3-manylinux_2_28_x86_64.whl (87.3 MB view details)

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

uni_db-0.1.6-cp310-abi3-manylinux_2_28_aarch64.whl (84.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

uni_db-0.1.6-cp310-abi3-macosx_11_0_arm64.whl (75.8 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

uni_db-0.1.6-cp310-abi3-macosx_10_12_x86_64.whl (80.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: uni_db-0.1.6.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.1.6.tar.gz
Algorithm Hash digest
SHA256 932860c27c75c6e0ab841a4acfb41e8b11a17e4c1fabb8727e4d054467851a96
MD5 a7fa1632578117e329c2e05bcd50c896
BLAKE2b-256 d549246e9196b5c929e13c566c76e0ebd88b32a9deaf583e046b43e7215255cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.1.6-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 76.7 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.1.6-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a88e0d67f9e9263694d7c9beb4f2d334e6a01d6b485a81289f0dcfa8f415b895
MD5 7d3c4d4f69a7649e6513e982754a24a0
BLAKE2b-256 117fa02e896e8aa01dc0b40ab519ed57e24b1d50f37f90448bc674199691c152

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.1.6-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 87.3 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.1.6-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aef35d9c09c73b41de6d7d142ea9b34f5e2ba204475fdebd4ddc7501cffd56e3
MD5 68e359d6caf62ad7c0ccc334a2271d68
BLAKE2b-256 b56589ca57d8ffb1a688799f0b46ed3af11fbe232eebe7f5404d62b3a1a66455

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.1.6-cp310-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 84.9 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.1.6-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 db5d35606384ebabfc3c4074484e84fb020b8c947eb9d32bdabd24fbb75bcb1f
MD5 13ed84929c0fc5262fefcae87f06446f
BLAKE2b-256 a18bb37ba5e2c1a1d4938bc4a5cdd272c339bb44c4ee650a831cfd31ad497d01

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.1.6-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 75.8 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.1.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a884c9a6af265379a797b371b2e7d19235355ac68b6bdaf0253fd1ea3cd6da11
MD5 71dc35130dbc1fd0d4113a2c55d9a31f
BLAKE2b-256 1555b050e220680bb262970fb5c8ff76a988088b30e8236ea95926cbd2249cf6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.1.6-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 80.1 MB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.1.6-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bff8d4c7383d6308c1b6c3691324575649cd00c96266538902cd3ac77de819dd
MD5 54365a05412f435ca61ee1dd53c93e42
BLAKE2b-256 b29c228f6d97a489e29769082e49ba60f09a588f44ec88aa3929e2df0383e4e8

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