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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

sqlitegraph-0.4.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.4.0.tar.gz.

File metadata

  • Download URL: sqlitegraph-0.4.0.tar.gz
  • Upload date:
  • Size: 985.4 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.0.tar.gz
Algorithm Hash digest
SHA256 fbf37b9e9c76be408a9f8c6105301e565e9c0a9545f6e9b357cc9e32044d133c
MD5 44b1fcff8ba52b902aa3e792866a59d3
BLAKE2b-256 7dd8e8e17ab92af02890842ff5657ffd9075c5537c5439ed87084861d7eb4dc3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: sqlitegraph-0.4.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.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9eaacfa96588c5150df5e0424beba37c7121c798daaf069c6cbb7c772031ba65
MD5 2a1562a168b4abc292b3532d4d345f6d
BLAKE2b-256 1decbb0fafcd59d0d79734c464f6c0a3da1ea07607aea889e0d05a7b062eae35

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1f424d469c8b154fbad7893013100c168ee19ceb86364762e01083fa867f9aed
MD5 dae72ae9ae9d29177971d138c5bdf01c
BLAKE2b-256 4df1fe4e2e61c88a7735e39cd9e73ee152e80c43521b7f14bba8c69139ace6d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.4.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 85536474423e399c19ec64d6c4832a39399e07602d40cd01faa705aefa5dc66a
MD5 a25e854d2e6f464f2b889fd76241d789
BLAKE2b-256 c0ec3b5ead43ebb73a6398a3c3c35d01ba96bd63bc332312f115b51778ad27a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e981b16d9dcdc2bd4d714f15b696da53724022c1d56619fa5d1a2cab5722459
MD5 11bce5b31839dada5004aeb13025185f
BLAKE2b-256 19a12eac06d68bdaf23c18c4169763df12664bdab05b955691bb664d12e157da

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cfc3ad1721e5799074b305eca38942e545dee2f34b38f81a205943b2048bc397
MD5 edbd04037c6d98111d7d830561ff828b
BLAKE2b-256 c2950ceb98fa9e63e4eb13d9ee3cd73d424cce5a4ea663160242121f544fe5f3

See more details on using hashes here.

Provenance

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