toposort
Implements a topological sort algorithm.
What it is and what it does
toposort is a pure Python implementation of the topological sorting algorithm. It takes a dictionary where each key is a node and its value is a set of nodes it depends on, then returns an iterator of sets representing valid processing orders—nodes with no remaining dependencies come first. If a circular dependency exists, it raises CyclicDependencyError with details about the cycle.
The package is straightforward and self-contained, with no external runtime dependencies. It supports both granular iteration (toposort) and flattened output (toposort_flatten), making it suitable for build systems, task scheduling, and any workflow requiring dependency resolution. The implementation handles arbitrary hashable node types, not just integers.
Use it for:
- Determine build order for interdependent software modules or packages.
- Schedule task execution respecting prerequisite constraints in workflow systems.
- Resolve import or initialization order in complex codebases with circular-dependency detection.
- Order database migrations or schema changes based on foreign-key dependencies.
- Compute execution order for computation graphs in data pipelines.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements topological sorting of directed acyclic graphs, ordering nodes so dependencies are processed before dependents.
Yes, if you need a simple, dependency-free topological sort. The algorithm is stable and well-tested (Production/Stable status), and the abandoned maintenance status poses minimal risk for a mature, narrow-scope library. Use it for straightforward dependency ordering; if you need advanced graph algorithms or active support, consider alternatives.
Install
toposort on PyPI
pip
pip install toposortuv
uv add toposortpoetry
poetry add toposortInstalling toposort
Before you install
Low install friction with no runtime dependencies. Package is marked abandoned (last release 2023-02-25, 1266 days ago), so expect no active maintenance or bug fixes.
License in practice
Apache License 2.0 (permissive) allows use in most projects without significant restrictions.
Quickstart
from toposort import toposort, toposort_flatten
data = {2: {11}, 9: {11, 8, 10}, 10: {11, 3}, 11: {7, 5}, 8: {7, 3}}
result = list(toposort(data))
flat = toposort_flatten(data)
Verify before relying
- Whether the abandoned status affects reliability for stable, well-tested algorithms like topological sort.
- Performance characteristics on large graphs or whether there are known limitations in the implementation.
Package facts
| License | Apache License Version 2.0 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,266 days since the last release |
| First released | |
| Downloads | 13,017,745/month — #1,297 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: toposort-1.10-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
bigtreeBigtree provides tree, binary tree, and…
permissive · top 15,000 on PyPI
cyclicDetects and reports cyclic relationships in a…
permissive · top 15,000 on PyPI
types-toposortProvides type hints for the toposort package,…
permissive · top 15,000 on PyPI
altgraphaltgraph constructs and analyzes graphs…
permissive · top 5,000 on PyPI
DijkstarDijkstar implements Dijkstra's shortest-path…
permissive · top 15,000 on PyPI
objectgraphObjectgraph provides a Python class for…
permissive · top 15,000 on PyPI
asciidagRenders directed acyclic graphs as ASCII art in…
copyleft · top 15,000 on PyPI
anastructAnalyzes 2D frames and trusses to compute…
copyleft · top 15,000 on PyPI
grandalfGrandalf computes node coordinates and routes…
copyleft · top 5,000 on PyPI
natsortnatsort provides natural sorting for strings…
permissive · top 1,000 on PyPI