explaingit

pycqa/isort

6,944PythonAudience · developerComplexity · 1/5LicenseSetup · easy

TLDR

A one-command Python utility that automatically sorts and groups the import statements at the top of your Python files, keeping them clean, alphabetical, and consistently organized without any manual work.

Mindmap

mindmap
  root((isort))
    What It Does
      Sorts Python imports
      Groups by category
      Removes duplicates
    Import Groups
      Standard library
      Third-party packages
      Your own code
    Usage Modes
      Command-line tool
      Python library
      Editor plugins
      Git hook
    Configuration
      Line length
      Custom sections
      Skip files
    Ecosystem
      PyCQA organization
      CI integration
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Run isort on a Python project before committing to automatically clean up all import statements in one pass.

USE CASE 2

Add isort to a CI pipeline in check-only mode to fail the build when imports are not sorted.

USE CASE 3

Install the editor plugin for VS Code or PyCharm to have imports sorted automatically as you write code.

USE CASE 4

Configure isort to match your project's specific line length and import grouping conventions.

Tech stack

Python

Getting it running

Difficulty · easy Time to first run · 5min

Requires Python 3.10 or higher to run the tool itself, though it can sort code written for older Python versions.

Free to use for any purpose, including commercial use, as long as the MIT copyright notice is kept.

In plain English

isort is a small utility for Python developers that automatically cleans up and reorganizes the import statements at the top of Python files. In Python, every file usually starts with a list of imports (lines that bring in code from other files or packages). These can easily become jumbled over time as a codebase grows. isort sorts them alphabetically, groups them by category (standard library, third-party packages, your own code), and removes duplicates. The tool can be run from the command line on a single file, a folder, or an entire project. It also has a check-only mode that reports which files have unsorted imports without modifying them, which is useful in automated testing or continuous integration pipelines. A git hook integration lets it run automatically before each commit. Isort can also be used directly in Python code as a library, and editor plugins exist for a range of text editors and IDEs so imports get sorted as you work. Configuration options cover things like line length, how long import lines wrap, whether to include trailing commas, and how to order custom sections beyond the built-in groupings. Individual imports or entire files can be marked to skip sorting using inline comments or a marker in the file's docstring. Installation is a single pip command. The project requires Python 3.10 or higher to run the tool itself, but it can format code written for older Python versions including Python 2. Isort is part of the PyCQA (Python Code Quality Authority) organization, which maintains several widely used Python code quality tools. It is MIT licensed and actively maintained with a full documentation site.

Copy-paste prompts

Prompt 1
I want to add isort to my Python project's pre-commit hooks so imports are sorted automatically on every commit. Show me the .pre-commit-config.yaml entry.
Prompt 2
My project uses a custom section for internal packages in isort. How do I configure known_third_party and known_first_party to get the grouping right?
Prompt 3
How do I mark a specific file in my Python project so isort skips sorting it entirely?
Prompt 4
I want to run isort in CI to fail the build when imports are unsorted, without modifying any files. What flag do I use?
Prompt 5
Show me how to use isort as a Python library inside a script to sort imports in a string of Python code programmatically.
Open on GitHub → Explain another repo

← pycqa on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.