CycloneDX Software Bill of Materials (SBOM) generator for Python projects and environments
cyclonedx-bom is a Python library and command-line tool for generating CycloneDX Software Bill of Materials (SBOM) for Python projects and environments. It supports various formats and schema versions of the CycloneDX specification. The current version is 7.3.0, and it maintains an active release cadence with frequent updates, with the latest release on March 30, 2026.
Warnings
- breaking In v7.0.0, the handling of PEP 639 (improving license clarity) was finalized and is now always enabled. Consequently, the `--PEP-639` CLI switch was removed.
- breaking In v7.0.0, deprecated CLI switches `--schema-version` and `--outfile` were removed.
- gotcha The `cyclonedx-bom` package is primarily a command-line interface (CLI) tool. Its internal Python API is not stable and explicitly not intended for public programmatic SBOM generation. For programmatic library-level interaction (e.g., creating data models, validation), you should use the `cyclonedx-python-lib` package instead.
- gotcha Direct support for Conda as a package manager input (`--conda` or `--conda-json` CLI flags) was removed in versions prior to v4.
- gotcha As of v7.3.0, the new `-S` flag allows skipping `*.pth` file evaluation during environment analysis. While useful in some contexts, be aware that this may lead to incomplete component detection in your SBOM.
- gotcha This library requires Python versions 3.9 or newer, but is not compatible with Python 4.x.
Install
-
pip install cyclonedx-bom
Quickstart
import subprocess
import json
import os
# Generate an SBOM for the current Python environment in JSON format
# and print it to stdout. In a real scenario, you'd typically direct to a file.
try:
# Using `-o -` directs output to stdout
result = subprocess.run(
['cyclonedx-py', 'environment', '--output-format', 'JSON', '-o', '-'],
capture_output=True,
text=True,
check=True
)
sbom_data = json.loads(result.stdout)
print("Successfully generated CycloneDX SBOM (first 200 chars):")
print(json.dumps(sbom_data, indent=2)[:200] + "...")
except subprocess.CalledProcessError as e:
print(f"Error generating SBOM: {e}")
print(f"Stdout: {e.stdout}")
print(f"Stderr: {e.stderr}")
except json.JSONDecodeError:
print("Failed to decode JSON from SBOM output.")
print(f"Raw output: {result.stdout}")