isort 6.0.1


pip install isort

  Latest version

Released: Feb 26, 2025

Project Links

Meta
Author: Timothy Crosley, staticdev
Requires Python: >=3.9.0

Classifiers

Development Status
  • 6 - Mature

Environment
  • Console

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Natural Language
  • English

Programming Language
  • Python
  • Python :: 3
  • Python :: 3 :: Only
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • Software Development :: Libraries
  • Utilities

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


PyPI version Test Lint Code coverage Status License Join the chat at https://gitter.im/timothycrosley/isort Downloads Code style: black Imports: isort DeepSource


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.9+ to run but supports formatting Python 2 code too.

Example Usage

Before isort:

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:

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:

pip install isort

Using isort

From the command line:

To run on specific files:

isort mypythonfile.py mypythonfile2.py

To apply recursively:

isort .

If globstar is enabled, isort . is equivalent to:

isort **/*.py

To view proposed changes without applying them:

isort mypythonfile.py --diff

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

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:

import isort

isort.file("pythonfile.py")

or:

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 space indentation.
  • Tab
  • A verbatim string with quotes around it.

For example:

"    "

is equivalent to 4.

For the import styles that use parentheses, you can control whether or not to include a trailing comma after the last import with the include_trailing_comma option (defaults to False).

Intelligently Balanced Multi-line Imports

As of isort 3.1.0 support for balanced multi-line imports has been added. With this enabled isort will dynamically change the import length to the one that produces the most balanced grid, while staying below the maximum import length defined.

Example:

from __future__ import (absolute_import, division,
                        print_function, unicode_literals)

Will be produced instead of:

from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

To enable this set balanced_wrapping to True in your config or pass the -e option into the command line utility.

Custom Sections and Ordering

isort provides configuration options to change almost every aspect of how imports are organized, ordered, or grouped together in sections.

Click here for an overview of all these options.

Skip processing of imports (outside of configuration)

To make isort ignore a single import simply add a comment at the end of the import line containing the text isort:skip:

import module  # isort:skip

or:

from xyz import (abc,  # isort:skip
                 yo,
                 hey)

To make isort skip an entire file simply add isort:skip_file to the module's doc string:

""" my_module.py
    Best module ever

   isort:skip_file
"""

import b
import a

Adding or removing an import from multiple files

isort can be ran or configured to add / remove imports automatically.

See a complete guide here.

Using isort to verify code

The --check-only option

isort can also be used to verify that code is correctly formatted by running it with -c. Any files that contain incorrectly sorted and/or formatted imports will be outputted to stderr.

isort **/*.py -c -v

SUCCESS: /home/timothy/Projects/Open_Source/isort/isort_kate_plugin.py Everything Looks Good!
ERROR: /home/timothy/Projects/Open_Source/isort/isort/isort.py Imports are incorrectly sorted.

One great place this can be used is with a pre-commit git hook, such as this one by @acdha:

https://gist.github.com/acdha/8717683

This can help to ensure a certain level of code quality throughout a project.

Git hook

isort provides a hook function that can be integrated into your Git pre-commit script to check Python code before committing.

More info here.

Setuptools integration

Upon installation, isort enables a setuptools command that checks Python files declared by your project.

More info here.

Spread the word

Imports: isort

Place this badge at the top of your repository to let others know your project uses isort.

For README.md:

