Quick question for anyone who has had to hand over an SBOM for a Python service (customer questionnaire, security review, or just your own "what is actually running in prod?").
There are two places you can build it from, and they don't always agree:
- What you declared: requirements.txt, a lock file, pyproject.toml.
- What is actually installed in the environment that runs the code: the venv or the container image.
The second one picks up things the first can miss: transitive dependencies you never pinned, a package someone pip installed by hand to debug something, or a version that drifted because a pin was looser than you thought.
Disclosure: I built a small tool for the second approach, so I'm biased. It's a single stdlib Python file that reads the installed packages with importlib.metadata and writes CycloneDX 1.5 JSON with Package URLs, fully offline (no PyPI calls). Writing it surfaced a few details I didn't expect:
- Name normalization matters. Package URLs expect the normalized PyPI name, so
Ruamel.Yamlhas to becomeruamel-yaml. If two tools normalize differently, diffing their SBOMs gets noisy fast. - License data is only as good as the package metadata. It can come from
License-Expression, the free-textLicensefield, or a classifier, and some packages fill in none of them. - The same name can show up twice in one environment (duplicate distributions), so you have to decide how to report it.
- An inventory is not a vulnerability scan. The SBOM tells you what's there; matching it against CVEs is a separate step on top.
So I'm curious how others handle it:
- Do you generate the SBOM from the lock file, from the built image, or both?
- If you scan the image, do you run something like Syft/Trivy in CI, or generate it inside the running environment?
- Has anyone actually been asked for an SBOM by a customer, and in which format: CycloneDX or SPDX?
- How do you deal with missing or messy license fields?
Would love to hear what your pipeline looks like, especially for small teams that don't have a dedicated security person.