Flake8 Import Order Plugin
A Flake8 and Pylama plugin that checks the ordering of import statements in Python code. It ensures imports are grouped (standard library, third-party, local) and typically alphabetized within groups, though the exact rules depend on the configured style. The current version is 0.19.2, and it maintains an active release cadence with regular updates.
Warnings
- breaking Version 0.19.0 dropped support for Python 3.7 and 3.8. Ensure your Python environment is 3.9+ when upgrading to 0.19.0 or newer.
- gotcha For correct classification of local application imports, you *must* configure `application-import-names` and optionally `application-package-names` in your Flake8 configuration. Without this, your own modules might be incorrectly flagged as third-party.
- gotcha The standard library module list used for classification is vendored and static across all Python versions. This might lead to incorrect classifications if your specific Python environment has a different set of standard library modules (e.g., very old or very new Python versions).
- gotcha The plugin primarily checks module-scope imports. Conditional imports (e.g., inside `if` blocks) are generally ignored, with the exception of imports within `if TYPE_CHECKING:` blocks.
Install
-
pip install flake8-import-order
Imports
- N/A
N/A
Quickstart
# 1. Create a Python file (e.g., my_module.py): # import os # import pytest # from my_app import utils # import sys # # 2. Create a Flake8 configuration file (e.g., .flake8): # [flake8] # import-order-style = google # application-import-names = my_app,my_other_app # To run the check: # flake8 my_module.py # # Expected output for the example above: # my_module.py:2:1: I100 Your import statements are in the wrong order. # my_module.py:3:1: I201 Missing newline between import groups.