How to Declare Your Licence With an SPDX Identifier

A LICENSE file tells humans what the terms are. An SPDX identifier tells machines. Dependency scanners, registry pages and corporate approval tools all read the short identifier rather than parsing legal text, so getting it right means your package is classified correctly without anyone filing a ticket about it.

What you need

Step 1: put the identifier in the manifest

Each ecosystem has a field for it. Use the identifier or a valid SPDX expression, not a free-text description.

# package.json
"license": "MIT"

# Cargo.toml
[package]
license = "MIT OR Apache-2.0"

# pyproject.toml (newer metadata, see PEP 639)
[project]
license = "Apache-2.0"
license-files = ["LICENSE"]

For Python, check that your build backend supports the SPDX-expression form of license before switching to it; older backends expect a table or rely on trove classifiers instead. Go modules have no manifest field, so for Go the licence file in the module root is what tooling inspects.

Step 2: use expressions for more than one licence

SPDX expressions combine identifiers with AND, OR and WITH. MIT OR Apache-2.0 means the user may choose either. Apache-2.0 AND MIT means both apply, typically because different files carry different terms. GPL-2.0-or-later WITH Classpath-exception-2.0 attaches a listed exception. Pick the operator that matches reality; scanners take it literally.

Step 3: optionally tag source files

A one-line header at the top of each source file makes the licence travel with the code when files are copied out of the repository:

// SPDX-License-Identifier: MIT

This is especially worth doing in libraries that people vendor, and in repositories that mix licences.

Common mistakes

How to check it worked

After publishing, or in a dry run, look at how the registry displays your licence; npm and crates.io show it on the package page. Run any licence scanner your organisation uses against a project that installs your package and confirm it reports the identifier you intended. Finally, compare the manifest, the file headers and the LICENSE text side by side. All three should tell the same story. This page is general information about metadata, not legal advice; for questions about obligations, consult the licence text itself or a qualified lawyer.

Related pages