TongGraph
TongGraph is a lightweight embedded graph compute database for Python applications that need local GraphRAG retrieval, AI memory, agent context graphs, and probabilistic graph reasoning. TongGraph is for applications that want fast local graph structure, persistence, traversal, algorithms, and inference without running a separate database service.
Feature Highlights
- Property graph model with labels, typed edges, scalar properties, and external IDs.
- Rust core exposed through a compact Python SDK.
- Local SQLite persistence with reopen, indexes, snapshots, and compute segment compaction.
- Traversal and analytics APIs for neighbors, k-hop retrieval, BFS, shortest path, connected components, PageRank, random walks, subgraphs, and batch jobs.
- Structured path-query DSL plus a provider-neutral natural-language compiler hook.
- Embedded Cypher compatibility subset for common local
CREATE,MATCH,MERGE, andRETURNflows. - Probabilistic graph layer with variables, CPDs, factor tables, evidence, active-subgraph belief propagation, posteriors, and traces.
- Reproducible Python benchmark scripts for graph algorithms and belief propagation.
Getting Started
Use the source tree during development:
git clone https://github.com/bigai-nlco/TongGraph.git
cd TongGraph
uv sync --dev
uv run python scripts/build_python_extension.py
Verify the package:
uv run python -c "from tonggraph import Graph; print(Graph().node_count())"
Create a small graph:
from tonggraph import Graph
graph = Graph()
alice = graph.add_node(
"alice",
labels=["Person"],
properties={"name": "Alice", "active": True},
)
bob = graph.add_node("bob", labels=["Person"], properties={"name": "Bob"})
graph.add_edge(alice, bob, "KNOWS", properties={"weight": 0.8})
print(graph.neighbors(alice))
print(graph.k_hop(alice, 1))
Use local persistence by passing a SQLite path:
graph = Graph("memory.db")
graph.add_node("session:1", labels=["Session"])
graph.compact()
reopened = Graph("memory.db")
print(reopened.node_count())
Run the Python tests and benchmark scripts:
uv run pytest
uv run python scripts/benchmark_algorithms.py --nodes 1000 --degree 4 --repeat 2
uv run python scripts/benchmark_belief_propagation.py --nodes 1000 --degree 4 --repeat 2
Documentation
Development
uv sync --dev
uv run python scripts/build_python_extension.py
uv run pytest
uv run mkdocs build --strict
Metadata
Release files for tonggraph 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tonggraph-0.1.0.tar.gz | 304.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tonggraph-0.1.0-cp313-cp313-macosx_11_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 11.0+ ARM64 | Details |
Total release size: 973.6 kB
Release files / tonggraph-0.1.0.tar.gz
| Download URL | tonggraph-0.1.0.tar.gz |
|---|---|
| Size | 304.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb0862db468cfcd031b38b8b9458954938f044dcc3c668c470a88ca5e55056ed
|
|
BLAKE2b-256 checksum How to use checksums |
06f699f33fb2660ecead9c9843f54ac8be8e81ced8ec6f9f9345a29cf88d5747
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / tonggraph-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | tonggraph-0.1.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 669.1 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c9507adec62c731d6be8dd09f03c9ede6db7782bda5c9c0660787d1443d71de3
|
|
BLAKE2b-256 checksum How to use checksums |
048351809262e87b9e0452d97e5f280e4f1bab695a20a81e18525b31250565f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|