Skip to main content

larzgraph

Graphs and the everyday algorithms. Pure Python, zero dependencies.

The useful 90% of a graph library, tiny: build a directed or undirected weighted graph and run traversal, shortest paths, connectivity, ordering, and cycle detection — no networkx, no numpy, nothing to install.

from larzgraph import Graph, DiGraph

g = Graph()
g.add_edge("a", "b"); g.add_edge("b", "c", weight=2)
g.shortest_path("a", "c")          # (['a', 'b', 'c'], 3)
g.connected_components()

dag = DiGraph()
dag.add_edges([("build", "test"), ("test", "deploy")])
dag.topological_sort()             # ['build', 'test', 'deploy']
dag.has_cycle()                    # False

Why

  • The algorithms you actually use — BFS, DFS, Dijkstra shortest paths, connected components, topological sort, cycle detection, and strongly-connected components (Tarjan) — without importing a scientific stack.
  • Directed and undirected, weighted, with a clean small API.
  • Deterministic — traversal and topological order break ties in sorted order, so results are reproducible and testable.
  • Zero dependencies. Great for build-order resolution, dependency graphs, routing, task scheduling, and teaching — anywhere networkx is overkill.

Install

pip install larzgraph

Usage

from larzgraph import Graph, DiGraph

g = Graph()                              # undirected
g.add_edges([("a", "b"), ("b", "c", 4)]) # weight optional (default 1)
g.neighbors("b"); g.degree("b"); g.weight("b", "c")

g.bfs("a"); g.dfs("a")                   # traversal order
g.has_path("a", "c")
g.shortest_path("a", "c")                # (path, distance) via Dijkstra
g.connected_components(); g.is_connected()
g.has_cycle()

d = DiGraph()                            # directed
d.add_edges([("a", "b"), ("b", "c"), ("c", "a")])
d.topological_sort()                     # raises CycleError here
d.has_cycle(); d.is_dag()
d.strongly_connected_components()        # [['a', 'b', 'c']]
d.weakly_connected_components()

Tests

python -m unittest discover -s tests -v   # 24 tests, zero deps

The Larz stack

Pure-Python, zero-dependency building blocks: larz · larzchain · larzmoney · larzcrypt · larzdb · larzagent · larzchart · larzmark · larztask · larzvault · larzvm · larzcache · larzvalidate · larzid · larzrpc · larzstate · larzhttp · larzconf · larzcron · larzlimit · larzlog · larzcli · larzretry · larztime · larzpdf · larzpack · larztemplate · larzcolor · larztable · larzjson · larzbus · larzmigrate · larzgraph

License

MIT © larz-scripter

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

larzgraph-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larzgraph-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file larzgraph-0.1.0.tar.gz.

File metadata

  • Download URL: larzgraph-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzgraph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d9c655188e3236b2ef341aac2427999987eb5db841d581b09aec37ce6667c27
MD5 f0ce7582940728c88e921446bbbb70d7
BLAKE2b-256 28c09d4f54dc894e65ee4352c1276fa268c7d6b55165bcd54eaaed70775c93dd

See more details on using hashes here.

File details

Details for the file larzgraph-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzgraph-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzgraph-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2bcd58978bb8a582bc0c46a922f45756ad8ae9aa5b5d617e40bf7674f4de320
MD5 b743e0b31c5f9903e7fbb34c572e6153
BLAKE2b-256 e64384cefad7d892c5415db0065660f408cd1a15fa15430c06bfd3399b523488

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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