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.3.0.tar.gz (2.4 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.3.0-cp310-abi3-win_amd64.whl (79.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

uni_db-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl (90.0 MB view details)

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

uni_db-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl (87.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

uni_db-0.3.0-cp310-abi3-macosx_11_0_arm64.whl (78.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

uni_db-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl (82.9 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: uni_db-0.3.0.tar.gz
  • Upload date:
  • Size: 2.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","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.3.0.tar.gz
Algorithm Hash digest
SHA256 aaf0f965455364abfb0cbb67500591d00fa581b4c1b9ccd4534dca200043aeda
MD5 08cfae13d0519f335f6b51dc165ce997
BLAKE2b-256 73fc3e204c43d6382c05fff6d5dddc4c2f8a844f3ca00d02ec0e324cac9c50ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.3.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 79.4 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","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.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c86007e2c49792f76e076016bb2a34e7e41962a9a31b5adc6803c73de708d0ae
MD5 89b50553c8d5116b9c7ecaeeee9b065d
BLAKE2b-256 49566cb32b69c65e1b7a08db7b51c38c2266f8badd3b00b8e3e2bc83415febd2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 90.0 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","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.3.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6947664a372795e4be8f5600f47504f417585b0b3ee7876d1023802fe163c479
MD5 e8fb2f2ffaebd4c2901d4c0354cc0e21
BLAKE2b-256 676dfdf145247b2f64d2de4dd0dfa6cb53cdd5dbf3237324bb0b8f43829dc0a0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.3.0-cp310-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 87.8 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","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.3.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 00cd95caef503a9147bdec3187fad9ac8ec7dda2ea96b0f5caa38e87901cd4c4
MD5 81f06e7be042951811b78365e0d8d067
BLAKE2b-256 b6d8aa971d8439d46d05b1973587ef52503b85c1b1b4b741b891b5f6b5a365f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 78.4 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","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.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b67b82a72dcfe587a500f8c70a4d162a114db9c6da4710f1671c144eb2b4e546
MD5 67d6990eb84792643c4d013860a02510
BLAKE2b-256 e6652254fdf8a955ad0dc75c8f58f273454b10581f1183b6fa343244e82c389f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uni_db-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 82.9 MB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","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.3.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 353e58bdd09c6b83b288389c14f0d58711237a242990e707fa893a879f69f1f8
MD5 86a0fdd63ad4d6a3731b972ed351c7d3
BLAKE2b-256 3bc41276e7322136a2ba425850484dfec42ea1653c407ffc56c8394173e3cdef

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