Skip to main content

A command-line tool for managing SPDX headers in Python source files

Project description

SPDX Headers

PyPI version License: AGPL v3 License ComplianceDownloads

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

  1. Features
  2. Installation
  3. Quick Start
  4. Core Commands
  5. Using As a Pre-Commit Hook
  6. Documentation
  7. Contributing
  8. 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.typed for 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.ini file.

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

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.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

Contributing

Contributions are welcome! Please open an issue or pull request. When submitting changes:

  1. Run make check to execute formatting, lint, mypy, and test suites.
  2. Update or add documentation in docs/ if behaviour changes.
  3. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spdx_headers-1.0.2.tar.gz (88.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spdx_headers-1.0.2-py3-none-any.whl (59.7 kB view details)

Uploaded Python 3

File details

Details for the file spdx_headers-1.0.2.tar.gz.

File metadata

  • Download URL: spdx_headers-1.0.2.tar.gz
  • Upload date:
  • Size: 88.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for spdx_headers-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1dedd164e2ba152c93fd0f920ede627d17f0d4ed6d4d6058934fa907f5df410a
MD5 5cd79fed50ec39db8aacf6a9877c6908
BLAKE2b-256 0361fcfef6e34dadb8bd8255e337f2dad14d4771649124bd32b2c813070a3b84

See more details on using hashes here.

File details

Details for the file spdx_headers-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: spdx_headers-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 59.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for spdx_headers-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3b3b68c01d18ac67e3d8d4097d57e71defecb53de36684a3fcabb1af306cbea5
MD5 c280d841931ec2884a944227ff65af45
BLAKE2b-256 76a2fe7ba232a61ace86d605af3c44e6aee33763d8d4bb02ac97ececafd80dda

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page