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.2.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.2-cp310-abi3-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

sqlitegraph-0.5.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.5.2.tar.gz.

File metadata

  • Download URL: sqlitegraph-0.5.2.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.2.tar.gz
Algorithm Hash digest
SHA256 8558237442daf56c7ef3d62de4d5a29f9f47014a9ad0ffeacfcd82d5b9f046ef
MD5 3fd76084af13485bfb57dfb7d3f0123d
BLAKE2b-256 387cc9389f5c46fc3862ac4588579b1fa73a7fc6640727460a1714a7eed93ccf

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: sqlitegraph-0.5.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.5.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b22aefe105b685ac89fc1e86ff460bbdab99638eef8464bd319b506dfc0c55d4
MD5 441a63ed4ba8d61702dd02033f760371
BLAKE2b-256 ad9fd4ada3f61ee2429e885789db3f3538c2284fc752444b633d6b26b9d23e64

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.5.2-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 72ad79d9d04e8b358bd0510445606e046862d9f37ad84aac68085a6e98d4bcfb
MD5 72b5dbeeebc053c7867e01df7ca9c7bc
BLAKE2b-256 953557e713813682b2f23bd1dabde4e2d83795935e6f2d1de114f28ecce33694

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.5.2-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3306b2ed9bb46c27a092f3ea10dbeb722e9e65988bdd071c48f8cf9e61a13ff6
MD5 4ffd71fe61689ef566ec720de41fc48f
BLAKE2b-256 7009173248f5495bed163ebeaf26d961db1b6a57f573aeaf04a011c58a2fc7c5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.5.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c4c0da3cc2349dd774af9fee721bf1399d2572a22a582244379838844b39e1d
MD5 3ffb2d3d3106669af736cbab72e78cc3
BLAKE2b-256 dde8d46cc4a2ce37dbdd5375e78a3a409b5e5d70c8ea242d0f83883ed8ea759e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for sqlitegraph-0.5.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 04ae7265cd87e93dc340f0f8703cb6b0517a78557c5d0c353af52f90004b4f10
MD5 5267ee5d37e2ddbf944759f44b88a64e
BLAKE2b-256 ae2c88fd5ddadc72e307cf835f65c741b95e84efec5cd9a9963e02fac2796f9a

See more details on using hashes here.

Provenance

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