Skip to main content

A bytecode compiling template loader for Django

Project description

A template loader that compiles Django templates into Python bytecode for improved performance.

This package exposes the compiling_loader.Loader template loader. This loader will compile the template syntax tree generated by Django into Python bytecode. If a tag can’t be generated, a fallback will be compiled, which just evaluates the template nodes. The fallback method means that this loader is compatible with the existing loaders, even if you have a lot of custom tags.

The compiler is modular and built around Python 3.4’s singledispatch function, meaning that it can easily be extended to support your own tags if you have expensive custom tags that would benefit from compilation.

The loader itself does not do any caching; it works together with Django’s built-in cached loader to avoid recompilation.


Install the django-compiling-loader Python package and set the TEMPLATE_LOADERS settings to the following value:

    ('django.template.loaders.cached.Loader', [
        ('compiling_loader.Loader', [

If you have other loaders, put them inside the compiling_loader.Loader list to ensure that the generated templates get compiled.


The loader has been tested with Django 1.7, and requires Python 3.4. When it comes to rendering compatibility, this project contains a fair number of test cases that compare the render output from the standard Django template evaluation and this compiler. So far, no incompatibilities have been found.


The test_proj/ script renders a small inheritance based template a large number of times, as well as a large both inheritance and include based template a few times. Below are some comparisons:






0.21 ms

0.10 ms



125 ms

42 ms


Project details

Download files

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

Source Distribution

django-compiling-loader-0.0.1.tar.gz (10.8 kB view hashes)

Uploaded Source

Built Distribution

django_compiling_loader-0.0.1-py3-none-any.whl (16.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page