Registry / testing / flake8-isort

flake8-isort

JSON →
library7.0.0pypypiunverified

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.

pip install flake8-isort flake8 isort
INSTALL
IMPORT
SIG · FLAKE8-ISORT
F
flake8-isort
testingpythonv7.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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')
Debug
Known issues
breakingVersion 7.0.0 dropped support for Python 3.9 and requires `isort` 7.0.0. Ensure your Python and `isort` versions are compatible before upgrading.
fix
Upgrade Python to 3.10+ and install `isort` 7.0.0+. Refer to the `CHANGES.rst` for detailed compatibility matrix.
affects: >=7.0.0
breakingVersion 6.0.0 dropped support for `isort` 4.x and added support for `flake8` 6.0.0. Mismatched `flake8` or `isort` versions can lead to `FailedToLoadPlugin` errors.
fix
Ensure `flake8` is at version 6.0.0+ and `isort` is at version 5.0.0+ (or 7.0.0+ for `flake8-isort` 7.0.0).
affects: >=6.0.0
gotcha`flake8-isort` requires an `isort` configuration file (e.g., `.isort.cfg` or a `[tool.isort]` section in `pyproject.toml`) to function correctly. Without it, it will report an `I002` error ("no configuration found").
fix
Create a configuration file for `isort` in your project root or specify its location using `isort --settings-file`.
affects: All
gotchaDo not use `flake8-isort` simultaneously with `flake8-import-order`. These plugins offer similar functionalities for checking import order and can cause conflicts or redundant checks. `flake8-isort` defers all logic to `isort`.
fix
Choose one plugin based on your preference (e.g., `flake8-isort` if you also use `isort` to fix imports).
affects: All
gotchaIf using `flake8`'s `select` option (to only run specific checks), ensure the 'I' error code category is included (e.g., `--select=E,W,F,I`) to see `flake8-isort`'s reported issues (I001-I005).
fix
Add 'I' to your `flake8` `select` configuration or remove the `select` option to run all checks.
affects: All
Errors
Common errors & fixes
I001 isort found an import in the wrong position
This error occurs when imports in a Python file are not ordered according to the rules defined by the isort library, which flake8-isort enforces.
fix
Run `isort .` from your project's root directory to automatically reorder imports across your project, or manually adjust the import order to comply with isort's standards, potentially configured in a `.isort.cfg` or `pyproject.toml` file.
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "flake8-isort" due to cannot import name 'SortImports' from 'isort'
This error indicates an incompatibility between the installed versions of `flake8-isort` and `isort`, often arising after a major update to `isort` that changes its internal API (e.g., from `isort` v4 to v5).
fix
To resolve this, ensure that your `flake8-isort` version is compatible with your `isort` version. You might need to either downgrade `isort` to a version compatible with your `flake8-isort` (e.g., `pip install 'isort<5'`) or upgrade `flake8-isort` to a version that supports your current `isort` version (e.g., `pip install --upgrade flake8-isort`).
I002 no configuration found (.isort.cfg or [isort] in configs)
This error means that isort (and consequently flake8-isort) could not locate a configuration file, such as `.isort.cfg`, `pyproject.toml` with a `[tool.isort]` section, or `setup.cfg` with an `[isort]` section, in the current directory or its parent directories.
fix
Create a configuration file (e.g., `pyproject.toml` or `.isort.cfg`) in your project's root directory and add a `[tool.isort]` or `[isort]` section with your desired settings to define how isort should organize imports.
flake8-isort doesn't detect isort failures
Even when installed, `flake8-isort` might not report import sorting issues if its error codes (which start with `I`) are not explicitly enabled or are unintentionally ignored in your `flake8` configuration.
fix
Verify your `flake8` configuration (e.g., in `.flake8` or `pyproject.toml`). Ensure that `I` is included in the `select` option (e.g., `select = E,F,W,I`) and not listed in the `ignore` option within the `[flake8]` section.
Upgrade
Version history
7.0.0latest on PyPI · released Oct 25, 2025
Audit
Dependencies
flake8requiredPeer dependency, flake8-isort is a plugin for flake8.
isortrequiredPeer dependency, flake8-isort uses isort's core logic for import sorting.
pythonrequiredRequired Python version.
Agent activity
5 hits · last 30 days
node
4
Resources
flake8-isort — pip install flake8-isort · libregistry