isort
Python import sorter — automatically sorts and organizes import statements according to PEP 8 and configurable profiles. isort features: alphabetical sorting within sections, three-section grouping (stdlib/third-party/local), multi-line import formatting styles, --profile=black/google/django/pycharm for preset configurations, --check-only for CI validation, --diff for showing changes, force_sort_within_sections, known_first_party/known_third_party for classification, skip_glob for excluding files, isort API for programmatic use, pre-commit hook, and compatibility with black formatter via profile=black.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Code formatting tool that modifies Python import sections. No network calls. No security concerns. Modifies files in place — ensure version control before running on important files. Pre-commit hook integration ensures code is committed before modification.
⚡ Reliability
Best When
Maintaining consistent Python import ordering across a project — isort's profile=black mode makes it the standard companion to the black formatter, together covering all code style concerns.
Avoid When
Full code formatting (use black), unused import detection (use autoflake/ruff), or non-Python code.
Use Cases
- • Agent code formatting — subprocess.run(['isort', 'src/'], check=True) — sort all imports in src/; agent CI pipeline ensures consistent import ordering; modifies files in place; combines with black for complete formatting
- • Agent CI import check — subprocess.run(['isort', '--check-only', '--diff', 'src/'], capture_output=True); if result.returncode != 0: print(result.stdout) — check without modifying; agent pre-commit or CI validation shows what would change; --diff shows unified diff of proposed changes
- • Agent pre-commit integration — in .pre-commit-config.yaml: repos: - repo: https://github.com/PyCQA/isort, rev: 5.x.x, hooks: - id: isort, args: ['--profile=black'] — automatic import sorting on commit; agent development workflow enforces import order before each commit
- • Agent programmatic use — from isort import code; sorted_code = code(source_code, profile='black', known_first_party=['myagent']) — sort imports in string; agent code generation tool ensures sorted imports in generated files; profile='black' for black compatibility
- • Agent pyproject.toml config — [tool.isort]: profile = 'black'; known_first_party = ['myagent', 'agent_lib']; skip_glob = ['**/migrations/*'] — project configuration; agent project isort config in pyproject.toml; all team members and CI use same settings; skip_glob excludes auto-generated files
Not For
- • General code formatting — isort only sorts imports; for full formatting use black
- • Removing unused imports — isort only sorts, does not detect unused imports; use autoflake or ruff for unused import removal
- • Non-Python imports — isort is Python-only; for JavaScript/TypeScript use eslint --fix
Interface
Authentication
No auth — local code formatting tool.
Pricing
isort is MIT licensed. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ profile=black is required when using black — isort and black can conflict on multi-line import formatting; isort --profile=black aligns with black's style; without profile: isort and black endlessly reformat each other's changes; always configure: [tool.isort] profile = 'black' in pyproject.toml when using both
- ⚠ known_first_party required for project imports — isort auto-detects some third-party packages but project-specific modules are classified as third-party unless declared; [tool.isort] known_first_party = ['myagent']; without this: project imports sorted in third-party section instead of first-party
- ⚠ --check-only exit code is 1 for any unsorted file — agent CI using check=True with subprocess will raise on any import ordering issue; this is the desired behavior for CI; for local running: use check=False and inspect returncode; exit code confusion: 1 means 'imports need sorting', not 'error'
- ⚠ isort modifies files in place — running isort src/ modifies Python files directly; agent code review pipelines must git commit before running isort or lose changes; use --check-only --diff in CI and run in-place only in pre-commit or local formatting step
- ⚠ Skip auto-generated files — migrations, protobuf-generated code, and other auto-generated files should not be sorted; [tool.isort] skip_glob = ['*/migrations/*', '*/generated/*']; auto-generated imports often have specific ordering requirements; isort will break them
- ⚠ from __future__ imports must stay first — isort correctly places 'from __future__ import annotations' at top; but custom sort orders (force_sort_within_sections) can misplace future imports; verify: isort never moves __future__ imports below other imports; test with: isort --check-only on file with future imports
Alternatives
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for isort.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-06.