Python
Snyk support for Python with Snyk Code and Snyk Open Source, including SCM import, CLI and IDE testing, and supported versions
Applicability and integration
Available integrations:
SCM import
CLI and IDE: test or monitor your app
Python for Snyk Code
For an overview of the supported security rules, visit Python rules.
For Python with Snyk Code, Snyk supports Python versions up to 3.12. Snyk Code does not support language features introduced in newer versions.
For Python with Snyk Code, Snyk supports the following file format: .py
Available features:
Reports
Interfile analysis
Supported frameworks and libraries
For Python, Snyk supports the following frameworks and libraries:
AioHTTP
aiofiles
anthropic
argparse
AWS Lambda
bottle
CherryPy
Django
defusedxml
fastapi
fastMCP
flask
flask_pymongo
google.cloud.bigquery
google_generativeai
grpcio
httpx
huggingface_hub
aiopg
LangChain
LangChain LiteLLM
ldap3
libxml
lxml
mistralai
modelcontextprotocol/python-sdk
mongoengine
openai
pandas
paramiko
peewee
pickle
PyYAML
pyca/cryptography
pymongo
pymssql
pyramid
psycopg
python-ldap
Python Standard Library
requests
sqlite3 (or pysqlite2)
sqlalchemy
turboGears
urllib
werkzeug
Snyk Code treats data returned through LangChain LiteLLM as untrusted, so it reports model output that reaches a sink the same way it reports any other untrusted input.
Serverless support
Snyk Code analyzes Python functions that run on AWS Lambda. Snyk resolves handlers from AWS SAM and Serverless Framework configuration files, so it analyzes the function entry point as application code instead of skipping it.
Snyk treats the event data that reaches a handler as a taint source. Injection, path-traversal, and related findings then reflect data entering the function from the service that triggered it. Snyk supports the following triggers:
Amazon API Gateway
Amazon DynamoDB
Amazon EventBridge
Amazon Kinesis
Amazon S3
Amazon SNS
Amazon SQS
Snyk treats the handler event as untrusted as a whole, rather than tracking individual fields in it.
Directory layout
Snyk Code relies on Python projects to follow a standard directory layout for accurate analysis. Specifically, Snyk Code expects Projects to be compatible with setuptools automatic discovery, which identifies packages and modules automatically based on the directory structure. This includes support for __init__.py files to ensure that symbols defined in package initialization files are imported correctly, leading to a more accurate and deeper analysis.
Snyk Code supports both src-layout and flat-layout. When your Project follows these conventions, Snyk Code can trace code effectively and provide accurate results.
Template file analysis
Snyk Code parses template files and follows data from your application code into the template, so it reports a cross-site scripting vulnerability that becomes exploitable only where the template renders its output.
For Python, Snyk Code supports the following template engines:
Jinja2
For file extensions and the full set of supported language and template engine combinations, visit Template file analysis.
Python for Snyk Open Source
For Python with Snyk Open Source, Snyk supports the following Python versions: 2.7, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14, 3.15
Supported package managers and registries
Supported package registry: pypi.org
For Pipenv Projects, Snyk uses Python version information specified in each Pipfile to choose the major and minor versions to use in scanning, for example:
Snyk ignores specific patch versions and uses a recent patch version from each series.
Snyk defaults to Python 3.10 if the Pipfile contains:
No Python version information
Only a major version
An unsupported version
For Poetry Projects, you do not need to specify the Python version. Poetry files contain sufficient information to build a full dependency tree without running native tooling.
Supported file formats
For Poetry:
pyproject.tomlandpoetry.lockFor pip:
requirements.txtFor Pipenv:
PipfileandPipfile.lockFor setup.py:
setup.py
Available features
Automatic and manual Fix PRs (supported only for pip)
License scanning
Reports
Test your app's SBOM and packages using
pkg:pypiPURLs through the SBOM test CLI command
IDE and CI/CD support
If you use a supported IDE to write Python, you must add some configurations to scan Python manifest files properly.
To scan your Projects, you must first install the relevant package manager and ensure that your Project contains the supported manifest files.
Python packages that are operating system-specific and not supported by Linux can be incompatible with Snyk SCM scans and cause errors.
Virtual environment configuration
If you use a virtual environment, you must add the following information:
In your Snyk integration settings, locate the Additional Options field.
Add the
PYTHON_PATHto this field, for example--command=.venv/bin/python.
By default, the Snyk IDE integration looks for a *req*.txt file in the root of the Project as it is seen in the IDE.
Scan multiple directories
If you have manifest files in other directories in the root of the Project, Snyk cannot identify them unless you direct it to.
In your Snyk integration settings, locate the Additional Options field. Enable a recursive search and add the --all-projects option in the Additional Options field.
Last updated
Was this helpful?

