A simple Python templating tool

The other day I wrote a very simple Python utility, that some might find useful (the code is on GitHub). It’s a command line program called, which allows you to create new files or directories from templates. So, for instance, I often have common boilerplate code when writing a Python script, similar to this:

#!/usr/bin/env python


Author: Gertjan van den Burg
License: GPL v3

def main():

if __name__ == '__main__':

Now, I store this in the template directory (by default this is ~/.newpy_templates) as the file Then, if I run on the command line without any arguments, I get:

Usage: ./ target [output_name]
Available targets:
Name          File / Dir
----          ----------
python  ->

It’s then easy to create a file from a template, simply by running:

$ python

will generate a file named with the contents of the file in the template directory. Personally, I use this not only for python files, but also for LaTeX document templates and Beamer slides. The latter two examples are actually directories, which also supports.

Finally, I have the following alias in my ~/.bashrc file:

alias new='/path/to/'

which makes even easier and more intuitive to use:

$ new python

You can find on GitHub.