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

Uploaded CPython 3.10+Windows x86-64

uni_db-1.1.0-cp310-abi3-manylinux_2_28_x86_64.whl (92.4 MB view details)

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

uni_db-1.1.0-cp310-abi3-manylinux_2_28_aarch64.whl (91.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

uni_db-1.1.0-cp310-abi3-macosx_11_0_arm64.whl (82.9 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

uni_db-1.1.0-cp310-abi3-macosx_10_12_x86_64.whl (87.2 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: uni_db-1.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 f56115bba9116bb143b4797e94d45672fa59469bddd209b7f5f2d288de692e1b
MD5 f966b38df45fbcaab99f8293eb9cd027
BLAKE2b-256 afe7fe0e4e4f5b3daf6b6df74866c963ef196289541fdf0aad77b51f335468df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.1.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 82.5 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.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0a62fd65889478337e0c01577fde31a99cdee2980195a985cd55df24074148be
MD5 953443bd582521f29e27f8d8f3b50e53
BLAKE2b-256 25dc7a4b32678d0e1b08dc4e0ef8b5e297028a0ff3dbf816e2a52c163a279895

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 92.4 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.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e7740e43d11c07453e820f62202d4872b6ca8cd2d0c87d14b90c2d2ce44eaaa2
MD5 78c751be221f122f6af70a1095ea41f1
BLAKE2b-256 5363972ac63f4cb81c850f0e73e867a9e489e21edf2544b884fbe7d093dd00ba

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.1.0-cp310-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 91.0 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.1.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2c67013007d724aa80bb612cb4fc7ab57d0c84270bcd1a902ff9f9fd12649855
MD5 178c7cfeb3810384df3b64700d33f582
BLAKE2b-256 74ed4bab7077a3d133188f7b004342d6f665626d20ab7137005ffa0a41b017ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.1.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 82.9 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.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9db5c2fff2e95abebf2a82b17c0fa60af0944fdc000c7a3e46f111a75431efc3
MD5 f15d520f4a1050e3700791092df1f6cc
BLAKE2b-256 96d4b374c9a6fe986b6c69bfb06da66096e826ac47f21b345990cf80070a9b44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-1.1.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 87.2 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.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cf1d4fa430dbef6863703dd00d9ce2c74424d965716f063f3300ed138e453b21
MD5 a58fd72565518c13b606e280d70bf654
BLAKE2b-256 6442360b9712257d7b7d21f139965da691d281e35da195fb6296a07a69e19b4b

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