ogdf-py¶
Python bindings for the Open Graph Drawing Framework (OGDF), built with nanobind.
This is a curated subset of OGDF, not a full wrapper: enough to build graphs, run layout and core graph algorithms, style and draw them, and read/write common graph file formats. See Coverage for exactly what is and is not included.
Install¶
pip install ogdf-py
Binary wheels are published for Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (AMD64) on CPython 3.10-3.14.
Example¶
import ogdf
# Build a graph and run a force-directed layout.
g = ogdf.Graph()
ogdf.random_planar_connected_graph(g, 30, 45)
ga = ogdf.GraphAttributes(g)
ogdf.FMMMLayout().call(ga)
# Export to SVG.
ogdf.draw_svg(ga, "graph.svg")
What's included¶
-
Graph model -
Graph,Node,Edge, node/edge iteration, andNodeArray/EdgeArrayattribute arrays. -
Attributes & styling - coordinates, size, labels, colors, shapes, fill patterns, stroke, edge arrows, and bends.
-
Layouts - layered, force-directed, stress/MDS, planarization, orthogonal, planar straight-line, tree, and circular.
-
Algorithms - connectivity and structure tests, components, shortest paths, spanning tree, flow, cut, matching, coloring, and planarity.
-
Generators - complete, bipartite, wheel, cube, grid, Petersen, trees, and several random families.
-
File I/O - GML, GraphML, DOT, GEXF, GDF, TLP interchange, plus SVG and TikZ drawing output.
-
Python interoperability - NetworkX and edge-list conversion, array-to-dict helpers, and results as ordinary Python lists.
-
Checked preconditions - a typed exception taxonomy, and
validate()/graph_report()to inspect an input before calling. -
Reproducibility - seeding for every stochastic operation, and
provenance()metadata to record alongside a result. -
Drawing metrics - crossings, edge-length uniformity, area, angular resolution, node overlap, and stress, plus a layout comparison helper.
-
Coordinate transforms - normalize, center, scale, fit-to-box, and component packing, all bend-aware.
-
One-call workflow -
layout(graph, ogdf.FMMMLayout, seed=..., pack=True, fit=(800, 600))from graph to placed drawing.
Where to go next¶
-
Getting Started - installation, the graph model, interoperability, errors, and reproducibility.
-
Choosing a Layout - which of the twenty-two layouts fits your graph, and why.
-
Recipes - four complete workflows, from NetworkX to SVG to annotated drawings.
-
Drawing Metrics - measure and compare layouts on numbers rather than by eye.
-
Gallery - example drawings.
-
Coverage - exactly what is and is not included.
Run python -m ogdf to print an installation report (versions, platform, capabilities) for a bug report.