A lightweight, type-safe library for building, managing, and visualizing dependency graphs.
Project description
graphable
graphable is a lightweight, type-safe Python library for building, managing, and visualizing dependency graphs. It provides a simple API for defining nodes and their relationships, performing topological sorts, and exporting graphs to various formats like Mermaid, Graphviz, and ASCII text trees.
Features
- Type-Safe: Built with modern Python generics and type hints.
- Topological Sorting: Easily get nodes in dependency order.
- Cycle Detection: Built-in protection against circular dependencies.
- Filtering & Tagging: Create subgraphs based on custom predicates or tags.
- Visualizations:
- Mermaid: Generate flowchart definitions or export directly to SVG.
- Graphviz: Generate DOT definitions or export to SVG with custom styling.
- D2: Generate D2 definitions or export to SVG with modern styling and layouts.
- PlantUML: Generate component or deployment diagram definitions.
- TikZ: Generate high-quality LaTeX definitions for academic documents.
- GraphML: Industrial-standard XML export for professional analysis tools (Gephi, yEd).
- Interactive HTML: Generate a single, portable HTML file with zooming and panning.
- JSON & Cytoscape: Export graph structure as machine-readable data.
- CSV: Export simple edge lists for data processing.
- NetworkX: Seamless integration with the NetworkX library for advanced analysis.
- Text Tree & ASCII Flowchart: Generate beautiful ASCII representations.
- Modern Tooling: Managed with
uvandjust.
Installation
uv add graphable
# or
pip install graphable
Quick Start
from graphable.graph import Graph
from graphable.graphable import Graphable
from graphable.views.texttree import create_topology_tree_txt
# 1. Define your nodes
a = Graphable("Database")
b = Graphable("API Service")
c = Graphable("Web Frontend")
# 2. Build the graph
g = Graph()
g.add_edge(a, b) # API Service depends on Database
g.add_edge(b, c) # Web Frontend depends on API Service
# 3. Get topological order
for node in g.topological_order():
print(node.reference)
# Output: Database, API Service, Web Frontend
# 4. Visualize as a text tree
print(create_topology_tree_txt(g))
# Output:
# Web Frontend
# └─ API Service
# └─ Database
Visualizing with ASCII Flowchart
from graphable.views.asciiflow import create_topology_ascii_flow
print(create_topology_ascii_flow(g))
# Output:
# +----------+
# | Database |
# +----------+
# v
# +--> API Service
#
# +-------------+
# | API Service |
# +-------------+
# v
# +--> Web Frontend
Visualizing with Mermaid
from graphable.views.mermaid import create_topology_mermaid_mmd
mmd = create_topology_mermaid_mmd(g)
print(mmd)
# Output:
# flowchart TD
# Database --> API Service
# API Service --> Web Frontend
Visualizing with Graphviz
from graphable.views.graphviz import create_topology_graphviz_dot
dot = create_topology_graphviz_dot(g)
print(dot)
# Output:
# digraph G {
# "Database" [label="Database"];
# "Database" -> "API Service";
# "API Service" [label="API Service"];
# "API Service" -> "Web Frontend";
# "Web Frontend" [label="Web Frontend"];
# }
Advanced Analysis with NetworkX
If you have networkx installed, you can convert your graph for advanced analysis:
import networkx as nx
# Convert to NetworkX DiGraph
dg = g.to_networkx()
# Use NetworkX algorithms
print(nx.dag_longest_path(dg))
# Output: ['Database', 'API Service', 'Web Frontend']
Visualizing with D2
from graphable.views.d2 import create_topology_d2
d2 = create_topology_d2(g)
print(d2)
# Output:
# Database: Database
# Database -> API Service
# API Service: API Service
# API Service -> Web Frontend
# Web Frontend: Web Frontend
Documentation
Full documentation is available in the docs/ directory. You can build it locally:
just docs-view
Development
This project uses uv for dependency management and just as a command runner.
just install # Install dependencies
just check # Run linting, type checking, and tests
just coverage # Run tests with coverage report
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 graphable-0.3.0.tar.gz.
File metadata
- Download URL: graphable-0.3.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe7a76d2faedb0c621b044fb5fa2319083087786a38d31d0362bb6a6ed44749f
|
|
| MD5 |
8a73640e9c6e893886a308d3b59292b0
|
|
| BLAKE2b-256 |
84b70e378fc7204ab4e5730927f5fa44fdb6eeb5bf0338dc270048e88644daa0
|
Provenance
The following attestation bundles were made for graphable-0.3.0.tar.gz:
Publisher:
publish.yml on TheTrueSCU/graphable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphable-0.3.0.tar.gz -
Subject digest:
fe7a76d2faedb0c621b044fb5fa2319083087786a38d31d0362bb6a6ed44749f - Sigstore transparency entry: 936529644
- Sigstore integration time:
-
Permalink:
TheTrueSCU/graphable@a7c81ddaa3c7ac43b75cc56827a85299c2cf62ea -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/TheTrueSCU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a7c81ddaa3c7ac43b75cc56827a85299c2cf62ea -
Trigger Event:
release
-
Statement type:
File details
Details for the file graphable-0.3.0-py3-none-any.whl.
File metadata
- Download URL: graphable-0.3.0-py3-none-any.whl
- Upload date:
- Size: 27.4 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 |
0ef65f192e896fb5610fdada7a37c6c20698a1e808ee6ce55a6022a173cdf07e
|
|
| MD5 |
b1995a6761f2dab0c0e3c799e9fd48d1
|
|
| BLAKE2b-256 |
6ae08f70af2405b9b2170ac55948c44fb87e754ba2ae379c09d8e2ccfa1f3bfd
|
Provenance
The following attestation bundles were made for graphable-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on TheTrueSCU/graphable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphable-0.3.0-py3-none-any.whl -
Subject digest:
0ef65f192e896fb5610fdada7a37c6c20698a1e808ee6ce55a6022a173cdf07e - Sigstore transparency entry: 936529649
- Sigstore integration time:
-
Permalink:
TheTrueSCU/graphable@a7c81ddaa3c7ac43b75cc56827a85299c2cf62ea -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/TheTrueSCU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a7c81ddaa3c7ac43b75cc56827a85299c2cf62ea -
Trigger Event:
release
-
Statement type: