Skip to main content

Pre-compile Jinja2 templates to Python byte code

Project description

Pre-compile Jinja2 templates to Python byte code.


Jinja2 pre-compiler comes with a utility script called jinja2precompiler. Please type jinja2precompiler --help at the shell prompt to know more about this tool.

Compiling the Jinja2 template

Then run jinja2precompiler command:

$ jinja2precompiler templates
Compiling into folder "templates"
Compiled "templates/template.html" as
Finished compiling templates

Will compiling to Python byte code with --pyc option:

$ jinja2precompiler --pyc templates
Compiling into folder "templates"
Compiled "templates/template.html" as tmpl_5f0fcb0ed56efa600c50d9f2870192327823c063.pyc
Finished compiling templates

Get the compiled module name

Will return a module file name with --modulename option:

$ jinja2precompiler --modulename templates/template.html

$ jinja2precompiler --modulename --pyc templates/template.html

And you can prepend directory path with --base option:

$ jinja2precompiler --modulename --base=templates templates/template.html

Will return module file names you specify the argument more than one:

$ jinja2precompiler --modulename a.html b.html c.html

With Make

An example Makefile file: $(wildcard templates/*.html)
      jinja2precompiler -c templates
      zip -FS -j templates/*.pyc

Will compiling only updated files and storing into the zip file.


Installing from PyPI using pip:

pip install jinja2precompiler

Installing from PyPI using easy_install:

easy_install jinja2precompiler

Installing from source:

python install


  1. Jinja2


0.2: supports walking symlink directories


Jinja2 pre-compiler is licensed under the terms of the BSD 3-Clause.

Copyright 2012 ENDOH takanao.

Project source code is available at Github. Please report bugs and file enhancement requests at the issue tracker.

Download files

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

Files for jinja2-precompiler, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size jinja2-precompiler-0.2.tar.gz (154.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page