Python Wrapper for the Edge Addition Planarity Suite and Graph Library
Actively maintained. Last release 5 months ago, commits in 20 of the last 26 weeks. A safe choice.
pip install planarityPlanarity
The planarity repository provides the source code for the planarity Python package. The planarity package was originally developed to provide Python and NetworkX developers with a Python API to access planar graph testing, embedding, drawing, and forbidden subgraph isolation algorithms from the Edge Addition Planarity Suite (EAPS).
The planarity repository has now been transferred to the Github Graph Algorithms Organization. The planarity repository and Python package have been updated with the full set of planarity-related algorithms from EAPS as well as all public methods from its generalized graph library to enable development of a wide range of high-performance graph algorithms and applications.
Example
In [1]: # Example of the complete graph of 5 nodes, K5
In [2]: # K5 is not planar
In [3]: import planarity
In [4]: edgelist = [('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'),
...: ('b', 'c'),('b', 'd'),('b', 'e'),
...: ('c', 'd'), ('c', 'e'),
...: ('d', 'e')]
In [5]: print(planarity.is_planar(edgelist))
False
In [6]: # remove an edge to make the graph planar
In [7]: edgelist.remove(('a','b'))
In [8]: print(planarity.is_planar(edgelist))
True
In [9]: # make an ascii text drawing
In [10]: print(planarity.ascii(edgelist))
----1---- | | | | | | -3--| | | |||| | -2--||| | | ||| ---4---|| | || ---5----
In [11]: # Shows correspondence between vertex labels and indices
In [12]: print(planarity.mapping(edgelist))
{1: 'd', 2: 'c', 3: 'e', 4: 'a', 5: 'b'}
See here for more examples.
For further details on development setup and installation, please see this wiki page on the planarity repository.