Skip to main content

Concurrently detect the minimum Python versions needed to run code

Project description

PyPI version Build Status Coverage Commits since last


Concurrently detect the minimum Python versions needed to run code. Additionally, since the code is vanilla Python, and it doesn’t have any external dependencies, it works with v2.7+ and v3+.

It functions by parsing Python code into an abstract syntax tree (AST), which it traverses and matches against internal dictionaries with 1000 rules divided into 124 modules, 668 classes/functions/constants members of modules, 179 kwargs of functions, 4 strftime directives, 2 array typecodes, 3 codecs error handler names, and 20 codecs encodings. Including looking for v2/v3 print expr and print(expr), long, f-strings, coroutines (async and await), boolean constants, "..".format(..), imports (import X, from X import Y, from X import *), function calls wrt. name and kwargs, strftime + strptime directives used, and function, function and variable annotations, array typecodes, codecs error handler names and encodings. It tries to detect and ignore user-defined functions, classes, arguments, and variables with names that clash with library-defined symbols.


It is fairly straightforward to use Vermin:

./ /path/to/your/project

Or via PyPi:

% pip install vermin
% vermin /path/to/your/project

When using continuous integration (CI) tools, like Travis CI, Vermin can be used to check that the minimum required versions didn’t change. The following is an exerpt:

- ./
- pip install vermin
- vermin -t=2.7 -t=3 project_package


% ./
Vermin 0.6.2
Usage: ./ [options] <python source files and folders..>

  -q    Quite mode. It only prints the final versions verdict.
  -v..  Verbosity level 1 to 3. -v, -vv, and -vvv shows increasingly more information.
        -v    will show the individual versions required per file.
        -vv   will also show which modules, functions etc. that constitutes
              the requirements.
        -vvv  will also show line/col numbers.
  -t=V  Target version that files must abide by. Can be specified once or twice.
        If not met Vermin will exit with code 1.
  -p=N  Use N concurrent processes to analyze files (defaults to all cores = 8).
  -i    Ignore incompatible version warnings.
  -l    Lax mode: ignores conditionals (if, ternary, for, while, try, bool op) on AST
        traversal, which can be useful when minimum versions are detected in
        conditionals that it is known does not affect the results.
  -d    Dump AST node visits.
        Analyze 'hidden' files and folders starting with '.' (ignored by default).

% ./ -q vermin
Minimum required versions: 2.7, 3.0

% ./ -q -t=3.3 vermin
Minimum required versions: 2.7, 3.0
Target versions not met:   3.3
% echo $?

% ./ -v examples
Detecting python files..
Analyzing 6 files using 8 processes..
2.7, 3.2     /path/to/examples/
2.7, 3.0     /path/to/examples/
2.0, 3.0     /path/to/examples/
!2, 3.4      /path/to/examples/
Minimum required versions:   3.4
Incompatible versions:         2

% ./ -vv /path/to/examples/
Detecting python files..
Analyzing using 8 processes..
!2, 3.4      /path/to/examples/
  'abc' requires (2.6, 3.0)
  'abc.ABC' requires (None, 3.4)

Minimum required versions: 3.4
Incompatible versions:     2

% ./ -vvv /path/to/examples/
Detecting python files..
Analyzing using 8 processes..
!2, 3.4      /path/to/examples/
  L1 C7: 'abc' requires (2.6, 3.0)
  L2: 'abc.ABC' requires (None, 3.4)

Minimum required versions: 3.4
Incompatible versions:     2

Known Limitations

Vermin parses Python source code into abstract syntax trees (ASTs) which it traverses to do analysis. However, it doesn’t do conditional logic, i.e. deciding which branches will be taken at runtime, since it can cause unexpected side-effects to actually evaluate code. As an example, analysis of the following:

if False:
  print(f"..but I won't be evaluated")

Will yield “f-strings require 3.6+” even though the branch will not be evaluated at runtime.

The lax mode, via argument -l, was created to circumvent cases like this. But it’s not a perfect solution since it will skip all if, ternarys, for, while, try, and boolean operations. Therefore it is recommended to run with and without lax mode to get a better understanding of individual cases.


Contributions are very welcome, especially adding and updating detection rules of modules, functions, classes etc. to cover as many Python versions as possible. For PRs, make sure to keep the code vanilla Python and run make test first. Note that code must be remain valid and working on Python v2.7+ and v3+.

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 vermin, version 0.6.2
Filename, size File type Python version Upload date Hashes
Filename, size vermin-0.6.2-py2.py3-none-any.whl (26.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page