isort

8.0.1 · active · verified Sat Mar 28

isort is a Python utility and library designed to sort imports alphabetically, automatically separating them into sections by type. It provides a command-line utility, a Python library, and plugins for various editors to streamline import organization. Currently at version 8.0.1, isort maintains an active development pace with frequent major and minor releases, ensuring ongoing feature enhancements and bug fixes.

Warnings

Install

Imports

Quickstart

Demonstrates programmatic use of `isort` to sort a string of Python code and check if it's correctly sorted. The `isort.code()` function takes a string of code and returns the sorted version, while `isort.check_code()` verifies compliance.

import isort

unsorted_code = '''import os
import sys
from third_party import lib
from . import local_module'''

sorted_code = isort.code(unsorted_code)
print(sorted_code)

# Example of checking if code is sorted correctly
is_sorted = isort.check_code(sorted_code)
print(f"Is the code sorted correctly? {is_sorted}")

view raw JSON →