flake8-isort

7.0.0 · active · verified Sat Apr 11

flake8-isort is a flake8 plugin that integrates the isort library to check the order of imports in Python files. It leverages isort's sorting logic and configuration (e.g., via .isort.cfg or pyproject.toml) to report import style violations as flake8 errors. Regularly maintained, its current version is 7.0.0, released in October 2025.

Warnings

Install

Quickstart

To use flake8-isort, first install it along with flake8 and isort. Then, create an `isort` configuration file (e.g., `.isort.cfg` or within `pyproject.toml`) to define your preferred import sorting style. Finally, run `flake8` as you normally would; `flake8-isort` will automatically detect and report import order issues based on your `isort` configuration.

# 1. Install dependencies (if not already installed)
# pip install flake8-isort flake8 isort

# 2. Create an example Python file (e.g., `my_module.py`)
# This file has unsorted imports
# print("Content of my_module.py:")
# print("""
# import os
# import sys
# from datetime import datetime
# from collections import defaultdict
# """)

# 3. Create an isort configuration file (e.g., .isort.cfg or pyproject.toml)
# Example .isort.cfg:
# [isort]
# profile = black
# known_third_party = datetime,collections
# 
# Or in pyproject.toml:
# [tool.isort]
# profile = "black"
# known_third_party = ["datetime", "collections"]

# 4. Run flake8 (flake8-isort will automatically integrate)
# For demonstration, let's create a dummy file and config
import os

# Create a dummy Python file
with open('temp_module.py', 'w') as f:
    f.write('import os\nfrom sys import argv\nimport collections\n\ndef func(): pass\n')

# Create a dummy isort config file
with open('.isort.cfg', 'w') as f:
    f.write('[isort]\nprofile = black\n')

# To run flake8 with flake8-isort, you'd typically execute from your shell:
# flake8 temp_module.py
# The output would show I001 (isort found an import in the wrong position)

# Clean up dummy files
os.remove('temp_module.py')
os.remove('.isort.cfg')

view raw JSON →