isort
isort is a command-line utility and library for Python that automatically sorts and organizes import statements into a consistent, configurable order. By default, it groups them into standard-library, third-party, and local sections, following the import grouping recommended by PEP 8.
Installation and Setup
Install it from the Python Package Index (PyPI) into a virtual environment:
A common setup that aligns with Black is:
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, following the import grouping recommended by PEP 8.
- 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:
$ python -m isort path/to/file.py
$ python -m isort src/ tests/
Check whether imports are correctly sorted without writing changes:
$ python -m isort --check --diff .
Override or fine-tune behavior on the command line:
$ python -m isort --profile black --line-length 100 .
Related Resources
Tutorial
How to Manage Python Projects With pyproject.toml
Learn how to manage Python projects with the pyproject.toml configuration file. In this tutorial, you'll explore key use cases of the pyproject.toml file, including configuring your build, installing your package locally, managing dependencies, and publishing your package to PyPI.
For additional information on related topics, take a look at the following resources:
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Sept. 7, 2026