{"id":6640,"library":"flake8-tidy-imports","title":"flake8-tidy-imports","description":"A flake8 plugin that helps you write tidier imports by enforcing rules on import aliases, banned modules, and relative imports. It is currently at version 4.12.0, actively maintained, and supports Python versions 3.10 and newer. Releases typically occur a few times a year, with major versions introducing significant changes.","status":"active","version":"4.12.0","language":"en","source_language":"en","source_url":"https://github.com/adamchainz/flake8-tidy-imports","tags":["flake8","linter","imports","code quality","python","static analysis"],"install":[{"cmd":"pip install flake8-tidy-imports","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"flake8-tidy-imports is a plugin for Flake8 and requires it to run.","package":"flake8","optional":false}],"imports":[],"quickstart":{"code":"import os\n\n# Example file: my_module.py\n# import json as json # I250: Unnecessary import alias\n# from datetime import timedelta as timedelta # I250: Unnecessary import alias\n# from ..utils import helper # I252: Relative import from parent module (if configured)\n# import mock # I251: Banned import 'mock' used - use unittest.mock instead. (if configured)\n\n# Configure flake8 in setup.cfg or pyproject.toml\n# [flake8]\n# banned-modules = \n#   mock = use unittest.mock instead.\n#   django.utils.six = no more six!\n#   {python2to3}\n# ban-relative-imports = parents\n# select = I25\n\n# To run flake8:\n# flake8 my_module.py\n\n# For demonstration purposes, this code is not meant to be run directly\n# but shows common violations flake8-tidy-imports would catch.\n# The actual plugin operates via the flake8 command-line tool.\n\nprint(\"Run 'flake8 <your_file.py>' after configuring flake8-tidy-imports.\")","lang":"python","description":"After installation, `flake8-tidy-imports` automatically registers itself with `flake8`. You typically configure it via a `setup.cfg`, `pyproject.toml`, or `.flake8` file. The primary options are `banned-modules` to specify disallowed imports with custom messages and `ban-relative-imports` to control relative import restrictions. If you use `flake8`'s `select` option, ensure you include `I25` to activate the plugin's checks."},"warnings":[{"fix":"If you explicitly selected or ignored `flake8-tidy-imports` rules in your `flake8` configuration (e.g., `select = I20`), you must update them to the new `I25` prefix (e.g., `select = I25`).","message":"Rule codes were renumbered in version 4.0.0. All rule codes were increased by 50 (e.g., I200 became I250).","severity":"breaking","affected_versions":"<4.0.0 to 4.0.0+"},{"fix":"Ensure your project runs on Python 3.4+ (for older `flake8-tidy-imports` versions) or Python 3.10+ (for current 4.x versions).","message":"Python 2 support was dropped in version 2.0.0.","severity":"breaking","affected_versions":"<2.0.0 to 2.0.0+"},{"fix":"Add `I25` (to enable all `flake8-tidy-imports` rules) or specific rules like `I250`, `I251`, `I252` to your `select` configuration in your `flake8` config file (e.g., `select = E,W,F,I25`).","message":"If `flake8`'s `select` option is defined, `flake8-tidy-imports` rules (I25x) must be explicitly added for the plugin to be active.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use patterns like `example.yellow.*` to match `example.yellow`, `example.yellow.truck`, etc. You can ban `decimal.Decimal` as well as `decimal`.","message":"The `banned-modules` configuration can use wildcards (`*`) to match zero or more path components. It also allows banning imported objects, not just modules.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Add `{python2to3}` to your `banned-modules` list in `flake8` configuration, e.g., `banned-modules = mock = use unittest.mock.\\n{python2to3}`.","message":"A special `{python2to3}` directive can be used within `banned-modules` to automatically ban a preselected list of Python 2-era modules and recommend their Python 3/six replacements.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}