isort
Python command line utility and library that sorts imports alphabetically and groups them into sections by type.
isort is a Python import formatter. It sorts imports alphabetically, splits them into sections by type (for example __future__, standard library, third-party and first-party), and removes duplicates. It ships as a command line utility and a Python library, and editor plugins are listed on the project wiki. It requires Python 3.11+ to run, but it can format Python 2 code.
From the command line, isort file.py file2.py sorts specific files and isort . recurses through a directory. --diff shows proposed changes without applying them. --atomic applies changes only if they don't introduce syntax errors, and it is off by default. -c (--check-only) reports files with incorrectly sorted imports to stderr, which suits CI and Git pre-commit hooks. isort supports pre-commit officially and provides a Git hook function. From Python, isort.file("pythonfile.py") rewrites a file and isort.code("import b\nimport a\n") returns sorted code as a string.
Output is configurable. multi_line_output has 12 wrapping modes for from-imports that exceed line_length. indent accepts a number of spaces, a tab or a quoted string. include_trailing_comma controls trailing commas in parenthesized imports. balanced_wrapping (or -e) picks the line length that gives the most balanced grid. Custom sections and ordering are configurable, and the project provides a Black compatibility guide. A # isort:skip comment skips a single import, and isort:skip_file in a module docstring skips the whole file. isort can also add or remove imports across multiple files. It is aimed at Python developers and teams who want consistent import ordering enforced locally or in CI.
Installation
# via pip
pip install isort
Alternatives & related tools
Grip
Python command-line server that renders local Markdown readme files through the GitHub Markdown API, with live refresh and HTML export.
Hatch
Python project manager covering builds, environments, Python distributions, testing, static analysis, version management, and publishing to PyPI.
harlequin
Terminal-based SQL IDE with database adapter support for DuckDB, SQLite, PostgreSQL, MySQL and dozens of other databases
Azure CLI
Microsoft's cross-platform command-line interface for managing Azure resources with az group/subgroup/command syntax, JMESPath queries, and tab completion.
tox
Command-line virtual environment manager and test runner for Python that automates testing across environments and acts as a frontend to CI servers.
add a badge to your README
Maintain isort? Show that it's featured on trmn. The badge links back to this page.
[](https://www.trmn.sh/tools/isort?utm_source=badge)<a href="https://www.trmn.sh/tools/isort?utm_source=badge"><img src="https://www.trmn.sh/badge/isort.svg" alt="Featured on trmn" height="20"></a>