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.5.0.tar.gz (999.1 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.5.0-cp310-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

sqlitegraph-0.5.0-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.5.0-cp310-abi3-manylinux_2_28_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

sqlitegraph-0.5.0-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.5.0.tar.gz.

File metadata

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

File hashes

Hashes for sqlitegraph-0.5.0.tar.gz
Algorithm Hash digest
SHA256 9490f7a45abaffb28f1910973c3dc0b2c7945899c53da65f1c183707d9e519a6
MD5 bda87462ff18ffc655cdc0e76fd46c80
BLAKE2b-256 1e0d35a49dab325434beff967f6ad58cc70e27da3e3f96028958501b3fc1c4ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.5.0.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.5.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: sqlitegraph-0.5.0-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.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8c2cb5bcc9e4dc19105c579cc790da9bf85e1c7ea566dd662d3c310c40567886
MD5 a10bb7a6931fad485dd6e43a116f7408
BLAKE2b-256 012f0ba6e7fd7eb8235043d364d499ff120fa0cd72eff025f2df7a72ff6c738e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.5.0-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.5.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for sqlitegraph-0.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9a48f64226ef275c4233d46602ed6d747cdeb7e531583102d93cdd11fa38f341
MD5 87029e3e29ae87c1acf11d0ab591fc66
BLAKE2b-256 30bcc161da16c624f4a71f89e56f17ff9c3689971cbb1d75634356e91fb27f68

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.5.0-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.5.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for sqlitegraph-0.5.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9bb1f90b694949f250bd2f2d217a95249a5b9f2c991d29cb463d328e61d52800
MD5 0f1e7ff0ecb3151e2511bdc68a66d6df
BLAKE2b-256 e6c70063c3f37cd354c3dd6abe0e65f36d9b8807a5e7970b15b60bf0257950b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.5.0-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.5.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sqlitegraph-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 46651c91ff3eae12b981ac79f9699c6310242e08a35dd08e9cb04442bc3bf3b8
MD5 cd583e692f663201a961367367cde018
BLAKE2b-256 e10f9a1d5906457a936be57200eab9cbf4545fb699e7261eb2ae7c622d6175b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.5.0-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.5.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for sqlitegraph-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 447e1df015da01bf36cb4e0bc4e82ac71ee2de55a43441a8c8ab5dfdc8456e14
MD5 702519be4198819b160c676f8c82044e
BLAKE2b-256 33d999ecb5a1a1fdc36753d907753d279ed82a65b44af9a0fdde6fe3192349e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlitegraph-0.5.0-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