Guides · 05

SPDX Identifiers and File Headers

How to write SPDX-License-Identifier and SPDX-FileCopyrightText headers, deprecated identifiers (GPL-2.0 → GPL-2.0-only), the license field in package metadata, and the REUSE specification.

Last checked: 2026-09-23

What is SPDX?

SPDX (Software Package Data Exchange) is a Linux Foundation project and a standard for expressing software components and license information in a machine-readable way. In 2021 it became the international standard ISO/IEC 5962:2021. Its most widely used part is the short identifiers of the SPDX License List: an agreement to write just MIT instead of assorted names like "MIT License", "The MIT license" or "MIT licence".

Two header lines

Put the following two lines as comments at the top of a source file, and both people and tools can immediately see the file's copyright holder and license.

// SPDX-FileCopyrightText: 2026 Jane Doe <jane@example.com>
// SPDX-License-Identifier: MIT

The generator's File header tab creates these two lines in seven comment styles.

Watch out for deprecated identifiers

Since SPDX License List 3.0 (December 2017), identifiers for GNU licenses must reveal the version clause.

Deprecated identifierCurrent identifier
GPL-2.0GPL-2.0-only
GPL-2.0+GPL-2.0-or-later
GPL-3.0GPL-3.0-only
LGPL-2.1LGPL-2.1-only
AGPL-3.0AGPL-3.0-only

Writing just GPL-3.0 does not tell you whether it is "only" or "or later". The difference between the two is explained in only vs or-later.

Package metadata

Most package managers accept SPDX identifiers or expressions.

EcosystemFileExample
npmpackage.json"license": "MIT" · "UNLICENSED" for private
RustCargo.tomllicense = "MIT OR Apache-2.0"
Pythonpyproject.tomllicense = "Apache-2.0" (PEP 639)
Mavenpom.xmlName and URL inside <licenses>

npm's UNLICENSED means something completely different from "Unlicense": it marks a private package whose use is not permitted. The spellings are similar, so mistakes are common.

REUSE: making the whole repository machine-readable

The REUSE specification from the Free Software Foundation Europe (FSFE) defines how to apply SPDX headers consistently across a repository.

  1. Put every license text in a LICENSES/ folder named SPDX-identifier.txt (e.g. LICENSES/MIT.txt).
  2. Add SPDX-FileCopyrightText and SPDX-License-Identifier to each file.
  3. For files that cannot contain comments (images, JSON, etc.), provide the information in a filename.license sidecar file or in a REUSE.toml at the repository root.
  4. Use the reuse lint tool to check that no files are missing.

Practical tips

This article is general information, not legal advice. Consult a professional for important decisions.

Sources