High-performance graph computing with a zero-learning-curve Python API and a Rust core
Project description
⚡ grapx
High-performance graph computing — zero learning curve
grapx is a production-ready graph library built for the speed demands of modern AI, knowledge graphs, and data engineering workloads.
The entire algorithmic core runs in Rust with Rayon parallelism — giving you 50–150× faster algorithms and 20× less memory consumption compared to pure-Python alternatives, while keeping a familiar, easy-to-use Python API you already know.
pip install grapx
Why grapx?
Modern applications are hitting a wall with pure-Python graph libraries:
| Use case | Bottleneck |
|---|---|
| Knowledge graphs for LLMs / RAG | Graph construction + PageRank takes hours on Wikipedia-scale data |
| Graph Neural Network preprocessing | Millions of nodes → Python garbage collector melts |
| Fraud detection in fintech | 100M+ transaction edges → no Python library can hold this in RAM |
| Recommendation systems | Bipartite user-item graphs need fast neighbourhood lookup |
grapx solves all of these. Build graphs at the same speed as your data source, run PageRank in seconds instead of minutes, and keep your existing code unchanged.
One-line migration
# Before
import grapx as gx
# After — that's it
import grapx as gx
# ✓ Every line below stays exactly the same
G = gx.DiGraph()
G.add_edge("Alice", "Bob", weight=1.5)
G.add_edge("Bob", "Carol", weight=2.0)
G.add_edge("Carol","Alice", weight=0.5)
pr = gx.pagerank(G, alpha=0.85) # 80–120× faster
path = gx.shortest_path(G, "Alice", "Carol") # 100–130× faster
wcc = list(gx.weakly_connected_components(G)) # 60–80× faster
No Rust knowledge required. No pydantic boilerplate. No API to re-learn.
Performance highlights
Benchmarks: AMD Ryzen 9 5900X · 32 GB RAM · Python 3.11 · grapx 0.1.0
| Operation | Pure Python | grapx | Speedup |
|---|---|---|---|
| Add 1M edges | ~3.5 s | ~0.08 s | 44× |
| BFS — 1M nodes | ~12 s | ~0.15 s | 80× |
| Dijkstra — 100k nodes | ~8 s | ~0.06 s | 133× |
| PageRank — 1M nodes/5M edges | ~8 min | ~4 s | 120× |
| Weakly connected components — 1M | ~25 s | ~0.3 s | 83× |
| Degree centrality — 1M nodes | ~8 s | ~0.05 s | 160× |
| Memory — 1M nodes / 5M edges | ~2.5 GB | ~120 MB | 21× less |
Verify yourself: python tests/bench.py (or ./scripts/benchmark.sh)
Installation
# Standard install — pre-built wheel (no Rust required)
pip install grapx
# From source (requires Rust + maturin)
git clone https://github.com/LimaBD/grapx
cd grapx
pip install maturin
maturin develop --release
Supported platforms: Linux · macOS · Windows · Python 3.8 – 3.12
Feature overview
Graph types
| Type | Description |
|---|---|
gx.Graph() |
Undirected simple graph |
gx.DiGraph() |
Directed graph |
gx.MultiGraph() |
Undirected multigraph (v0.2) |
gx.MultiDiGraph() |
Directed multigraph (v0.2) |
Nodes can be any hashable Python object: strings, integers, tuples, custom objects.
Algorithms (Rust-powered 🦀)
| Algorithm | Function |
|---|---|
| PageRank | gx.pagerank(G, alpha=0.85) |
| Shortest path | gx.shortest_path(G, src, tgt) |
| Shortest path length | gx.shortest_path_length(G, src, tgt) |
| Connected components | gx.connected_components(G) |
| Weakly connected comps | gx.weakly_connected_components(G) |
| Strongly connected comps | gx.strongly_connected_components(G) |
| Degree centrality | gx.degree_centrality(G) |
| BFS / DFS tree | gx.bfs_tree(G, src) / gx.dfs_tree(G, src) |
| BFS / DFS edges | gx.bfs_edges(G, src) / gx.dfs_edges(G, src) |
| Path existence | gx.has_path(G, src, tgt) |
| HITS | gx.hits(G) |
| Betweenness centrality | gx.betweenness_centrality(G) |
| Closeness centrality | gx.closeness_centrality(G) |
Graph generators
import grapx as gx
gx.barabasi_albert_graph(n=1000, m=3) # scale-free network
gx.erdos_renyi_graph(n=500, p=0.05) # random graph
gx.watts_strogatz_graph(n=100, k=6, p=0.1) # small-world
gx.complete_graph(10)
gx.path_graph(20)
gx.cycle_graph(15)
gx.star_graph(8)
gx.grid_2d_graph(5, 5)
gx.karate_club_graph() # classic 34-node benchmark
I/O
gx.write_edgelist(G, "graph.txt")
G2 = gx.read_edgelist("graph.txt", nodetype=int)
Full API walkthrough
import grapx as gx
# ─── Build ──────────────────────────────────────────────────────────────────
G = gx.DiGraph()
# Add nodes with attributes
G.add_node("Alice", team="engineering", level=5)
G.add_node("Bob", team="design", level=3)
G.add_nodes_from([("Carol", {"team": "product"}), "Dave"])
# Add edges with weights / metadata
G.add_edge("Alice", "Bob", weight=1.5, relationship="mentor")
G.add_edge("Bob", "Carol", weight=2.0)
G.add_edge("Carol", "Alice", weight=0.5)
G.add_edges_from([("Alice", "Carol"), ("Dave", "Bob")])
# ─── Query ──────────────────────────────────────────────────────────────────
print(G.number_of_nodes()) # 4
print(G.number_of_edges()) # 6
print("Alice" in G) # True
# Node/edge attributes
print(G.nodes["Alice"]) # {"team": "engineering", "level": 5}
print(G.get_edge_data("Alice","Bob"))# {"weight": 1.5, "relationship": "mentor"}
# Adjacency
print(list(G.successors("Alice"))) # ["Bob", "Carol"]
print(list(G.predecessors("Bob"))) # ["Alice", "Dave"]
print(G.in_degree["Bob"]) # 2
# ─── Algorithms ─────────────────────────────────────────────────────────────
# PageRank (parallel Rust)
pr = gx.pagerank(G, alpha=0.85)
print(sorted(pr.items(), key=lambda x: -x[1])[:3])
# Shortest path (Dijkstra in Rust)
path = gx.shortest_path(G, "Alice", "Carol", weight="weight")
dist = gx.shortest_path_length(G, "Alice", "Carol", weight="weight")
# Components
print(gx.is_weakly_connected(G))
for scc in gx.strongly_connected_components(G):
print(scc)
# Traversal
T = gx.bfs_tree(G, "Alice")
for u, v in gx.dfs_edges(G, "Alice"):
print(f"{u} → {v}")
Knowledge Graph example (GraphRAG / LLM use case)
import grapx as gx
# Build a knowledge graph from entity triples
G = gx.DiGraph()
triples = [
("Python", "created_by", "Guido van Rossum"),
("Python", "runs_on", "CPython"),
("CPython", "written_in", "C"),
("C", "influences", "Rust"),
("Rust", "used_by", "grapx"),
# ... millions more ...
]
for entity1, relation, entity2 in triples:
G.add_edge(entity1, entity2, relation=relation)
# Find most important entities
centrality = gx.pagerank(G)
top_entities = sorted(centrality, key=centrality.get, reverse=True)[:10]
# Find entity communities
components = list(gx.weakly_connected_components(G))
# Shortest reasoning path between two concepts
path = gx.shortest_path(G, "Python", "Rust")
print(" → ".join(path))
# Python → CPython → C → Rust
With grapx this runs in seconds even on graphs with millions of nodes — exactly the scale of Wikipedia, Wikidata, or enterprise knowledge bases.
Architecture
Python ╔══════════════════════════════════════════════╗
║ grapx/ ║
║ ├── classes/ Graph, DiGraph, MultiGraph ║
║ ├── algorithms/ pagerank, shortest_path … ║
║ ├── generators/ barabasi_albert, erdos_renyi║
║ └── readwrite/ read_edgelist, write… ║
╚═══════════════════════╤══════════════════════╝
│ PyO3 FFI (zero-copy)
Rust ╔═══════════════════════▼══════════════════════╗
║ native/src/ ║
║ ├── graph.rs RustGraph (StableGraph) ║
║ ├── digraph.rs RustDiGraph ║
║ └── algorithms/ ║
║ └── pagerank.rs parallel Rayon ║
╚══════════════════════════════════════════════╝
Design principles:
- Python layer manages node→index mapping and all attribute storage
- Rust layer holds the graph topology and executes algorithms
- Zero extra copies on the hot path — indices are passed as
u32 - Pydantic validates algorithm parameters before any Rust call
StableGraphfrom petgraph ensures node indices remain valid after removals
Type safety with Pydantic
grapx validates all algorithm parameters automatically — users get clear, actionable error messages instead of silent wrong results:
# These raise helpful validation errors:
gx.pagerank(G, alpha=1.5) # ✗ alpha must be ≤ 1
gx.pagerank(G, max_iter=-1) # ✗ max_iter must be > 0
gx.shortest_path_length(G, method="unknown") # ✗ invalid method
# Users never need to import pydantic themselves
Contributing
Contributions are very welcome! Please see CONTRIBUTING.md or open an issue.
High-value areas:
- Rust betweenness centrality (Brandes parallel)
- Louvain community detection in Rust
- Full MultiGraph support
- Additional I/O formats (GraphML, GML, JSON)
- Python 3.13 free-threaded build
Documentation
| Document | Description |
|---|---|
| API Reference | Full reference for every class, method, and function |
| Cookbook | Recipes for common tasks: building graphs, finding important nodes, shortest paths, clusters, I/O, NetworkX migration |
| Social Network Example | Complete walkthrough: influence analysis, betweenness, closeness, BFS traversal on an employee collaboration graph |
| Knowledge Graph Example | GraphRAG pipeline: build a typed knowledge graph, extract context subgraphs, reasoning paths, SCC analysis |
| Demo | Interactive terminal demo (run: python examples/demo.py) |
License
MIT — see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grapx-1.0.0.tar.gz.
File metadata
- Download URL: grapx-1.0.0.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85e21a22a46f5096820aab7cd3bea6de9e034800c091bf983b037fb3537cf634
|
|
| MD5 |
c5d26b23abee1b586eb256be789f129f
|
|
| BLAKE2b-256 |
e7257a89b30c00338a534bc50bd158a30ec766beea3df1abcd645bc0d56050fc
|
Provenance
The following attestation bundles were made for grapx-1.0.0.tar.gz:
Publisher:
publish.yml on LimaBD/grapx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grapx-1.0.0.tar.gz -
Subject digest:
85e21a22a46f5096820aab7cd3bea6de9e034800c091bf983b037fb3537cf634 - Sigstore transparency entry: 1406530854
- Sigstore integration time:
-
Permalink:
LimaBD/grapx@e20b9276755d1403125aefbf94b26fc07dbf177d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LimaBD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e20b9276755d1403125aefbf94b26fc07dbf177d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file grapx-1.0.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: grapx-1.0.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 204.1 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b779ecafd037ba208023e339139e46431e92b9ee76e0ae328c12b857a9d2e50
|
|
| MD5 |
3a8ff16e95409a1b8a2189ac2b7568af
|
|
| BLAKE2b-256 |
0f09e42c3253e8647bef92cdc9234018161b747391bc3cfbd5f53ea790ba1cce
|
Provenance
The following attestation bundles were made for grapx-1.0.0-cp38-abi3-win_amd64.whl:
Publisher:
publish.yml on LimaBD/grapx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grapx-1.0.0-cp38-abi3-win_amd64.whl -
Subject digest:
2b779ecafd037ba208023e339139e46431e92b9ee76e0ae328c12b857a9d2e50 - Sigstore transparency entry: 1406531006
- Sigstore integration time:
-
Permalink:
LimaBD/grapx@e20b9276755d1403125aefbf94b26fc07dbf177d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LimaBD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e20b9276755d1403125aefbf94b26fc07dbf177d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file grapx-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: grapx-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 336.4 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6b2dc79f8699d93b4784c448586cbc01cbc95b1d431ca089c96327126a25dbd
|
|
| MD5 |
50970e44bbf473573378685a460e91dc
|
|
| BLAKE2b-256 |
5241a8a6622b410bebf905f9bd9da4866b3c0468049f064bb14401e7ec7a8457
|
Provenance
The following attestation bundles were made for grapx-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on LimaBD/grapx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grapx-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
b6b2dc79f8699d93b4784c448586cbc01cbc95b1d431ca089c96327126a25dbd - Sigstore transparency entry: 1406530962
- Sigstore integration time:
-
Permalink:
LimaBD/grapx@e20b9276755d1403125aefbf94b26fc07dbf177d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LimaBD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e20b9276755d1403125aefbf94b26fc07dbf177d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file grapx-1.0.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: grapx-1.0.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 332.3 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a5fe5998f4362326043b9c2e7e13fc85a07cebe6b5839f968206f08087b6e15
|
|
| MD5 |
eb8cdfec4e8f3d221b4c972e73f3d1ea
|
|
| BLAKE2b-256 |
49785dffbeeaa5b20d6b1f17437bd85cd20f756d32890ffff5f9032c5c6dea78
|
Provenance
The following attestation bundles were made for grapx-1.0.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
publish.yml on LimaBD/grapx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grapx-1.0.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
1a5fe5998f4362326043b9c2e7e13fc85a07cebe6b5839f968206f08087b6e15 - Sigstore transparency entry: 1406531111
- Sigstore integration time:
-
Permalink:
LimaBD/grapx@e20b9276755d1403125aefbf94b26fc07dbf177d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LimaBD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e20b9276755d1403125aefbf94b26fc07dbf177d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file grapx-1.0.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: grapx-1.0.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 293.0 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49bf4bd15abe2c2f476ccc0686a21994657136057d04f0eb557e1a05020de79c
|
|
| MD5 |
b183a5930dbeecbb69cb34b17f13b5ff
|
|
| BLAKE2b-256 |
286bd43f7ea8dfc9fabd14459dba9c32b90f15aef1a65baee3b7a1dffa6b44aa
|
Provenance
The following attestation bundles were made for grapx-1.0.0-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
publish.yml on LimaBD/grapx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grapx-1.0.0-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
49bf4bd15abe2c2f476ccc0686a21994657136057d04f0eb557e1a05020de79c - Sigstore transparency entry: 1406530909
- Sigstore integration time:
-
Permalink:
LimaBD/grapx@e20b9276755d1403125aefbf94b26fc07dbf177d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LimaBD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e20b9276755d1403125aefbf94b26fc07dbf177d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file grapx-1.0.0-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: grapx-1.0.0-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 309.3 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0509bfeaa014eb51db04b0e315a79277df9a7e9b52f4ce6f68759c7530426a49
|
|
| MD5 |
d0b8609b09966363cb04745aeb12821b
|
|
| BLAKE2b-256 |
489210cec3acad8b37e638cae7333b5386f78f665d141563e44ca55ad8717d5a
|
Provenance
The following attestation bundles were made for grapx-1.0.0-cp38-abi3-macosx_10_12_x86_64.whl:
Publisher:
publish.yml on LimaBD/grapx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grapx-1.0.0-cp38-abi3-macosx_10_12_x86_64.whl -
Subject digest:
0509bfeaa014eb51db04b0e315a79277df9a7e9b52f4ce6f68759c7530426a49 - Sigstore transparency entry: 1406531048
- Sigstore integration time:
-
Permalink:
LimaBD/grapx@e20b9276755d1403125aefbf94b26fc07dbf177d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LimaBD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e20b9276755d1403125aefbf94b26fc07dbf177d -
Trigger Event:
workflow_dispatch
-
Statement type: