isort
isort is a command-line utility and library for Python that automatically sorts and organizes import statements into a consistent, configurable order.
Installation and Setup
Install it from the Python Package Index (PyPI) into a virtual environment:
A common setup that aligns with Black is:
TOML
pyproject.toml
[tool.isort]
profile = "black"
line_length = 88
known_first_party = ["package_name"]
src_paths = ["src"]
Key Features
- Groups and orders imports by section, such as standard-library, third-party, and local modules.
- Enforces consistent formatting of single and multi line imports and can combine or split imports as configured.
- Reads settings from
pyproject.toml,setup.cfg, or.isort.cfg, with ready made profiles likeblack. - Provides a check mode and clear exit codes for continuous integration and pre-commit workflows.
- Supports per-file ignores and skip patterns to fine-tune what gets formatted.
Usage
Sort imports in a file or directory in place:
Shell
$ python -m isort path/to/file.py
$ python -m isort src/ tests/
Check whether imports are correctly sorted without writing changes:
Shell
$ python -m isort --check --diff .
Override or fine-tune behavior on the command line:
Shell
$ python -m isort --profile black --line-length 100 .
By Leodanis Pozo Ramos • Updated Dec. 12, 2025