Skip to main content

GA Graph

CI PyPI Python

GA Graph provides lightweight dictionary-backed graph containers, path collections, turn classification helpers, and a link-based time-dependent shortest-path router.

The PyPI distribution is named ga-graph; the import package is named graph.

Installation

python -m pip install ga-graph

Development and test tools are available as extras:

python -m pip install -e ".[test]"
python -m pip install -e ".[dev]"

Quick Start

from graph import Graph

network = Graph(total_time=60, delta_t=15)
network.add_node("A")
network.add_node("B")
network.add_link("ab", "A", "B", cost=5)

assert network.get_link("ab").i == "A"
assert network.get_node_degree("A", include_in_links=False) == 1

Graphs

Graph stores nodes, directed links, and turns in dictionary-backed containers. Each entity keeps a required identifier plus arbitrary extra attributes.

from graph import ActionPolicy, Graph

network = Graph()
network.add_link(
    "ab",
    "A",
    "B",
    on_missing_node=ActionPolicy.REPLACE,
    capacity=1200,
)
network.add_turn("ab_bc", "ab", "bc", on_missing_link=ActionPolicy.IGNORE)

Duplicate and missing references can be handled with ActionPolicy.RAISE, WARN, IGNORE, REPLACE, or SKIP, depending on the method.

Paths

Path stores a source, target, departure time, optional mode, link sequence, and cumulative costs. PathList stores one path per (source, target, t_start, mode) key. KPathList stores multiple ranked paths for the same key.

from graph import KPathList, Path

paths = KPathList()
paths.add_path(Path("A", "C", 0, links=["ab", "bc"], costs=[5, 9], mode="car"))
paths.add_path(Path("A", "C", 0, links=["ac"], costs=[12], mode="car"))

best = paths.path("A", "C", 0, "car", k=0)
second = paths.path("A", "C", 0, "car", k=1)

Time-Dependent Routing

TimeDependentLinkBasedShortestPath builds a dense routing view from a Graph. Scalar costs are expanded across the graph time horizon; sequence costs are used as piecewise-constant time profiles.

from graph import Graph, TimeDependentLinkBasedShortestPath

network = Graph(total_time=60, delta_t=15)
for node in ["A", "B", "C"]:
    network.add_node(node, cost=0)

network.add_link("ab", "A", "B", cost=1)
network.add_link("bc", "B", "C", cost=1)
network.add_link("ac", "A", "C", cost=10)

router = TimeDependentLinkBasedShortestPath.from_graph(network, link_cost_field="cost")
path = router.shortest_paths("A", "C").path("A", "C", 0, None)

assert path.get_links() == ("ab", "bc")
assert path["tot_cost"] == 2

The router supports optional mode fields, node costs, turn costs, and prohibited turn fields.

API Summary

  • Graph(t0=0, total_time=60, delta_t=15, **kwargs)
  • Graph.add_node(idx, on_existing=ActionPolicy.RAISE, **kwargs)
  • Graph.add_link(idx, i, j, on_existing=..., on_missing_node=..., **kwargs)
  • Graph.add_turn(idx, in_link, out_link, on_existing=..., on_missing_link=..., **kwargs)
  • Graph.get_node(idx), Graph.get_link(idx), Graph.get_turn(idx)
  • Graph.remove_node(idx, cascade=False), Graph.remove_link(idx, cascade=False)
  • Graph.remove_redundants()
  • Path(source, target, t_start, links=None, costs=None, mode=None, ...)
  • PathList()
  • KPathList()
  • TurnType.parse(value) and TurnType.classify_turn(...)
  • TimeDependentLinkBasedShortestPath.from_graph(graph, ...)
  • TimeDependentLinkBasedShortestPath.shortest_paths(source, targets=None, t_start=0)

Development

GA Graph supports Python 3.10 and newer.

python -m pip install -e ".[dev]"
python -m compileall -q src
python -m pytest --cov=graph --cov-report=term-missing
ruff format --check .
ruff check .
mypy
python -m pip check
python -m build
python -m twine check dist/*

GitHub Repository Setup

This project is prepared for the future repository andreagemma/graph.

  1. Create the empty repository on GitHub.
  2. Initialize the local repository if needed and push the project to main.
  3. Confirm the CI workflow passes on GitHub.
  4. Configure the PyPI Trusted Publisher for project ga-graph, owner andreagemma, repository graph, workflow release.yml, and environment pypi.

Releases

src/graph/_version.py is the only version source. To publish a release:

  1. Update __version__ in _version.py and commit the release changes.
  2. Push main and wait for CI to pass.
  3. Run the Create release GitHub Actions workflow. With no override it creates the v<version> tag, creates release notes, and dispatches the build and PyPI publication workflow.

PyPI versions are immutable. Increment _version.py before publishing different content.

License

GA Graph is distributed under the MIT License. See LICENSE.

Release files for ga-graph 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ga-graph 0.1.0
File Size Uploaded
ga_graph-0.1.0.tar.gz 19.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ga-graph 0.1.0
File Interpreter ABI Platform
ga_graph-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 41.4 kB

Release files / ga_graph-0.1.0.tar.gz

Download URL ga_graph-0.1.0.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5def25cf12c6d3b83234371360d1721b589ba91ad36f1e49988a71069d4dc70d
BLAKE2b-256 checksum
How to use checksums
f1454616427224988c79cc3ba5c08acc8cdec56ac18c95c86a4bfdcd2e981fa1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release files / ga_graph-0.1.0-py3-none-any.whl

Download URL ga_graph-0.1.0-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f98c402bb14661d1565207e29940428df96c4e9646af9e6d61becc5e27196d8c
BLAKE2b-256 checksum
How to use checksums
eff37d354b74fa578050b59c71118f28e587bb15220d5e46283bd9de11638484
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page