Skip to main content

digraphtools

Some tools for working with directed acyclic graphs, partial orders and topological sorting with Python

digraphtools was written as a lightweight way of using DAGs and partial ordering to represent, sort and traverse dependency trees in a lightweight way.

The code is hosted on github at https://github.com/dbasden/python-digraphtools

Graph Representation

Graphs

A graph is represented as a dict which maps a node to a list nodes connected via the outgoing edges of that node.

e.g.

graph = { 1: [2,3],

2: [3], 3: [] }

is a DAG represented by the edges (1,2) (1,3) (2,3) where the edge 2tuple is in the form of (from,to)

There are helper methods in deptools to generate graphs from a list of edges, and vice versa

Binary relations

If a DAG represents dependencies, e.g. the edge (1,2) is taken to mean “1 depends on 2”, this is backwards from a binary relation. (1,2) would be the relation 2P1

Topological Sorting

There are two ways of generating linear extensions / topological sorts of dependencies (i.e. orders items must be processed in to satisfy dependency requirements):

deptools.dfs_topsort_traversal

deptools.dfs_topsort_traversal will take a graph and iterate over a single valid topologicaly sorted order

deptools.topsort.vr_topsort

deptools.topsort.vr_topsort will generate all valid linear extensions / topological orderings given an initial ‘seed’ linear extension (such as the one generated by deptools.dfs_topsort_traversal).

The method does not take the graph format as used by deptools as input, but it does have a helper method to generate it’s input matrix from a partial order set (which can be generated from a graph using helpers in deptools).

See the examples in topsort.py and test/test_topsort.py for how to do this.

Authors

digraphtools was initially written by David Basden

Thanks

Thanks to Yaakov L. Varol and Doron Rotem for the design of the algorithm in topsort.py

Metadata

Release files for digraphtools 0.2.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 digraphtools 0.2.0
File Size Uploaded Provenance Actions
digraphtools-0.2.0.tar.gz 7.7 kB Without provenance Details for digraphtools-0.2.0.tar.gz

Release files / digraphtools-0.2.0.tar.gz

Download URL digraphtools-0.2.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dcda4a47c4845996f9921b6739167d497dcd71f38059da076d51dcf4b74a38f4
BLAKE2b-256 checksum
How to use checksums
6f0f61d2b62da73e8fdf9dac96f4d730318e105f6464875a3d60ee645851bd23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for digraphtools 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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