isort - Imports Sorter¶
Main point
Use isort to automatically sort and group Python imports.
There are several knobs configuring isort’s behavior. Full reference of settings can be found on the isort wiki.
You can specify project level configuration by placing
.isort.cfg
file at the root of your project.- An example of preconfigured
.isort.cfg
is in Big-Bang-py.
- An example of preconfigured
It is recommended to include isort in your linting Invoke task and also to run it during Pre-commit Git Hook. Example of both can be found in Big-Bang-py, see project.py and pre-commit files.
To manage edge cases, disable isort:
- per line:
from spam import gouda, eggs # isort:skip # OR from foo import ( # isort:skip baz, bar, )
- per file:
""" Make the best, yet wrongly sorted, spam & eggs. NOTE! To make isort skip an entire file simply, add `isort:skip_file` somewhere in module's docstring, just like below: isort:skip_file """ import spam import eggs