In this lesson, you will learn,

  • what isort is
  • how to install isort
  • isort's main configuration options.
You can find the scripts and code for this course within the Automating Python Code Quality repo.

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


isort can be run against a file or directory, or recursively (via .), like so:

$ isort .
$ isort dir/*
$ isort

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
Members Only Content
Want to Learn Network Automation?
Join our membership to access:
  • Full deep-dive course library (inc. Batfish, pyATS, Netmiko)
  • Code repositories inc. full course code, scripts and examples
  • 24x7 multi-vendor labs (Arista, Cisco, Juniper)
  • Private online community
  • Tech demos and sessions

Join Now ➜
Close You've successfully subscribed to Packet Coders.
Close Success! Your account is fully activated, you now have access to all content.
Close Welcome back! You've successfully signed in.
Close Nearly there! To activate your account, please click the link in the email we just sent you.