Metadata-Version: 2.0
Name: django-compiling-loader
Version: 0.0.1
Summary: A bytecode compiling template loader for Django
Home-page: https://github.com/mhallin/django-compiling-loader
Author: Magnus Hallin
Author-email: mhallin@gmail.com
License: BSD
Keywords: django performance template
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.7
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Topic :: Software Development :: Compilers
Provides-Extra: dist
Requires-Dist: twine; extra == 'dist'
Requires-Dist: wheel; extra == 'dist'
Provides-Extra: test
Requires-Dist: pytest (~=2.7.2); extra == 'test'
Requires-Dist: pytest-cov (~=1.8.1); extra == 'test'
Requires-Dist: pytest-django (~=2.8.0); extra == 'test'
Requires-Dist: Django (~=1.7.0); extra == 'test'

=========================
 Django-compiling-loader
=========================

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

.. image:: https://api.travis-ci.org/mhallin/django-compiling-loader.svg?branch=master
   :target: https://travis-ci.org/mhallin/django-compiling-loader

.. image:: https://coveralls.io/repos/mhallin/django-compiling-loader/badge.svg?branch=master&service=github
   :target: https://coveralls.io/github/mhallin/django-compiling-loader?branch=master

----

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.


Usage
=====

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

.. code-block:: python

   TEMPLATE_LOADERS = (
       ('django.template.loaders.cached.Loader', [
           ('compiling_loader.Loader', [
               'django.template.loaders.filesystem.Loader',
               'django.template.loaders.app_directories.Loader',
           ]),
       ]),
   )

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


Compatibility
=============

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.


Performace
==========

The ``test_proj/run_benchmarks.py`` 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:

=========  =======  ========  =======
Template   Default  Compiled  Speedup
=========  =======  ========  =======
Small      0.21 ms  0.10 ms   2,1x
Large      125 ms   42 ms     3,0x
=========  =======  ========  =======


