Model Directed and Undirected Graphs in Pure Python with Liasis-Graph
Prototyping task dependencies, state transitions, or small network topologies in Python often pushes teams between two awkward choices: pulling in a large scientific graph package for fifty lines of logic, or hand-rolling nested dictionaries whose directed and undirected rules silently drift apart. Worse, older lightweight graph utilities frequently point to test runners like nose that no longer…
To work with prototype dependencies, state transitions, or small network topologies in Python, teams often face a dilemma: choosing between using a large scientific graph package for many lines of code or creating hand-rolled nested dictionaries that can cause confusion as directed and undirected rules diverge. Moreover, older lightweight graph utilities may reference test runners such as nose, which are no longer compatible with Python 3.12 and newer versions.
Liasis-Graph, available under the MIT license at paladini/UFSC-graphs, provides a solution to these problems. It is a zero-dependency Python module that models both undirected (digraph=False) and directed (digraph=True) graphs using dictionary-of-sets adjacency tables. The module enforces mode boundaries through DigraphError and NotDigraphError exceptions.
To use Liasis-Graph, one should always pass a fresh {} dictionary to the Graph constructor to prevent a mutable default argument leak. The module includes core operations and additional methods like is_regular() and is_complete(). When testing, make sure to run the standard-library unittest suite without nose, as nose is not compatible with recent Python versions.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to