Licenseheaders

0.8.8 · active · verified Thu Apr 16

licenseheaders is a Python 3 command-line tool designed to add or change license headers for all files of supported types in a given directory tree. It supports various predefined templates and allows for custom templates and variable substitutions. The current version is 0.8.8, and it appears to be actively maintained, with the last PyPI update on April 8, 2021, and GitHub issues still being addressed.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `licenseheaders` via its command-line interface to add a predefined license template (LGPLv3) to a specific Python file, including a custom copyright owner.

import os

# Ensure licenseheaders is installed: pip install licenseheaders

# Create a dummy file for demonstration
with open("example.py", "w") as f:
    f.write("def my_func():\n    pass\n")

# Run licenseheaders from the command line to add an LGPLv3 license
# to a dummy Python file in the current directory, with a specific owner.
# This simulates running `licenseheaders -t lgpl3 -o "Your Name" -f example.py`
print("Adding LGPLv3 license to example.py...")
os.system('python -m licenseheaders -t lgpl3 -o "Your Name" -f example.py')

print("\nContent of example.py after adding license:")
with open("example.py", "r") as f:
    print(f.read())

# Clean up
os.remove("example.py")

view raw JSON →