Skip to main content

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

Metadata

Release files for spqrtree 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spqrtree 0.1.2
File Size Uploaded Provenance
spqrtree-0.1.2.tar.gz 62.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spqrtree 0.1.2
File Interpreter ABI Platform
spqrtree-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 94.6 kB

Release files / spqrtree-0.1.2.tar.gz

Download URL spqrtree-0.1.2.tar.gz
Size 62.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b9b79fd657275f258ad7571c9988cc1ea5aa25066a656f83d6e228b55f641b6f
BLAKE2b-256 checksum
How to use checksums
3aea0c904bb145540b5d3d5befc731fe07223df307a4c0f554ff6135078a24a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / spqrtree-0.1.2-py3-none-any.whl

Download URL spqrtree-0.1.2-py3-none-any.whl
Size 32.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4572c7467f70aa833e66fd15c608579d00690568511d67cbc5dc475f59820041
BLAKE2b-256 checksum
How to use checksums
c9d65fda700d7486755b9eef2c5a97b1f79b27d65f993e50ee16ed7629fbd3d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for spqrtree 0.1.2

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.

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