skillfed

toposort

Implements a topological sort algorithm.

toposort v1.10 13.0M downloads/30d#1,297 on PyPI
Permissive license Apache License Version 2.0 Abandoned released

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 toposort

uv

uv add toposort

poetry

poetry add toposort

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python Modules

Tags

topological sortdependency orderingdirected acyclic graphtoposort algorithmprocess dependencies in ordercircular dependency detectionnode ordering
graph-algorithmsdependency-resolution

More Python Modules packages