Skip to content

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:

Language: Windows PowerShell
(venv) PS> py -m pip install isort
(venv) PS> py -m isort --version
Language: Shell
(venv) $ python -m pip install isort
(venv) $ python -m isort --version

A common setup that aligns with Black is:

Language: TOML Filename: 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 like black.
  • 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:

Language: Shell
$ python -m isort path/to/file.py
$ python -m isort src/ tests/

Check whether imports are correctly sorted without writing changes:

Language: Shell
$ python -m isort --check --diff .

Override or fine-tune behavior on the command line:

Language: Shell
$ python -m isort --profile black --line-length 100 .

Course

Absolute vs Relative Imports in Python

If you've worked on a Python project that has more than one file, chances are you've had to use an import statement before. In this course, you'll not only cover the pros and cons of absolute and relative imports but also learn about the best practices for writing import statements.

intermediate best-practices python


By Leodanis Pozo Ramos • Updated May 28, 2026