Skip to main content

Jinja2 based template module.

Project description


License Build Status

haip.template is Jinja2 based async template rendering module.


  • minimalistic: a single exported async function "render"
  • autoreturn-type: the return data type is derived from the file suffix

Getting Started


pip install haip.template

or from source:

git clone


async def render(template_filename, *, template_dir=None, **args)

The template-file is defined by config.template_dir/template_dir/template_filename. **args are used to fillin the placeholders in the template_file and the suffix of the template_file determines the return type. E.g. "template_name.json" will return a json structure (dict). render will propagate exceptions as they are raised by the underlaying modules.

Suffix handling is as follows:

  • .json : json struct (dict)
  • .sql : string (but **args values will be escaped)
  • .* : string


config (using haip.config)

template-dir: /path-to-template-dir/


Hello my name is {{ firstname }} {{ lastname }}!

python implementation

import haip.config as config
import haip.template as template

document = await template.render('mytemplate.jinja2', firstname='Reinhard', lastname='Hainz')

If mytemplate.jinja is in a subdirectory of the template-dir (e.g. /path-to-template-dir/mysubdir/):

document = await template.render('mytemplate.jinja2', template_dir='mysubdir', firstname='Reinhard', lastname='Hainz')

You can also use absolute paths in the template_dir argument of the render function.

Running the tests

Tests are written using pytest and located in the "tests" directory.

pytest tests


Feel free to use and enhance this project. Pull requests are welcome.


  • Reinhard Hainz - Initial work - haipdev


This project is licensed under the MIT License - see the LICENSE file for details


Project details

Download files

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

Files for haip-template, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size haip_template-0.1.3-py3-none-any.whl (4.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size haip-template-0.1.3.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page