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
- A decided licence. If you have not chosen yet, choosealicense.com and the Open Source Initiative's list of approved licences are good starting points.
- The exact identifier from the SPDX License List, for example
MIT,Apache-2.0,BSD-3-Clause,MPL-2.0orGPL-3.0-or-later. Spelling and case matter. - The full licence text in a file at the repository root.
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
- Writing
"Apache 2"or"BSD", which are not valid identifiers. "BSD" alone is ambiguous between several distinct licences. - Using deprecated identifiers like
GPL-3.0instead of choosingGPL-3.0-onlyorGPL-3.0-or-later. - A manifest that says one licence while the
LICENSEfile contains another. - Forgetting that bundled third-party code keeps its own licence and may need its notice shipped too.
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.