[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

Or README.rst:

.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336
    :target: https://pycqa.github.io/isort/

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Why isort?

isort simply stands for import sort. It was originally called "sortImports" however I got tired of typing the extra characters and came to the realization camelCase is not pythonic.

I wrote isort because in an organization I used to work in the manager came in one day and decided all code must have alphabetically sorted imports. The code base was huge - and he meant for us to do it by hand. However, being a programmer - I'm too lazy to spend 8 hours mindlessly performing a function, but not too lazy to spend 16 hours automating it. I was given permission to open source sortImports and here we are :)


Get professionally supported isort with the Tidelift Subscription

Professional support for isort is available as part of the Tidelift Subscription. Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.


Thanks and I hope you find isort useful!

~Timothy Crosley

6.0.1 Feb 26, 2025
6.0.0 Jan 27, 2025
6.0.0b2 Dec 12, 2022
6.0.0b1 Dec 11, 2022
6.0.0a1 Dec 11, 2022
5.13.2 Dec 13, 2023
5.13.1 Dec 11, 2023
5.13.0 Dec 09, 2023
5.12.0 Jan 28, 2023
5.11.5 Jan 30, 2023
5.11.4 Dec 21, 2022
5.11.3 Dec 17, 2022
5.11.2 Dec 13, 2022
5.11.1 Dec 12, 2022
5.11.0 Dec 12, 2022
5.10.1 Nov 09, 2021
5.10.0 Nov 03, 2021
5.9.3 Jul 29, 2021
5.9.2 Jul 08, 2021
5.9.1 Jun 21, 2021
5.9.0 Jun 21, 2021
5.8.0 Mar 21, 2021
5.7.0 Dec 31, 2020
5.6.4 Oct 13, 2020
5.6.3 Oct 11, 2020
5.6.2 Oct 10, 2020
5.6.1 Oct 08, 2020
5.6.0 Oct 08, 2020
5.5.5 Oct 08, 2020
5.5.4 Sep 30, 2020
5.5.3 Sep 20, 2020
5.5.2 Sep 10, 2020
5.5.1 Sep 04, 2020
5.5.0 Sep 03, 2020
5.4.2 Aug 15, 2020
5.4.1 Aug 13, 2020
5.4.0 Aug 13, 2020
5.3.2 Aug 07, 2020
5.3.1 Aug 07, 2020
5.3.0 Aug 05, 2020
5.2.2 Jul 30, 2020
5.2.1 Jul 29, 2020
5.2.0 Jul 27, 2020
5.1.4 Jul 20, 2020
5.1.3 Jul 19, 2020
5.1.2 Jul 18, 2020
5.1.1 Jul 16, 2020
5.1.0 Jul 15, 2020
5.0.9 Jul 11, 2020
5.0.8 Jul 11, 2020
5.0.7 Jul 10, 2020
5.0.6 Jul 09, 2020
5.0.5 Jul 08, 2020
5.0.4 Jul 06, 2020
5.0.3 Jul 05, 2020
5.0.2 Jul 04, 2020
5.0.1 Jul 04, 2020
5.0.0 Jul 04, 2020
4.3.21 Jun 26, 2019
4.3.20 May 15, 2019
4.3.19 May 13, 2019
4.3.18 May 02, 2019
4.3.17 Apr 07, 2019
4.3.16 Mar 24, 2019
4.3.15 Mar 11, 2019
4.3.14 Mar 10, 2019
4.3.13 Mar 08, 2019
4.3.12 Mar 06, 2019
4.3.11 Mar 06, 2019
4.3.10 Mar 03, 2019
4.3.9 Feb 25, 2019
4.3.8 Feb 25, 2019
4.3.7 Feb 25, 2019
4.3.6 Feb 25, 2019
4.3.5 Feb 25, 2019
4.3.4 Feb 12, 2018
4.3.3 Feb 06, 2018
4.3.2 Feb 05, 2018
4.3.1 Feb 02, 2018
4.3.0 Feb 01, 2018
4.2.15 Jun 07, 2017
4.2.14 Jun 06, 2017
4.2.13 Jun 02, 2017
4.2.12 Jun 01, 2017
4.2.11 Jun 01, 2017
4.2.9 Jun 01, 2017
4.2.8 Jun 01, 2017
4.2.5 Mar 30, 2016
4.2.4 Mar 29, 2016
4.2.3 Mar 28, 2016
4.2.2 Sep 24, 2015
4.2.1 Sep 20, 2015
4.2.0 Sep 19, 2015
4.1.2 Sep 02, 2015
4.1.1 Sep 01, 2015
4.1.0 Aug 30, 2015
4.0.0 Jul 13, 2015
3.9.6 Feb 06, 2015
3.9.5 Feb 05, 2015
3.9.4 Dec 29, 2014
3.9.3 Dec 25, 2014
3.9.2 Dec 22, 2014
3.9.1 Dec 19, 2014
3.9.0 Aug 04, 2014
3.8.3 Jul 21, 2014
3.8.2 Jun 11, 2014
3.8.1 May 15, 2014
3.8.0 Apr 30, 2014
3.7.2 Apr 30, 2014
3.7.1 Apr 25, 2014
3.7.0 Apr 17, 2014
3.6.2 Mar 07, 2014
3.6.1 Feb 24, 2014
3.6.0 Feb 22, 2014
3.5.0 Feb 18, 2014
3.4.2 Feb 09, 2014
3.4.1 Feb 09, 2014
3.4.0 Feb 01, 2014
3.3.1 Jan 31, 2014
3.3.0 Jan 29, 2014
3.2.0 Jan 24, 2014
3.1.2 Jan 20, 2014
3.1.1 Jan 08, 2014
3.1.0 Jan 04, 2014
3.0.0 Jan 02, 2014
2.6.3 Dec 09, 2013
2.6.2 Dec 08, 2013
2.6.1 Dec 07, 2013
2.6.0 Dec 09, 2013
2.5.0 Dec 09, 2013
2.4.1 Dec 10, 2013
2.4.0 Dec 10, 2013
2.3.0 Dec 10, 2013
2.2.1 Dec 10, 2013
2.2.0 Dec 10, 2013
2.1.0 Dec 10, 2013
2.0.1 Dec 10, 2013
2.0.0 Dec 10, 2013
1.3.2 Dec 10, 2013
1.3.1 Dec 10, 2013
1.3.0 Dec 10, 2013
1.2.5 Dec 10, 2013
1.2.3 Dec 10, 2013
1.2.2 Dec 10, 2013
1.2.0 Dec 10, 2013
1.0.1 Dec 10, 2013
1.0.0 Dec 10, 2013

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies: