Registry / data / altgraph

altgraph

JSON →
library0.17.5pypypi✓ verified 10d ago

altgraph is a foundational Python library for creating and manipulating directed and undirected graphs (networks). It provides a robust set of tools for graph data structures and basic algorithms, often used as a dependency in projects like PyInstaller. The current version is 0.17.5, with sporadic but active maintenance and releases typically a few times a year.

pip install altgraph
INSTALL
IMPORT
SIG · ALTGRAPH
A
altgraph
datapythonv0.17.5
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.17.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Graph
from altgraph.Graph import Graph
Dot
from altgraph.Dot import Dot
Used for Graphviz integration.

Demonstrates creating a simple directed graph, adding nodes and edges, and basic traversal operations.

from altgraph.Graph import Graph # Create a new graph g = Graph() # Add nodes g.add_node("Start") g.add_node("Mid") g.add_node("End") # Add edges g.add_edge("Start", "Mid") g.add_edge("Mid", "End") g.add_edge("Start", "End", label="direct") print(f"Nodes: {list(g.nodes())}") print(f"Edges: {list(g.edges())}") print(f"Successors of 'Start': {list(g.forw_nodes("Start"))}") print(f"Predecessors of 'End': {list(g.back_nodes("End"))}") # Example of iterating over nodes and edges for node in g.nodes(): print(f"Node: {node}") for head, tail, data in g.edges(): print(f"Edge: {head} -> {tail} (data: {data})")
Debug
Known issues
breakingVersion 0.17.0 and newer dropped support for Python 2.x and older Python 3.x versions (3.3, 3.4, 3.5). If you are using these older Python interpreters, you must use altgraph < 0.17.
fix
Upgrade to a supported Python version (3.6+) or pin altgraph to a version less than 0.17 (e.g., `altgraph==0.16.1`).
affects: >=0.17.0
gotchaWhen using `altgraph.Dot` for visualizing graphs, the Graphviz system package must be installed and accessible in your system's PATH. This is an external dependency, not a Python package.
fix
Install Graphviz separately for your operating system (e.g., `sudo apt-get install graphviz` on Debian/Ubuntu, `brew install graphviz` on macOS, or download from graphviz.org).
affects: All
gotchaaltgraph provides fundamental graph structures and basic algorithms. For advanced graph analytics, highly optimized performance on massive graphs, or a richer set of algorithms (e.g., shortest path, centrality), users might need to integrate with more specialized libraries like NetworkX or igraph.
fix
Consider `NetworkX` or `igraph` for complex graph analysis, or use `altgraph` as a foundational layer and implement custom algorithms as needed.
affects: All
breakingThe provided test script `script.py` contains a `SyntaxError: f-string: unmatched '('` on line 18, preventing its execution. This error is due to an issue in the script's syntax, not directly a problem with the `altgraph` library or its compatibility.
fix
Correct the syntax error in `script.py` on line 18 by ensuring all parentheses within the f-string are properly matched.
affects: All
breakingThe `Graph.add_edge()` method in `altgraph` does not accept a `label` keyword argument directly. Edge attributes, such as a 'label', must be passed via the `attr` dictionary argument (e.g., `attr={'label': 'direct'}`).
fix
Modify the call to `add_edge()` to pass edge attributes through the `attr` dictionary argument, like so: `g.add_edge('Start', 'End', attr={'label': 'direct'})`.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'altgraph'
The 'altgraph' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install altgraph'.
ImportError: cannot import name 'Graph' from 'altgraph'
The 'Graph' class is located in the 'altgraph.Graph' submodule, not directly in 'altgraph'.
fix
Import the class correctly: 'from altgraph.Graph import Graph'.
AttributeError: module 'altgraph' has no attribute 'Graph'
Attempting to access 'Graph' directly from 'altgraph' instead of its submodule.
fix
Use the correct import statement: 'from altgraph.Graph import Graph'.
TypeError: 'Graph' object is not callable
Trying to call a 'Graph' object as if it were a function.
fix
Ensure that 'Graph' is instantiated correctly: 'g = Graph()' instead of 'g = Graph' followed by 'g()'.
ValueError: Node 'X' already exists in the graph
Attempting to add a node that already exists in the graph.
fix
Check if the node exists before adding it, or handle the exception appropriately.
Upgrade
Version history
0.17.5latest on PyPI · released Nov 21, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
32
Resources