Sort your Python module imports automatically with isort


Python tip:

Instead of trying to keep your imports in order by hand, you can use the isort library.

# install isort
$ pip install isort

# sort a specific file
$ isort myfile.py

# sort all Python files, recursively
$ isort .

# see the differences without applying them
$ isort myfile.py --diff

# confirm changes before applying them
$ isort . --interactive

# check if the imports are sorted properly
$ isort . --check