SPDX Headers
spdx-headers is a command-line tool for auditing and maintaining SPDX license headers in Python projects. It can add, verify, and update SPDX headers, extract license texts, and integrates seamlessly with pre-commit.
Table of Contents
- Features
- Installation
- Quick Start
- Core Commands
- Using As a Pre-Commit Hook
- Documentation
- Contributing
- License
Features
- Automated SPDX management – add, change, remove, or verify headers across your Python sources.
- Auto-fix missing headers – infer the repository’s SPDX identifier and repair files automatically.
- SPDX license data updates – fetches the latest license list directly from SPDX.
- Pre-commit integration – ships with a hook that can block commits or auto-fix issues.
- License extraction – generate LICENSE files by SPDX identifier.
- Dry-run support – inspect changes before applying them.
- Typed codebase – includes
py.typedfor first-class type checking. - Flexible license viewing – preview SPDX license summaries and optionally keep the generated files for reference.
- Configurable exclusions – opt specific files out of header checks via a
.spdx-headers.inifile.
Recent Enhancements
- Individual file targeting – Use
--fileto target specific files instead of entire directories - Enhanced directory targeting – Improved
--pathoption with better path resolution - Better copyright detection – Automatically detects copyright information from repository root
- Template-ready version script – The
bump_version.pyscript now works across different projects with dynamic license detection
Installation
pip install spdx-headers
Working from Source (with uv)
The development workflow relies on uv for dependency management. Install it first:
curl -LsSf https://astral.sh/uv/install.sh | sh
# or: pipx install uv
Then clone the repository and install dependencies:
git clone https://github.com/uglyegg/spdx-tools.git
cd spdx-tools
uv sync --dev
uv run pre-commit install
Quick Start
# Add AGPL-3.0-or-later headers to all Python files
spdx-headers --add AGPL-3.0-or-later
# Verify all files have valid SPDX headers
spdx-headers --verify
# Check (CI friendly) and auto-fix missing headers when possible
spdx-headers --check --fix
# List SPDX identifiers containing “Apache”
spdx-headers --list Apache
# Extract the MIT license into LICENSE-MIT
spdx-headers --extract --add MIT --dry-run
# Target a specific file
spdx-headers --file src/my_module.py --add MIT
# Target a specific directory
spdx-headers --path src/utils --add Apache-2.0
Core Commands
| Command | Description |
|---|---|
spdx-headers --add LICENSE |
Add the specified SPDX header to all Python files. |
spdx-headers --change LICENSE |
Replace existing headers with the specified SPDX identifier. |
spdx-headers --remove |
Remove SPDX headers from all Python files. |
spdx-headers --verify |
Print a report of files missing headers (no exit code). |
spdx-headers --check [--fix] |
Return exit code 0/1 depending on compliance; --fix attempts auto-repair and the command reports detected SPDX identifiers (listing files if multiple licenses are found). |
spdx-headers --list [KEYWORD] |
List available SPDX identifiers, optionally filtering by keyword. |
spdx-headers --show LICENSE [--keep-temp] |
Display a license summary using the system’s default viewer (optionally keep the temp file). |
spdx-headers --extract [KEYWORD] [--add LICENSE] |
Extract license text for identifiers matching KEYWORD; combine with --add/--change to write headers and license text together. |
spdx-headers --update |
Download the latest SPDX license data. |
spdx-headers --file FILENAME |
Target an individual Python file instead of a directory. Overrides --path. |
spdx-headers --path DIRECTORY |
Specify the directory path to operate on. Defaults to auto-detected source directory. |
.spdx-headers.ini |
Optional configuration file used to exclude generated/vendor files from checks. |
See docs/usage.md for a comprehensive walkthrough.
Using As a Pre-Commit Hook
spdx-headers ships with a pre-commit hook that checks for (and can auto-fix) missing headers. Add the following to your .pre-commit-config.yaml:
- repo: https://github.com/uglyegg/spdx-tools
rev: v1.0.0
hooks:
- id: spdx-header-check
The bundled configuration automatically runs spdx-headers --check --fix, so files missing a header are rewritten when the repository has a consistent SPDX identifier. See docs/pre-commit.md for advanced configuration.
Documentation
docs/usage.md– extended CLI usage guide, tips, and examples.docs/pre-commit.md– integrating the tool withpre-commit.docs/configuration.md– managing.spdx-headers.iniexclusions.docs/github-actions.md– integrating the tool with GitHub Workflows.docs/dev-workflow– workflow when working on development for this application.
Contributing
Contributions are welcome! Please open an issue or pull request. When submitting changes:
- Run
make checkto execute formatting, lint, mypy, and test suites. - Update or add documentation in
docs/if behaviour changes. - Add tests covering new functionality.
License
This project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later). See the LICENSE file for details. Additional license texts can be generated via spdx-headers --extract.
Metadata
Release files for spdx-headers 1.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spdx_headers-1.5.1.tar.gz | 94.9 kB | Without provenance | Details for spdx_headers-1.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spdx_headers-1.5.1-py3-none-any.whl | Python 3 | none | any | Details for spdx_headers-1.5.1-py3-none-any.whl |
Total release size: 157.0 kB
Release files / spdx_headers-1.5.1.tar.gz
| Download URL | spdx_headers-1.5.1.tar.gz |
|---|---|
| Size | 94.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
245031be1236ad0848bcb7d21c2874ff756c0b005375a13ece273e5f5af0fbd3
|
|
BLAKE2b-256 checksum How to use checksums |
b3a79676c9692c963b1afd4801fe4f228876553450a9a74913e33ef74d79cc9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / spdx_headers-1.5.1-py3-none-any.whl
| Download URL | spdx_headers-1.5.1-py3-none-any.whl |
|---|---|
| Size | 62.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73bcb1ed087824b55ccaa497d03d8f0f0b0eaf30e5f0f7d5bbd29d2c4fe78fcf
|
|
BLAKE2b-256 checksum How to use checksums |
3e171f31d8562e6f970d64911f1abc330d233bc0c0601411cf7e19c1292be6da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for spdx-headers 1.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.