Snyk offers security scanning to test your projects for vulnerabilities, both through your CLI and through different integrations from our UI.
The following describes how to use Snyk to scan your Python projects:
Package managers/Features |
CLI support |
Git support |
License scanning |
Remediation |
Runtime monitoring |
|
---|---|---|---|---|---|---|
![]() |
✔︎ |
✔︎ |
✔︎ |
✔︎ |
||
![]() |
✔︎ |
|
✔︎ |
|
||
![]() |
setup.py |
✔︎ |
|
✔︎ |
✔︎ |
|
|
✔︎ |
|
✔︎ |
✔︎ |
Note
PyPI licenses are supported for all Python projects.
How it works
Snyk CLI tool for Python projects
The way by which Snyk analyzes and builds the tree varies depending on the language and package manager of the project.
Pip
In order to build the dependency tree Snyk analyzes the first requirements.txt
file that it finds. We also scan for installed packages to ensure we don’t miss any packages, even when not explicitly specified in your manifest file.
Pipenv
In order to build the dependency tree Snyk analyzes the Pipfile
file.
setup.py
In order to build the dependency tree Snyk analyzes the setup.py
file, and detects packages listed in the install_requires
key.
There is no auto-discovery for this file, it must be specified manually:
snyk test --file=setup.py
You can convert setup.py
to requirements.txt
by installing the packages into a virtual environment then running pip freeze.
Poetry
To find issues in a Python Poetry application Snyk uses pyproject.toml
and poetry.lock
files. Note both these files must be present for Snyk to identify Poetry dependencies and test for issues.
Additional support details
https://github.com/snyk/snyk-python-plugin/blob/master/lib/types.ts
CLI parameters for Python
Prerequisites
Parameters
When scanning your Python project for vulnerabilities, use these options to modify commands:
Option |
Description |
---|---|
|
Snyk uses Python in order to scan and find your dependencies. Snyk needs the Python version to start scanning, and defaults to "python" If you are using multiple Python versions, use this parameter to specify the correct Python command for execution. For example: |
|
Skip packages when they can’t be found in the environment (for example, private packages that can’t be accessed from the machine running the scan). |
|
Specify a specific file to test. By default, Snyk scans the requirements.txt file on the top level of the project. If explicitly specified with this parameter, Snyk can recognize any manifest files named *req*.txt, where: Each (*) is a wildcard and req can appear anywhere in the file name. For example, Snyk recognizes your manifest file when you have renamed it to requirements-dev.txt. |
|
This parameter is mandatory if you specify a value for the --file parameter that is not to a requirements.txt file. The test fails without this parameter.Specify this parameter with the value pip. |
Git services for Python projects
Python projects can be imported from any of the Git repositories we support.
In order to test your Python projects using pip as a package manager, we analyze your requirements.txt
file, and so you must have this file in your repository before importing.
If you’ve renamed your requirements.txt
files (for example, if you have renamed a file to requirements-dev.txt)
, we try to import every file that follows the *req*.txt
convention as a Python project.
If you are using a package manager that creates different manifest file formats other than requirements.txt
, then either convert or import (depending on the package manager/supported files) the manifest file to the requirements.txt
format.
For example:
dephell deps convert --from=conda --to=requirements.txt
We recommend you create different organizations to work with different Python versions. However, if you prefer to use one organization, add a .snyk file to your repository and specify the desired Python language version.
For example:
language-settings: python: '3.6.2'
Note
Currently, projects built with Pipenv cannot be imported to our UI manually.
Git settings for Python
From the Snyk UI you can configure the pip version you’re using to manage your Python project.
Available settings for Python are:
-
Python 2 (default)
-
Python 3
To update language preferences:
-
Go to Settings > Languages .
-
Click Edit settings for Python to choose the pip version for your projects in this organization.