Skip to main content

SteinerPy

PyPI version PyPI - Downloads Python 3.8+ License: MIT CI/CD codecov Documentation

SteinerPy solves Steiner tree and Steiner forest problems — and many advanced variants — to proven optimality, directly on NetworkX graphs. It uses the open-source HiGHS solver by default, with Gurobi supported as an optional backend.

  • One API, many variants — Steiner tree/forest, prize-collecting, node-weighted, maximum-weight connected subgraph, directed (arborescence), hop-constrained, group, rectilinear, terminal-leaf, and budgeted variants.
  • Exact, with a certificate — every solve reports a proven optimality gap; gap == 0.0 means provably optimal.
  • Fast by default — provably optimum-preserving graph reductions from the Steiner-tree literature run automatically, plus an opt-in dual-ascent accelerator and a heuristic-only mode that stays in NetworkX's speed class while still certifying its gap.

📖 Documentation: steinerpy.readthedocs.io

Installation

pip install steinerpy

Requires Python 3.8+. The HiGHS backend is installed automatically; to use Gurobi instead, install gurobipy and provide a valid license.

Quick start

import networkx as nx
from steinerpy import SteinerProblem

G = nx.Graph()
G.add_edge("A", "B", weight=1)
G.add_edge("B", "C", weight=2)
G.add_edge("C", "D", weight=1)

# One terminal group = Steiner tree; multiple groups = Steiner forest
# Edge/arc costs must be non-negative.
solution = SteinerProblem(G, [["A", "D"]]).get_solution()

print(f"Optimal cost: {solution.objective}")
print(f"Selected edges: {solution.selected_edges}")
print(f"Proven optimality gap: {solution.gap}")  # 0.0 == provably optimal

See the documentation for the full catalogue of problem variants, solver selection, performance features (dual ascent, graph reductions, heuristic-only mode), benchmarks against NetworkX and pcst_fast, and the API reference. The example notebook walks through the main features.

Citing

If you use SteinerPy in your research, please cite:

@article{markhorst2025future,
  title={Future-proof ship pipe routing: Navigating the energy transition},
  author={Markhorst, Berend and Berkhout, Joost and Zocca, Alessandro and Pruyn, Jeroen and van der Mei, Rob},
  journal={Ocean Engineering},
  volume={319},
  pages={120113},
  year={2025},
  publisher={Elsevier}
}

Contributing

Contributions are very welcome! Please read the contributing guidelines and open an issue to discuss your idea before starting on a pull request.

License

SteinerPy is available under the MIT license.

Star History

Star History Chart

Download files

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

Source Distribution

steinerpy-1.0.18.tar.gz (120.9 kB view details)

Uploaded Source

Built Distribution

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

steinerpy-1.0.18-py3-none-any.whl (122.8 kB view details)

Uploaded Python 3

File details

Details for the file steinerpy-1.0.18.tar.gz.

File metadata

  • Download URL: steinerpy-1.0.18.tar.gz
  • Upload date:
  • Size: 120.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for steinerpy-1.0.18.tar.gz
Algorithm Hash digest
SHA256 f76692827041d85a1d6b40d66643ecb0c74180cf1630ebbb0875f7623cc1c35e
MD5 1605900401069198f388a3e75466e44e
BLAKE2b-256 1682b2bd31533a090d09758039afe6d5661b58702040abe40b268f6143b2a71a

See more details on using hashes here.

File details

Details for the file steinerpy-1.0.18-py3-none-any.whl.

File metadata

  • Download URL: steinerpy-1.0.18-py3-none-any.whl
  • Upload date:
  • Size: 122.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for steinerpy-1.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 02a4adc1c3a7b604b755d4a3f335a33fc2b2f942e4f82eecd776787e2e4fa718
MD5 750973e04922f05b42a62d17f8789a4c
BLAKE2b-256 d2ee64aed25f4dcd3e976cff09dc2a1abf1d37f44cc384dcb772a04ca368be1c

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.19

2 files

This release

1.0.18 This release

2 files

1.0.17

2 files

1.0.16

2 files

1.0.15

2 files

1.0.14

2 files

1.0.13

2 files

1.0.12

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

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