Skip to main content

Embedded graph database with HNSW vector search — Python bindings to the sqlitegraph Rust crate.

Project description

sqlitegraph

Python bindings to the sqlitegraph embedded graph database. Storage, graph algorithms, and HNSW vector search run in a reviewed Rust core; this package is the Pythonic surface.

Alpha — API subject to change before 1.0.

Install

pip install sqlitegraph

Quick start

from sqlitegraph import Graph

g = Graph.open_in_memory()
alice = g.add_node(kind="User", name="Alice", data={"age": 30})
order = g.add_node(kind="Order", name="Order-123")
g.add_edge(alice, order, "placed")

print(g.neighbors(alice))

Query language

Graph.query() exposes the same Cypher-inspired language as the CLI:

from sqlitegraph import Graph

g = Graph.open_in_memory()
alice = g.add_node(kind="User", name="Alice", data={"age": 30})
bob = g.add_node(kind="User", name="Bob", data={"age": 31})
g.add_edge(alice, bob, "KNOWS")

result = g.query("MATCH (a:User)-[:KNOWS]->(b:User) RETURN a.name, b.name")
print(result["results"])

Supported query features include node scans, edge traversal, multi-hop chains, star/multi-pattern joins, variable-depth edges, WHERE with regex/numeric operators and parentheses, LIMIT, CREATE, SET, DELETE, and HNSW vector search through CALL db.index.vector.queryNodes(...).

Algorithms

from sqlitegraph import Graph

g = Graph.open_in_memory()
a = g.add_node(kind="Page", name="A")
b = g.add_node(kind="Page", name="B")
c = g.add_node(kind="Page", name="C")
g.add_edge(a, b, "LINKS")
g.add_edge(b, c, "LINKS")
g.add_edge(c, a, "LINKS")

print(g.pagerank(iterations=20))
print(g.connected_components())
print(g.strongly_connected_components())
print(g.label_propagation(50))
print(g.find_cycles(10))
print(g.dominators(a))

critical_path() is also available for directed acyclic graphs and returns {"path": [...], "distance": float, "path_length": int}.

HNSW vector search

from sqlitegraph import Graph

g = Graph.open_in_memory()
idx = g.create_hnsw_index("embeddings", dimension=3, metric="cosine")

idx.insert_vector([1.0, 0.8, 0.1], {"label": "graph databases"})
idx.insert_vector([0.1, 0.2, 1.0], {"label": "baking"})

print(idx.search([1.0, 0.9, 0.0], 1))
print(g.list_hnsw_indexes())

g.delete_hnsw_index("embeddings")

Examples

The examples/ directory contains runnable scripts:

Example What it shows
01_basic_crud.py Nodes, edges, update, delete, query by kind/pattern, degrees
02_graph_algorithms.py BFS, k-hop, shortest path, PageRank, Louvain & label-propagation communities, connected components (WCC), strongly-connected components (SCC), cycle search, dominator tree, critical path
03_vector_search.py HNSW index creation, insert, search, bulk insert, index listing
04_social_network.py Realistic network: influencers (PageRank), communities, connection paths, mutual follows
05_file_backed.py Persistent Graph.open(path), checkpoint, reopen, cleanup
06_hybrid_sqlite_hnsw_query.py sqlite3 application rows + sqlitegraph metadata + HNSW + Graph.query() expansion

Run any example from the repo root:

cd sqlitegraph-py
source .venv/bin/activate
python examples/01_basic_crud.py

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

sqlitegraph-0.4.2.tar.gz (990.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sqlitegraph-0.4.2-cp310-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

sqlitegraph-0.4.2-cp310-abi3-manylinux_2_28_x86_64.whl (2.3 MB view details)

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

sqlitegraph-0.4.2-cp310-abi3-manylinux_2_28_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

sqlitegraph-0.4.2-cp310-abi3-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

sqlitegraph-0.4.2-cp310-abi3-macosx_10_12_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file sqlitegraph-0.4.2.tar.gz.

File metadata

  • Download URL: sqlitegraph-0.4.2.tar.gz
  • Upload date:
  • Size: 990.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sqlitegraph-0.4.2.tar.gz
Algorithm Hash digest
SHA256 5bae0fa8bba04434c8969015e7ad053659dc11f978c43cacb237408b7919403c
MD5 8d58748f54232e82a72393394dbbfbfe
BLAKE2b-256 6a89df9d51e82cc325631a2633a988fcf037d18853473406fe8f894662d50be2

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.4.2.tar.gz:

Publisher: wheels.yml on oldnordic/sqlitegraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlitegraph-0.4.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: sqlitegraph-0.4.2-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sqlitegraph-0.4.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8e902a533badd4cc5a21fbab5448155fe9164b7a09534947fe2f296df124ee66
MD5 39e96ca219dd9fb73308aae89f57376a
BLAKE2b-256 30251375e11aef7de4782f1da2a89a4bccc01299b91f46c1e05af5a79868eabf

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.4.2-cp310-abi3-win_amd64.whl:

Publisher: wheels.yml on oldnordic/sqlitegraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlitegraph-0.4.2-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sqlitegraph-0.4.2-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aee013f74e7a9bd66d5b8238cb246f1712ed284f9bbf0fbba9bc79bc03f2580a
MD5 06aab99884dec78bb539fc81dbc5c35b
BLAKE2b-256 bb83ed72aaf131ec15e23ecc109bafe34ce59edf6e065452b0a007bfb638fd77

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.4.2-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on oldnordic/sqlitegraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlitegraph-0.4.2-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for sqlitegraph-0.4.2-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 05ff4fb54095f1d043d70b9743ba83d53166832375d0f0886c558398451ec225
MD5 e8d440a20672b7864513c14c809297df
BLAKE2b-256 8a1952076f1be7bc2cf0a00b76a2bbad4a164df2b7990633a16d99462d30fffb

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.4.2-cp310-abi3-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on oldnordic/sqlitegraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlitegraph-0.4.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sqlitegraph-0.4.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9cc3ad4d9dd1252776891a7029a5f3183680daf9ecde686ca0772d4bf6e9bdd
MD5 a09055c38c6bb4929b5a29cf4293efc5
BLAKE2b-256 aae462ad7a3ce072051b5e9eaec8c5c060cf95b90d32391a76658fe92122e3e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.4.2-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on oldnordic/sqlitegraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlitegraph-0.4.2-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for sqlitegraph-0.4.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4c506d086f41e7d2a8a2cbf9b6c946b660ba72c4020567b717f640d809d81bc5
MD5 7db2c13fa7ee20b197c46f5af57f68a5
BLAKE2b-256 84031801e5cc5d97cbe774e71c6a502940b04344cf77bf1531dde6bb56b6bf02

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.4.2-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: wheels.yml on oldnordic/sqlitegraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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