Skip to main content

Package requirements checker, plugin for flake8

Project description

This module provides a plug-in for flake8, which checks/validates package import requirements. It reports missing and/or not used project direct dependencies.

This plug-in adds new flake8 warnings:

  • I900: Package is not listed as a requirement.
  • I901: Package is required but not used.

Important notice

In order to collect project’s dependencies, this checker evaluates Python code from the file stored in the project’s root directory. Code evaluation is done with the eval() function. As a fall-back method, this checker also tries to load dependencies from the pyproject.toml file from the poetry tool section, or from the requirements.txt text file.

At this point it is very important to be aware of the consequences of the above approach. One might inject malicious code into the file, which will be executed by this checker. Hence, this checker shall NEVER be use to check code from an unknown source! However, in most cases, one validates code from a known source (e.g. own code) and one will run script stored in the file anyway. The worst case scenario is, that this checker will execute the equivalent of the python, which shall be idempotent (it’s a horribly designed file if it’s not).

If you have noticed some side effects during the flake8 check and your file is written in a standard way (e.g. pypa-sampleproject), please fill out a bug report.


You can install, upgrade, or uninstall flake8-requirements with these commands:

$ pip install flake8-requirements
$ pip install --upgrade flake8-requirements
$ pip uninstall flake8-requirements


For projects with custom (private) dependencies, one can provide mapping between project name and provided modules. Such a mapping can be set on the command line during the flake8 invocation with the --known-modules option or alternatively in the [flake8] section of the configuration file, e.g. setup.cfg. The syntax of the custom mapping looks like follows:


If some local project lacks “name” attribute in the file (it is highly discouraged not to provide the “name” attribute, though), one can omit the project name in the mapping and do as follows:


Real life example:

$ cat setup.cfg
max-line-length = 100
known-modules = my-lib:[mylib.drm,mylib.encryption]

If you use the -r flag in your requirements.txt file with more than one level of recursion (in other words, one file includes another, the included file includes yet another, and so on), add the --requirements-max-depth option to flake8 (for example, --requirements-max-depth=3 to allow three levels of recursion).

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for flake8-requirements, version 1.3.0
Filename, size File type Python version Upload date Hashes
Filename, size flake8_requirements-1.3.0-py2.py3-none-any.whl (11.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page