| name | networkxternal-0-3-0 |
| description | NetworkX-compatible interface for external memory MultiDiGraphs persisted in databases (SQLite, PostgreSQL, MySQL, MongoDB, Neo4J). Use when working with Terabyte-Petabyte graphs that won't fit into RAM, needing multi-edge support with key/label-based edge identity, or building graph applications requiring database-backed storage without changing application code. |
| license | MIT |
| author | Tangled <noreply@tangledgroup.com> |
| version | 0.1.0 |
| tags | ["graph","database","networkx","sqlite","postgresql","mysql","mongodb","neo4j","persistent-storage"] |
| category | databases |
| external_references | ["https://github.com/ashvardanian/NetworkXternal","https://docs.sqlalchemy.org/","https://github.com/ashvardanian/NetworkXternal/blob/main/networkxternal/base_api.py","https://networkx.github.io/documentation/stable/reference/classes/generated/networkx.Graph.html","https://networkx.github.io/documentation/stable/reference/classes/multidigraph.html","https://networkx.github.io/"] |
NetworkXternal 0.3.0
Overview
NetworkXternal provides a NetworkX-like API for graphs persisted in external databases, enabling you to scale from megabyte-sized in-memory graphs to terabyte-petabyte graphs that exceed available RAM — without changing application code. It wraps five database backends (SQLite, PostgreSQL, MySQL, MongoDB, Neo4J) behind a unified BaseAPI abstract class partially compatible with NetworkX's MultiDiGraph.
The library is written in Python (98.6%), uses SQLAlchemy for ORM-based SQL backends, PyMongo for MongoDB, and the official Neo4J Bolt driver for Neo4J. It comes with a performance penalty compared to pure in-memory NetworkX, but provides a practical starting point for database-backed graph applications.
When to Use
- Graphs too large to fit in RAM (terabyte to petabyte scale)
- Persistent graph storage across application restarts
- Multi-edge graphs where edges carry unique identity via key/label
- Migrating from in-memory NetworkX to database-backed storage with minimal code changes
- Applications needing concurrent read access to graph data (
__is_concurrent__ = True on SQL, MongoDB, Neo4J backends)
Core Concepts
BaseAPI: Abstract base class defining the graph interface. All backends inherit from it. Designed for directed weighted multigraphs by default. Supports multi-edges (multiple edges between same node pair). Edge IDs can be auto-generated by hashing connected node IDs using the Cantor pairing function.
Node: Dataclass with _id: int, weight: float, label: int, and payload: dict. Non-integer node names are hashed into integer IDs automatically.
Edge: Dataclass with _id: int, first: int, second: int, weight: float, label: int, is_directed: bool, and payload: dict. Supports tuple-like indexing (edge[0] returns first, edge[1] returns second) for NetworkX compatibility. Edge identity is deterministic via Edge.identify_by_members(first, second) using a modular Cantor pairing function.
GraphDegree: Simple dataclass holding count: int and weight: float, returned by reduction operations.
Architecture