Repolode
PyCQA

PyCQA/flake8-import-order

A flake8 and Pylama plugin that checks whether Python imports are grouped and ordered according to a chosen style guide.

Stars
279
Forks
72
Open issues
15
Last commit
4 days ago

What is it?

flake8-import-order is a linter plugin for flake8 and Pylama that checks only the grouping and ordering of Python import statements. It does not check other aspects of imports. Standard library imports come first, then third-party packages, then local packages, and each group is alphabetized, though the exact rules depend on the selected style.

The plugin adds four warnings: I100 and I101 for out-of-order imports and out-of-order names in a from-import, and I201 and I202 for missing or extra blank lines between import groups. It ships with several built-in styles, including cryptography (the default), google, smarkets, appnexus, edited, pycharm, and pep8, which enforces grouping without ordering within groups. Projects can declare their own application and package names through configuration options.

Custom styles can be added by subclassing the Style class and registering it through setuptools entry points.

Key features

  • 01Checks import grouping and ordering for flake8 and Pylama.
  • 02Provides four warning codes covering order and blank-line issues.
  • 03Includes built-in styles such as cryptography, google, smarkets, and pep8.
  • 04Lets projects configure local application and package names.
  • 05Supports custom styles via subclassing and entry points.

Use cases

  • Enforcing a consistent import layout across a Python codebase in CI.
  • Matching a team's import style guide such as Google's or a project-specific convention.
  • Adding import order checks to an existing flake8 linting setup.

Things to know

  • Licensed under LGPL-3.0, a copyleft license with conditions on redistribution.
  • Checks only module-scope imports; conditional imports are ignored except under TYPE_CHECKING.
  • Ordering is checked only between adjacent imports, so some out-of-order imports may not be reported.

In collections

Topics

#python#linter#flake8#code-style#static-analysis#flake8-extensions#linter-flake8#linter-plugin#pylama

FAQ

What is flake8-import-order?
A flake8 and Pylama plugin that checks whether Python imports are grouped and ordered according to a chosen style guide. flake8-import-order is a linter plugin for flake8 and Pylama that checks only the grouping and ordering of Python import statements. It does not check other aspects of imports. Standard library imports come first, then third-party packages, then local packages, and each group is alphabetized, though the exact rules depend on the selected style.
Is flake8-import-order free to use? What license does it have?
flake8-import-order is open source under the LGPL-3.0 license. Check the license terms before using it in commercial products.
Is flake8-import-order still maintained?
Actively maintained. The last commit to flake8-import-order was on Nov 3, 2026.
What can I use flake8-import-order for?
Enforcing a consistent import layout across a Python codebase in CI. Matching a team's import style guide such as Google's or a project-specific convention. Adding import order checks to an existing flake8 linting setup.
Where can I get flake8-import-order?
The source code and installation instructions are on GitHub: https://github.com/PyCQA/flake8-import-order

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects