Skip to main content

⚡ grapx

High-performance graph computing — zero learning curve

PyPI version CI Python 3.8+ License: MIT

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
  • StableGraph from 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


grapx — Because your data shouldn’t wait.

Author: Bruno Lima

PyPI · GitHub · Issues

Metadata

Release files for grapx 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grapx 1.0.0
File Size Uploaded
grapx-1.0.0.tar.gz 29.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for grapx 1.0.0
File
grapx-1.0.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
grapx-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
grapx-1.0.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
grapx-1.0.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
grapx-1.0.0-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 1.5 MB

Release files / grapx-1.0.0.tar.gz

Download URL grapx-1.0.0.tar.gz
Size 29.9 kB
Tags Source
SHA-256 checksum
How to use checksums
85e21a22a46f5096820aab7cd3bea6de9e034800c091bf983b037fb3537cf634
BLAKE2b-256 checksum
How to use checksums
e7257a89b30c00338a534bc50bd158a30ec766beea3df1abcd645bc0d56050fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release files / grapx-1.0.0-cp38-abi3-win_amd64.whl

Download URL grapx-1.0.0-cp38-abi3-win_amd64.whl
Size 204.1 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
2b779ecafd037ba208023e339139e46431e92b9ee76e0ae328c12b857a9d2e50
BLAKE2b-256 checksum
How to use checksums
0f09e42c3253e8647bef92cdc9234018161b747391bc3cfbd5f53ea790ba1cce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release files / grapx-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL grapx-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 336.4 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
b6b2dc79f8699d93b4784c448586cbc01cbc95b1d431ca089c96327126a25dbd
BLAKE2b-256 checksum
How to use checksums
5241a8a6622b410bebf905f9bd9da4866b3c0468049f064bb14401e7ec7a8457
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release files / grapx-1.0.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL grapx-1.0.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 332.3 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
1a5fe5998f4362326043b9c2e7e13fc85a07cebe6b5839f968206f08087b6e15
BLAKE2b-256 checksum
How to use checksums
49785dffbeeaa5b20d6b1f17437bd85cd20f756d32890ffff5f9032c5c6dea78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release files / grapx-1.0.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL grapx-1.0.0-cp38-abi3-macosx_11_0_arm64.whl
Size 293.0 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
49bf4bd15abe2c2f476ccc0686a21994657136057d04f0eb557e1a05020de79c
BLAKE2b-256 checksum
How to use checksums
286bd43f7ea8dfc9fabd14459dba9c32b90f15aef1a65baee3b7a1dffa6b44aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release files / grapx-1.0.0-cp38-abi3-macosx_10_12_x86_64.whl

Download URL grapx-1.0.0-cp38-abi3-macosx_10_12_x86_64.whl
Size 309.3 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0509bfeaa014eb51db04b0e315a79277df9a7e9b52f4ce6f68759c7530426a49
BLAKE2b-256 checksum
How to use checksums
489210cec3acad8b37e638cae7333b5386f78f665d141563e44ca55ad8717d5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page