Python
Language-specific information about the way that SonarQube Cloud supports the analysis of Python.
Supported versions
The level of support for a language is defined as follows:
Fully supported: Analysis will complete. All the language features are understood and examined.
Supported: Most language features are understood and examined but the version includes unsupported features. Analysis might break or provide incomplete results.
Versions 3.0 to 3.13 are fully supported.
Version 2.7 is supported.
Supported tools and frameworks
Django, FastAPI, Flask, Jupyter Notebooks, Numpy, Pandas, PySpark, PyTorch, Tensorflow and Scikit-learn.
Language-specific properties
To discover and update the Python-specific properties, navigate in SonarQube Cloud to Your Project > Administration > General Settings > Languages > Python. See the Analysis parameters page for more information about specific properties.
Handling project python version
Python code is analyzed by default as compatible with python 2 and python 3. Some issues will be automatically silenced to avoid raising False Positives. In order to get a more precise analysis you can specify the python versions your code supports via the sonar.python.version
parameter.
Accepted format are a comma separated list of versions having the format "X.Y"
Examples:
sonar.python.version=2.7
sonar.python.version=3.8
sonar.python.version=2.7, 3.7, 3.8, 3.9
Jupyter Notebooks
Jupyter Notebooks are an open document format based on JSON. They are used for all sorts of data science tasks: data cleaning and transformation, data visualization, statistical modeling, machine learning, deep learning, etc.
Supported versions
SonarQube Cloud can analyze Jupyter Notebooks nbformat.v4 and later.
Specific properties
Discover and update the Jupyter Notebooks-specific Analysis parameters in Administration > General Settings > Languages > Python > Jupyter Notebooks.
Managing rules
Jupyter Notebook rules can be enabled and disabled in your quality profile. See the Quality profile pages for more details.
Jupyter Notebooks in SonarQube for IDE for VSCode
You can analyze your Jupyter Notebooks projects directly in VS Code; see the Scan my project article in the SonarQube for VS Code docs. Note that Connected mode will be ignored when working with Jupyter Notebooks (if using connected mode with Jupyter Notebooks is important to you, please submit the idea on SonarQube Cloud’s portal in Productboard).
Important notes
Only Python code is analyzed in Jupyter Notebooks.
Only primary locations are shown (see the Managing code issues pages to learn more about primary vs secondary locations).
Analysis does not measure code duplication at this time.
Parallel code scan
By default, the Python analyzer tries to parallelize the analysis of files; it uses 90% of the cores available, up until 6.
If required, it is possible to customize the number of scheduled parallel jobs by configuring the property sonar.python.analysis.threads n
at the scanner level, where n
is an integer indicating the number of threads allocated for the analysis.
You should consider setting the sonar.python.analysis.threads
property only when the automatic detection of the number of logical CPUs cannot detect the desired number.
A typical example is when the analysis should not consume all the available computing resources to leave room for other tasks running in parallel on the same machine.
When setting the sonar.python.analysis.threads
property, you should set it to a value less or equal to the number of logical CPUs available. Over-committing does not accelerate the analysis and can even slow it down.
You can disable parallel code scan for Python by setting the property sonar.python.analysis.parallel
to false
. This can be useful when debugging an analysis.
Related pages
Test coverage Overview (the Coverage.py tool provided by Ned Batchelder, Nose, pytest)
Last updated
Was this helpful?