Planarity is a Python package for testing and manipulating the planarity of undirected graphs. It wraps the Boyer-Myrvold planarity algorithm (C library) and provides functions like is_planar, kuratowski_subgraph, and planar_embedding. The current version is 0.6, released with Cython 3 support, but the library is in maintenance mode with infrequent updates.
pip install planarityVerified import paths — ran on the pinned version, not inferred.
Simple test of planarity for the non-planar graph K5.
Remove parallel edges using set operations: edges = list(set((min(u,v), max(u,v)) for u,v in edges))
Install from a precompiled wheel if available, or use conda; alternatively, use the Cython source and ensure a C compiler is properly configured.
if not planarity.is_planar(edges): sub = planarity.kuratowski_subgraph(edges)
Run 'pip install planarity' in the correct environment.
Install with '--no-cache-dir' or upgrade pip: 'pip install --upgrade pip && pip install planarity'
Remap vertices to consecutive integers starting at 0 before calling planarity functions.