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.0.tar.gz (2.5 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.0-cp310-abi3-win_amd64.whl (82.1 MB view details)

Uploaded CPython 3.10+Windows x86-64

uni_db-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl (93.5 MB view details)

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

uni_db-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl (91.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

uni_db-1.0.0-cp310-abi3-macosx_11_0_arm64.whl (82.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

uni_db-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl (86.6 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

Hashes for uni_db-1.0.0.tar.gz
Algorithm Hash digest
SHA256 43a91e621ed4861a1ffb2f5bf18967f3b3ce4b33ebfed864622551debcf1c0ee
MD5 ef5a63c9fbb7939e4b390510dd064ce7
BLAKE2b-256 06f8e75eeef6864622dbffdb9de86034772584134e105346589c85544db49acd

See more details on using hashes here.

File details

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

File metadata

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

Hashes for uni_db-1.0.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c3c34b7c63550705fec320b2b9c62ae199f9e292eee9d9569f289d410d32f1db
MD5 fda3227635d8f42c7950477cff57f239
BLAKE2b-256 6b29a860b397bff595023adae6d2637af921d2c042f1d721dcf23710c39440a8

See more details on using hashes here.

File details

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

File metadata

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

Hashes for uni_db-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9ac3119497722006c189efea3bf30c4dc833619e38ce32542ae4df9133d475a3
MD5 a56c003e1bca7030e5355816db071da6
BLAKE2b-256 c783bfcb6bacb0f59ce430b28ca9c1d47bbec0d5ec818e72cac32607a6ca638f

See more details on using hashes here.

File details

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

File metadata

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

Hashes for uni_db-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1ea908f32ed6cba41106c203fe9470b60c64d1a7f2330a0add82ae08ed48ed4d
MD5 f29536b1e16ea3bf48535cd90e151aed
BLAKE2b-256 6b97917404c8cc9d69f8e96cbcee0a96822f9c0fa13a3134de1f8bd09eb823c8

See more details on using hashes here.

File details

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

File metadata

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

Hashes for uni_db-1.0.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 80ff9b555d411f4d568d6914b83d49ab0b20525da7cafa978fcdaa2e1575e8a5
MD5 b54b704ba959700a481d536c3b8e3b21
BLAKE2b-256 3fbbdf54754ca5331aec24ad8a63dbb2d00416be27d1c3395461cc90e15e4f5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 86.6 MB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.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

Hashes for uni_db-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 21f3d0f59782a5dc3f01454e0f73f4488c212f555d3f8ab104dae8abb99c0164
MD5 365a5cee6b38aad95ec39d81deae56a6
BLAKE2b-256 a8c58b92dcd827736e81b02228de01f5c40253ea1fc4a5a71b4cdb55c3859a3d

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