types-toposort provides type hints (typing stubs) for the `toposort` Python library, which implements a topological sort algorithm for directed acyclic graphs (DAGs). This stub package, currently at version 1.10.0.20260408, is part of the `typeshed` project and is released automatically, often daily, reflecting updates to the underlying typeshed definitions for `toposort`.
pip install toposort types-toposortVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic usage of the `toposort` library for which `types-toposort` provides stubs. It shows how to define dependencies and then perform a layered or flattened topological sort. The input is a dictionary where keys represent dependent nodes, and values are sets of their direct dependencies.
Ensure both `toposort` and `types-toposort` are installed: `pip install toposort types-toposort`.
Ideally, pin `types-toposort` to the same major.minor version as your `toposort` dependency. Be prepared for potential, albeit rare, type-checking issues even with synced major.minor versions due to typeshed's continuous updates.
Ensure your dependency graph is acyclic. Implement cycle detection (e.g., during graph construction) if your input is untrusted or dynamic.
Review `graphlib.TopologicalSorter` documentation in the Python standard library for an alternative to `toposort`.