Audience: agents working on pgraph's source code. If you're helping someone use pgraph, read https://petercorke.github.io/pgraph-python/llms.txt instead (or
llms-full.txtfor the complete documentation).
Part of the RVC ecosystem. Read rvc-ecosystem/AGENTS.md first — it defines shared conventions: repo ownership, math invariants, dependency boundaries, git/PR workflow, code standards, tech-debt tracking. This file only adds what's specific to this repo.
| PyPI package | pgraph-python |
| Nickname | pgraph-python |
| Owner | Peter Corke (petercorke) |
| Default branch | main |
| Contribution model | Branch → PR; main is protected: CI must pass and the branch must be up to date (gh pr update-branch) |
- Minimal graph/path-planning package. Pure Python, builds with Hatch (
hatchling); Python 3.9+. Depends onnumpy,matplotlibandspatialmath-python;ansitableandscipyarrive through spatialmath. Do not add scipy topyproject.toml: it is imported lazily, only insideGraph.build_kdtree(). - Used, unpinned (
"pgraph-python"), byrobotics-toolbox-python(PRMPlanner,RRTPlanner,LatticePlanner,PoseGraph, which subclassUVertex/DVertex) andmachinevision-toolbox-python(BundleAdjust). A breaking change needs a deprecation cycle with a working fallback (warnings.warn(..., DeprecationWarning, stacklevel=2)); run their pgraph-using tests before a release. - Layout.
src/pgraph/PGraph.pyholdsGraph,UGraph,DGraph,Vertex,EdgeandSE2Metric;exporters.pytheexport()formats. There is oneVertexclass: a vertex has no direction, the graph decides how an edge is recorded (UGraph/DGraphimplement the hooks_attach,_detach,_incomingand_endpoints_match).UVertex/DVertexare deprecated aliases, by module__getattr__. - Records that must agree. A vertex has
_edgelist(leaving, or incident if undirected) and_inlist(entering, directed only); the graph has_vertexlist,_vertexdict(names) and_edges(an insertion-ordered dict).g.validate()checks them all; use it in tests of anything that edits the structure. - Two staleness flags, consumed independently.
_connectivitychange(components, reset by_graphcolor) and_spatialchange(the k-d tree). Set both wherever a vertex is added or removed; only connectivity cares about edges. Never share one flag. Vertex.__setattr__is hot. It exists to tell the graph thatcoordwas assigned. Anything run per vertex (Vertex.__init__,add_vertex, components) writesvertex.__dict__directly to skip it; keep doing that, and declare new attributes at class level so mypy knows them.import pgraphloads only numpy. matplotlib, spatialmath and scipy are imported by the methods that need them (plot,highlight_*,_edge_artist,build_kdtree), and the classes that need matplotlib to be defined are in_plot.py.tests/test_lazy_imports.pyruns a fresh interpreter to check it: do not add a module-level import of them.- Pickle and
copyuse a flat description (__getstate__/__setstate__: vertices, edges by index, replayed through_attach);subgraphreuses it. Derived or transient state on a graph (the k-d tree) must be excluded there. A bare vertex or edge refuses to be pickled or copied. - Tests are
unittestclasses intests/, run withpytest; write expected values by hand or from an oracle in the test, never from the code under test. Import names explicitly (a star import is a CodacyF405); routepicklethrough one helper marked# nosec B301 nosemgrep. Codecov gates patch coverage, so every changed line needs a test.mypy srcis a CI check. - Performance claims are measured.
examples/benchmark.py(--md,--directed) produces the README tables; regenerate them after a performance change and compare withv0.6.5(git archive v0.6.5 src), not with a development build. - Docs are Sphinx (
make -C docs html;-nfor nitpicky) withsphinx-pyrunblock.. runblock:: pyconexamples that execute at build.docs/llms_intro.mdis the hand-written part ofllms.txt: update it when the API changes;docs/llms_txt.pybuildsllms.txtandllms-full.txtfrom it and the toctrees (make html llms), and CI publishes them with the site. - Release. Version is in
pyproject.toml, history inCHANGELOG.md. Publishing is.github/workflows/publish.ymlon a GitHub Release (trusted publishing, environmentpypi): it refuses unless the tag equals the version and the commit is onmain. Don't tag or upload by hand. examples/london.jsonis OpenStreetMap data (© OpenStreetMap contributors, ODbL); keep the attribution with it.