Skip to main content

Convenience wrapper around Jinja for scripts

Project description

j2scr: Avoid Jinja2 boilerplate for small scripts

This is a very simple package that wraps Jinja2. The purpose is to avoid boilerplate for micro-scripts that use jinja. This is achieved by setting a default jinja environment, and a loader searching relatively (unless an absolute path is given), and providing utility functions render, render_to_file, and set_options.

Use as such:

from j2scr import render, render_to_file, set_options

# You can render into a variable
string_with_content = render("../my_template.txt.j2", var=2, var2='Michael')
# Or into a file
render_to_file("../my_template.txt.j2", "my_content.txt" var=2, var2='Michael')

# You can change the loader/environment parameters (do it before rendering, of course):
set_options(encoding="latin-1", trim_blocks=True)
# Alternatively the environment and loaders are available as attributes.

If for some reason you want the minimalism of j2scr but without the global settings (eg. for a class), you can use the j2scr.J2Scr class which works the same way but has it's own env and loader.

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

j2scr-1.0.1.tar.gz (2.6 kB view hashes)

Uploaded Source

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