Skip to content
Latchkey

ruff isort (I): Sort Imports in CI

Ruff includes an isort-compatible import sorter under the I rule family, fixable with ruff check --fix.

You do not need standalone isort with Ruff; enable the I rules and Ruff both flags and fixes import order.

What it does

The I rule family (I001 unsorted imports, I002 missing required import) checks import ordering and grouping. ruff check --fix rewrites imports into the correct order. The [tool.ruff.lint.isort] table tunes grouping, known-first-party packages, and combining behavior.

Common usage

pyproject.toml
# enable import sorting
[tool.ruff.lint]
extend-select = ["I"]

[tool.ruff.lint.isort]
known-first-party = ["myapp"]
combine-as-imports = true

Config keys

KeyWhat it does
I (rule family)Enable import sorting checks
[tool.ruff.lint.isort] known-first-partyPackages treated as first-party
known-third-partyPackages forced into the third-party group
combine-as-importsMerge multiple as-imports from one module
force-single-lineOne import per line

In CI

Enable I in config so import order is enforced consistently, and let developers run ruff check --fix to sort. Drop standalone isort from the pipeline to avoid two tools disagreeing about order.

Common errors in CI

I001 "Import block is un-sorted or un-formatted" fails CI when imports are not ordered; ruff check --fix resolves it. Conflicting results between Ruff and a leftover isort step usually trace to different known-first-party settings; configure one tool, not both. If sorting is not enforced, the I family is probably not selected.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →