PyCQA /isort

A Python utility / library to sort imports.

★ 6,965⑂ 733👁 39⑃ 1,159● 1,355▤ 128
PythonCreated 2013-09-03isort.readthedocs.io/
6,965
stars
+0+0+2
733
forks
39
watchers
1,159
prs
1,355
issues
128
releases
–
discussions

README

------------------------------------------------------------------------


![Python Version][pypi status]








[pypi status]: https://pypi.org/project/isort/
_________________

Read Latest Documentation - Browse GitHub Code Repository
_________________

 isort your imports, so you don't have to.

isort is a Python utility / library to sort imports alphabetically and
automatically separate into sections and by type. It provides a command line
utility, Python library and plugins for various
editors to
quickly sort all your imports. It requires Python 3.11+ to run but
supports formatting Python 2 code too.

- Try isort now from your browser!
- Using black? See the isort and black compatibility guide.
- isort has official support for pre-commit!

!Example Usage

Before isort:

python
from my_lib import Object

import os

from my_lib import Object3

from my_lib import Object2

import sys

from third_party import lib15, lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14

import sys

from __future__ import absolute_import

from third_party import lib3

print("Hey")
print("yo")


After isort:

python
from __future__ import absolute_import

import os
import sys

from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8,
                         lib9, lib10, lib11, lib12, lib13, lib14, lib15)

from my_lib import Object, Object2, Object3

print("Hey")
print("yo")


 Installing isort

Installing isort is as simple as:

bash
pip install isort


 Using isort

From the command line:

To run on specific files:

bash
isort mypythonfile.py mypythonfile2.py


To apply recursively:

bash
isort .


If globstar
is enabled, isort . is equivalent to:

bash
isort /.py


To view proposed changes without applying them:

bash
isort mypythonfile.py --diff


Finally, to atomically run isort against a project, only applying
changes if they don't introduce syntax errors:

bash
isort --atomic .


(Note: this is disabled by default, as it prevents isort from
running against code written using a different version of Python.)

From within Python:

python
import isort

isort.file("pythonfile.py")


or:

python
import isort

sorted_code = isort.code("import b\nimport a\n")


 Installing isort's for your preferred text editor

Several plugins have been written that enable to use isort from within a
variety of text-editors. You can find a full list of them on the isort
wiki.
Additionally, I will enthusiastically accept pull requests that include
plugins for other text editors and add documentation for them as I am
notified.

 Multi line output modes

You will notice above the \"multi\_line\_output\" setting. This setting
defines how from imports wrap when they extend past the line\_length
limit and has 12 possible settings.

 Indentation

To change the how constant indents appear - simply change the
indent property with the following accepted formats:

-   Number of spaces you would like. For example: 4 would cause standard
    4 sp

Snapshot: 2026-11-04T14:00:00Z · Data license Apache-2.0 · JSON