flake8-requirements

2.3.0 · active · verified Fri Apr 17

flake8-requirements is a plugin for the flake8 static analysis tool that checks for missing or unused package requirements in Python projects. It helps maintain clean and accurate dependency lists by comparing imported modules against entries in requirements files (e.g., `requirements.txt`) or `pyproject.toml`. The current version is 2.3.0, and its release cadence is generally tied to bug fixes, new features, or compatibility updates for `flake8`.

Common errors

Warnings

Install

Quickstart

After installing `flake8-requirements`, it automatically integrates with `flake8`. Simply run `flake8` in your project directory. The plugin will check your imports against your `requirements.txt` (or a file specified by `--requirements-file`) and report missing (R001) or unused (R002) dependencies.

#!/bin/bash
# Create a dummy project for demonstration
mkdir my_project
cd my_project

echo "import requests\nprint('Hello')" > app.py
echo "requests" > requirements.txt

# Install flake8 and the plugin
pip install flake8 flake8-requirements

# Run flake8 with the plugin
flake8 .

# Example of a missing dependency error (R001)
echo "import unknown_lib\nimport requests" > app.py
flake8 .

# Example of an unused dependency error (R002)
echo "requests\nunused_lib" > requirements.txt
echo "import requests" > app.py
flake8 .

view raw JSON →