Safeguard
Supply Chain•

How do I generate an SBOM for npm, Python and Maven projects?

Generate an SBOM from your lockfile or build, not from memory. Here are the commands for npm, Python and Maven projects, and what to check in the output.

Safeguard Security Team
3 min read

Generate an SBOM from the resolved dependency data your build already has: the lockfile for npm, the environment or requirements for Python, and the Maven build for Java. Each ecosystem has a standard tool that writes CycloneDX or SPDX. Then check that versions and transitive dependencies are present.

Quick decision table

EcosystemToolReads fromFormats
npmBuilt in command, npm sbomDependency tree and lockfileCycloneDX or SPDX
PythonCycloneDX Python (cyclonedx-py)Environment, requirements, Poetry, PipenvCycloneDX
MavenCycloneDX Maven pluginThe build, all modulesCycloneDX, XML and JSON

npm

The npm CLI documents a command that generates an SBOM listing the dependencies of the current project, in SPDX or CycloneDX. If you limit it to the lockfile, it reads only the lock data, so fields from each dependency's own package.json, such as description or homepage, are missing.

npm sbom --sbom-format cyclonedx > sbom.cdx.json

Python

CycloneDX Python builds an SBOM from a virtual environment, from pip requirements, or from Poetry and Pipenv projects. Building from an environment captures what is actually installed, which is usually more complete than a loose requirements file.

Install the tool with pip, pipx, Poetry or uv as its documentation describes, then run it against the active environment.

cyclonedx-py environment > sbom.cdx.json

Maven

The CycloneDX Maven plugin's aggregate goal creates one BOM at the build root using dependencies from the whole multi-module build. By default it writes both XML and JSON into the target directory.

mvn org.cyclonedx:cyclonedx-maven-plugin:makeAggregateBom

Check the output

  1. Components have exact versions, not ranges.
  2. Transitive dependencies are listed, not just those in your manifest.
  3. Each component has an identifier a machine can match, such as a package URL.
  4. The SBOM describes the right product and build, and has a timestamp.
  5. It validates against the format's schema.

Regenerate on every build. An SBOM from last quarter describes last quarter's software.

Try it yourself

Open the demo and see how an inventory of direct and transitive dependencies is built from a manifest.

Click through it at your own pace, or open it full screen.

Where Safeguard fits

Safeguard's SBOM and dependency scanning generates and keeps SBOMs and checks them for known vulnerabilities. A free scan is a quick way to see the result for your own project.

Quick check

Which format should I choose?

Use whichever your customers or regulators ask for. Both CycloneDX and SPDX are widely supported, and most tools convert between them with some loss.

Do dev dependencies belong in the SBOM?

It depends on what you ship. Mark scope clearly so readers can tell runtime components from build tools.

Sources

  • npm Docs, npm sbom (formats and lockfile only behaviour).
  • CycloneDX Python repository on GitHub (inputs and commands).
  • CycloneDX Maven plugin repository on GitHub (makeAggregateBom goal, default outputs).

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.