Skip to main content

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

Project description

sqlitegraph

Python bindings to sqlitegraph — an embedded graph database with 35+ graph algorithms and HNSW vector search. Rust core, no server required, single .db or .graph file.

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.3.tar.gz (1.0 MB 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.3-cp310-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.10+Windows x86-64

sqlitegraph-0.5.3-cp310-abi3-manylinux_2_28_x86_64.whl (2.4 MB view details)

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

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

sqlitegraph-0.5.3-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.3.tar.gz.

File metadata

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

File hashes

Hashes for sqlitegraph-0.5.3.tar.gz
Algorithm Hash digest
SHA256 1ab3fc70c5431a45c2ab81ca44ad84fe64de398db621a7715bfc39d3ab8d787f
MD5 abfa409b9fa2ad5738ae8caa754b1a28
BLAKE2b-256 a0c2b9959b8119b3d33713fd07c8289ccf974b6013e54968934b54aad33c5040

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: sqlitegraph-0.5.3-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.0 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.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4428a6844e9a78a59d5784edeca34a0f001cb51923e8a37f8ac8b8ac3e13bea8
MD5 0de1a32f2639c257378396ad4638772c
BLAKE2b-256 df1b0f49681e40672ca14ab8b9d8054ece00141b192f5b26e12029842c3b3f29

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.5.3-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6c10bfc5e2b143b24e2b3a6858e31255b466d6bfe7d7aafe9127c88d7c159822
MD5 227e469796c177ad877d8c302926b931
BLAKE2b-256 c768057050b73383f299bfc7d5e9dddbd61aa0a57b37cd6284d9b20e680e1510

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.5.3-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a21dfb372cc9b4e6a520d6f239d873f6227b45d06428a358f66972d17c3f6f4b
MD5 3a2056aef4a02e311bfb53d6f6b5bb91
BLAKE2b-256 a87ceebe8b612128120a74367d661811487bdf83c3d82d3e94125fa47f4c7f80

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.5.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5f49355589837cf7e2f1adbd71fd9aff9b778b805fa409b0f70f4d415f093d2
MD5 4416124f6c8774d3e5dff9064d3d8a39
BLAKE2b-256 12466c55650bb8086720f29971601504ed6f5dba44fd9d9b62727b9760cf6445

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.5.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bd3d866db86d38d2113e2a06e783025036f7f705ab9a1e46cfd3ecf075979171
MD5 d6eb4ce52892ebbddfe63a2d0cb57d24
BLAKE2b-256 ae4546736291e55c6c8de827ff66d11017fa2fb93345ca6e9d3a5a68aa0589f4

See more details on using hashes here.

Provenance

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