Skip to main content

Pre-compile Jinja2 templates to Python byte code.

Usage

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 tmpl_5f0fcb0ed56efa600c50d9f2870192327823c063.py
...
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
tmpl_41d3b4a4b71afe0c223778e57c23244caee1baec.py

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

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

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

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

$ jinja2precompiler --modulename a.html b.html c.html
tmpl_25e7e8960b03ecb19189f36b8ef611389397c95c.py tmpl_83d0d31e29a7746a19536d616218a384f62d4694.py tmpl_45ecd51cee2d33904a8cd1af7c441dd3fc320870.py

With Make

An example Makefile file:

templates_compiled.zip: $(wildcard templates/*.html)
      jinja2precompiler -c templates
      zip -FS -j templates_compiled.zip templates/*.pyc

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

Installation

Installing from PyPI using pip:

pip install jinja2precompiler

Installing from PyPI using easy_install:

easy_install jinja2precompiler

Installing from source:

python setup.py install

Dependencies

  1. Jinja2

Changes

0.2: supports walking symlink directories

Licensing

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.

Release files for jinja2-precompiler 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinja2-precompiler 0.2
File Size Uploaded
jinja2-precompiler-0.2.tar.gz 154.7 kB Details

Release files / jinja2-precompiler-0.2.tar.gz

Download URL jinja2-precompiler-0.2.tar.gz
Size 154.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e9ffe1b4414b4f86273f1f14da0d9a2155837044c434f7ca17642f7fd98da449
BLAKE2b-256 checksum
How to use checksums
2ef248b9ca6af2f95a9de60a2eae05abc2d93d66516627fce58ad529a031c9a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page