Simple python script to add/replace license headers in a directory tree of source files
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
templates First scaffold of what we want. Sep 28, 2016
.gitignore WIP Sep 29, 2016 Create Apr 5, 2018
LICENSE.txt First scaffold of what we want. Sep 28, 2016
README.rst Update README.rst May 15, 2018
setup.cfg First scaffold of what we want. Sep 28, 2016


PyPi version Python compatibility Build Status PyPi Coverage Codacy


A tool to update, change or add license headers to all files of any of the supported types in or below some directory.

Currently, the following file types are supported: Java/Scala/Groovy, bash/sh/csh, ...


usage: [-h] [-v] [-V] [-d directory] [-t template] [-y years] [-b] [-a]
                          [-c copyrightOwner]

License Header Updater

positional arguments: none

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -v, --verbose         increases log verbosity (can be specified multiple times)
  -d, --dir             directory to process, all subdirectories will be included
  -t, --tmpl            template name or file to use (if not specified, -y must be specified)
  -y, --years           if template is specified, the year to substitute, otherwise this year
                        or year range will replace any existing year in existing headers.
                        Replaces variable ${years} in a template
  -b, --backup          for each file that gets changed, create a backup of the original with
                        the additional filename extension .bak
  -c, --cr              copyright owner, replaces variable ${owner} in a template
  -a, --addonly         add a header to all supported file types, ignore any existing headers.

# Add a new license header or replace any existing one based on the lgpl3 template.
# Process all files of supported type in or below the current directory.
# Use "Eager Hacker" as the copyright owner. -t lgpl3 -c "Eager Hacker"

If licenseheaders is installed as a package (from pypi for instance), one can interact with it as a command line tool:

python -m licenseheaders -t lgpl3 -c "Eager Hacker"

or directly:

licenseheaders -t lgpl3 -c "Eager Hacker"


Download from or :

pip install licenseheaders

Template names and files

This library comes with a number of predefined templates. If a template name is specified which when matched against all predefined template names matches exactly one as a substring, then that template is used. Otherwise the name is expected to be the path of file.

If a template does not contain any variables of the form ${varname} it is used as is. Otherwise the program will try to replace the variable from one of the following sources:

  • an environment variable with the same name but the prefix LICENSE_HEADERS_ added
  • the command line option that can be used to set the variable (see usage)

Supported file types and how they are processed

Java: - assumed for all files with the extensions: .java, .scala, .groovy - only headers that use Java block comments are recognised as existing headers - the template text will be wrapped in block comments


Licensed under the term of MIT License. See attached file LICENSE.txt.