Graph theoretic classes and algorithm helper functions.
Project description
Graphworks
A Python module for efficient graph theoretic programming
Quick Start
pip install graphworks
import json
from graphworks.graph import Graph
json_graph = {"label": "my graph", "graph": {"A": ["B"], "B": []}}
graph = Graph(input_graph=json.dumps(json_graph))
print(graph)
Optional extras:
pip install graphworks[matrix] # numpy adjacency matrix support
pip install graphworks[viz] # graphviz export
pip install graphworks[docs] # generate documentation
Development
Requirements
- Python 3.13+
- uv (>= 0.10.12)
Setup
uv sync --extra all
Running Tests
# Run all tests (includes coverage; fails under 90%)
uv run pytest
# Run a single test file
uv run pytest tests/test_graph.py
# Run a single test by name
uv run pytest tests/test_graph.py -k "test_method_name"
Linting and Formatting
# Lint
uv run ruff check --fix src/ tests/
# Format
uv run black src/ tests/
uv run isort src/ tests/
# Type checking
uv run ty check
# Code complexity
uv run xenon --max-average=A --max-modules=B --max-absolute=B src/
# Run all pre-commit hooks
prek run --all-files
Publishing
Version is managed automatically via git tags using hatchling-vcs.
- Tag a commit:
git tag -a X.Y.Z -m 'release message' - Push the tag:
git push --tags - The GitHub Actions workflow will build and publish to PyPI automatically.
Roadmap
Tier 1: Data model
-
Vertexclass with name, optional label, and immutable attribute mapping -
Edgedataclass with source, target, directed flag, optional weight, label, and attributes - Both classes are frozen (immutable) with identity-based equality and hashing
Tier 2: Graph refactor
- Internal storage uses
dict[str, Vertex]for vertex lookup - Adjacency structure uses
dict[str, dict[str, Edge]]for O(1) edge access - Edge weights, labels, and attributes survive all operations
-
add_edgesupportsweightandlabelkeyword arguments -
edge()lookup method for direct O(1) edge retrieval
Tier 3: Lossless conversions
-
to_adjacency_matrix()/from_adjacency_matrix()round-trips that preserve vertex names via an index mapping - Fix
get_complementto preserve original vertex names instead of generating UUIDs -
to_edge_list()/from_edge_list()conversions - Parse weighted JSON format (e.g.
g4.jsondict-as-neighbor style)
Tier 4: Algorithms
- Dijkstra's shortest path (weighted)
- Prim's / Kruskal's minimum spanning tree
- Strongly connected components (Tarjan or Kosaraju)
- Improved shortest-path implementations leveraging weighted edges
Tier 5: Export and CLI
- JSON export (
save_to_json) - Graphviz DOT export (
save_to_dot) - Rich-based demo script (
uv run demo) - CLI application for common graph operations
- Rich rendering integration for interactive graph display
Tier 6: Cross-cutting quality
- Thread safety (immutable graph views or locking around mutations)
- Input validation hardening
- Performance benchmarks
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 Distribution
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 graphworks-0.7.0.tar.gz.
File metadata
- Download URL: graphworks-0.7.0.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0a7e107e0ca00d4e81ffc18d572ce5946feff0c3ae4ee851c63012ebfa22ce7
|
|
| MD5 |
6c90bbb42eb522dfc9a586f361fbb18e
|
|
| BLAKE2b-256 |
5315935d71749bbf4b45dda2e35e98702255b83f9294207b317882abf292ddad
|
Provenance
The following attestation bundles were made for graphworks-0.7.0.tar.gz:
Publisher:
publish-to-pypi.yml on nathan-gilbert/graphworks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphworks-0.7.0.tar.gz -
Subject digest:
b0a7e107e0ca00d4e81ffc18d572ce5946feff0c3ae4ee851c63012ebfa22ce7 - Sigstore transparency entry: 1184234166
- Sigstore integration time:
-
Permalink:
nathan-gilbert/graphworks@ef1b5376c692e17ad36561c4a130f9e798bf9527 -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/nathan-gilbert
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ef1b5376c692e17ad36561c4a130f9e798bf9527 -
Trigger Event:
push
-
Statement type:
File details
Details for the file graphworks-0.7.0-py3-none-any.whl.
File metadata
- Download URL: graphworks-0.7.0-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48ab766b70ea6ed5ca88a7280f133c9421850c04934dfa733e7276eb9bc9f38d
|
|
| MD5 |
eb2e42c05ad187cd9ca0f61cb58a5fbf
|
|
| BLAKE2b-256 |
3cb8c733a38386bfe6f042f98b228b375c5be1c20a5167edbff691611ab79a01
|
Provenance
The following attestation bundles were made for graphworks-0.7.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on nathan-gilbert/graphworks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphworks-0.7.0-py3-none-any.whl -
Subject digest:
48ab766b70ea6ed5ca88a7280f133c9421850c04934dfa733e7276eb9bc9f38d - Sigstore transparency entry: 1184234209
- Sigstore integration time:
-
Permalink:
nathan-gilbert/graphworks@ef1b5376c692e17ad36561c4a130f9e798bf9527 -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/nathan-gilbert
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ef1b5376c692e17ad36561c4a130f9e798bf9527 -
Trigger Event:
push
-
Statement type: