Skip to main content

Pure Python SPQR-Tree implementation

Project description

Description

spqrtree is a pure Python implementation of the SPQR-tree data structure for biconnected graphs. It decomposes a biconnected graph into its triconnected components (S, P, Q, and R nodes) and organizes them as a tree.

SPQR-trees are a classical tool in graph theory, widely used for planarity testing, graph drawing, and network analysis.

The implementation is based on the Gutwenger & Mutzel (2001) linear-time algorithm, with corrections to Hopcroft & Tarjan (1973), and follows the SPQR-tree data structure defined by Di Battista & Tamassia (1996).

Features:

  • Pure Python — no compiled extensions or external dependencies.

  • Handles multigraphs (parallel edges between the same vertex pair).

  • Simple dict-based input for quick prototyping.

  • Typed package with PEP 561 support.

  • Requires Python 3.10 or later.

Installation

You can install spqrtree with pip:

pip install spqrtree

You may also install the latest source from the spqrtree GitHub repository.

pip install git+https://github.com/imacat/spqrtree.git

Quick Start

from spqrtree import SPQRTree, NodeType

# K4 complete graph
graph = {
    1: [2, 3, 4],
    2: [1, 3, 4],
    3: [1, 2, 4],
    4: [1, 2, 3],
}
tree = SPQRTree(graph)
print(tree.root.type)     # NodeType.R
print(len(tree.nodes()))  # number of SPQR-tree nodes

Documentation

Refer to the documentation on Read the Docs.

Change Log

Refer to the change log.

References

  • C. Gutwenger and P. Mutzel, “A Linear Time Implementation of SPQR-Trees,” Graph Drawing (GD 2000), LNCS 1984, pp. 77–90, 2001. doi:10.1007/3-540-44541-2_8

  • J. E. Hopcroft and R. E. Tarjan, “Dividing a Graph into Triconnected Components,” SIAM Journal on Computing, 2(3), pp. 135–158, 1973. doi:10.1137/0202012

  • G. Di Battista and R. Tamassia, “On-Line Planarity Testing,” SIAM Journal on Computing, 25(5), pp. 956–997, 1996. doi:10.1137/S0097539794280736

Acknowledgments

This project was written from scratch in pure Python but drew inspiration from the SageMath project. The SPQR-tree implementation in SageMath served as a valuable reference for both its implementation approach and its comprehensive test cases.

Development was assisted by Claude Code (Anthropic).

Authors

imacat
2026/3/4

Project details


Download files

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

Source Distribution

spqrtree-0.1.1.tar.gz (60.3 kB view details)

Uploaded Source

Built Distribution

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

spqrtree-0.1.1-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file spqrtree-0.1.1.tar.gz.

File metadata

  • Download URL: spqrtree-0.1.1.tar.gz
  • Upload date:
  • Size: 60.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for spqrtree-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e275319ff9a4a6f5b377de29919728d66db609ba101a105be1196bc4f32eec70
MD5 0df2010dea74b57f712ef6365a2daf65
BLAKE2b-256 f7a33288ab5f18eb719b380b9dbb62fae86d1feddf6111ee814dbe2d9632183b

See more details on using hashes here.

File details

Details for the file spqrtree-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: spqrtree-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for spqrtree-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 45be42b444bd66d209bf390c49980f0d2b5f191f88b8b004bc34eddbdea950ac
MD5 951c69490b1f0c361f38c10901131e54
BLAKE2b-256 3cfa9307ba46cc84adf9a0f25d60aa8ef5ef7086ad8555233e9feac52a3c55a3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page