This lesson is part of the Automating Python Code Quality course.
In this lesson, you will learn,
- what isort is
- how to install isort
- isort's main configuration options.
What is isort?
isort is a Python library that sorts and formats your imports alphabetically, into sections and by type.
How to Install isort
Installation of isort is performed by running the following:
poetry add -D isort
Usage
isort can be run against a file or directory, or recursively (via .
), like so:
$ isort .
$ isort dir/*
$ isort myfile.py
For example, let’s say we have the following Python script:
import requests, re, ipaddress
from rich import print
from rich import inspect
from rich import console