Skip to main content

Python

This article shows you how to analyze your applications written in Python using Qwiet AI by Harness.

Requirements

See Prerequisites for more information.

Analyzing your Python application

sl analyze --app <name> --pythonsrc [<path>]
ParameterDescription
--app <name>The name of the application to be analyzed
--pythonsrcThe flag identifying the application as written in Python
<path>The path to the Python application to be analyzed

Additional parameters​

The analysis accepts additional parameters after a double hyphen --.

Additional parameterDescription
--exclude <path>Exclude the specified file/directory during code analysis; can be relative to the project directory or absolute; can be specified multiple times
--exclude-regex <value>A regex specifying files to exclude (matched against paths relative to the input directory)
--ignore-pathsIgnores the specified paths from the analysis. Accepts both absolute and relative file paths; relative file paths are interpreted in relation to the directory provided as part of sl analyze...
--ignore-dir-namesExcludes all files where the relative path (from directory provided in sl analyze) contains at least one of names specified here

Such parameters, if valid, are passed directly to the Python analyzer.

Sample usage of additional parameters

To exclude specific files or directories from the analysis:

sl analyze --app <name> --pythonsrc [<path>] -- --exclude <path>

To exclude files or directories based on a regular expression match:

sl analyze --app <name> --pythonsrc [<path>] -- --exclude-regex <expression>

To ignore a specific path from the analysis:

sl analyze --app <name> --pythonsrc [<path>] -- --ignore-paths [<path>]

SCA​

To identify open-source vulnerabilities, Qwiet preZero automatically searches for build manifests in the project path you provided when running sl analyze. Depending on your build system, you may need to generate a dependency file before running sl.

Currently, sl supports requirements.txt, poetry.lock, and uv.lock. Use the appropriate command for your package manager to generate the required file:

  • pip: Run pip freeze > requirements.txt from your activated virtual environment.
  • Poetry: Run poetry lock to generate a poetry.lock file.
  • uv: Run uv lock to generate a uv.lock file. If a lock file is not found, sl will attempt to parse the pyproject.toml (if it exists), but providing a uv.lock file is recommended.

If SBOM generation finds no components, sl analyze tries to create a temporary requirements-sl.txt so SCA can still enumerate dependencies. It first runs uv pip compile against pyproject.toml (installing uv if needed), then falls back to pip freeze in a virtual environment under the project directory. Pass --disable-python-lock-file-creation (or set SHIFTLEFT_DISABLE_PYTHON_LOCK_FILE_CREATION=true) to skip this generation.

Analyzing Jupyter notebooks​

To submit a Jupyter notebook for analysis with Qwiet AI by Harness, you must first convert all of your .ipynb files to .py files:

# convert the notebooks (*.ipynb) into Python files (*.py)
jupyter nbconvert --to python *.ipynb

# analyze the Python files with Qwiet AI by Harness
sl analyze --app ipynb-pythonsrc --pythonsrc .