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

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
Ready to Master Network Automation? Start Your Journey Today!
Our membership provides:
  • 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
  • Live monthly tech sessions
  • Access to tech session library

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.