A lightweight tool and CLI for rendering Jinja2 templates with JSON or Python data, ideal for scripting and automation workflows.
Project description
Escapist: Simplify Jinja2 Template Rendering
Escapist is a lightweight Python tool designed to render Jinja2 templates using JSON or dict data and flexible environment settings. It can be used both as a CLI for quick template rendering tasks and as a Python library for programmatic integration.
For detailed usage and documentation, visit: Escapist Documentation
Features
- Customizable Jinja2 environment: Configure block delimiters, autoescaping, whitespace trimming, and more through JSON or dict settings.
- Supports JSON data: Provide template data via JSON files or Python dictionaries.
- CLI & API: Use via command line or import as a Python library.
- Batch rendering: Render multiple templates in one command.
- Cross-platform: Works on Windows, macOS, and Linux.
Installation
To install Escapist, run:
pipx install escapist
Usage
Command-Line Interface (CLI)
Escapist provides simple commands to render Jinja2 templates with JSON data and custom settings.
Render a Single Template
escapist render TEMPLATE_PATH \
--data DATA_JSON_FILE \
--settings SETTINGS_JSON_FILE \
--output OUTPUT_FILE_PATH
TEMPLATE_PATH: Path to your Jinja2 template file.--data: (Optional) Path to a JSON file containing data for rendering.--settings: (Optional) Path to a JSON file with Jinja environment settings.--output: (Optional) Path to save the rendered output. If omitted, output is printed to stdout.
Render Multiple Templates in Batch
escapist batch TEMPLATE_DIR \
--pattern '*.html' \
--data DATA_JSON_FILE \
--settings SETTINGS_JSON_FILE \
--output-dir OUTPUT_DIRECTORY \
--force
TEMPLATE_DIR: Directory containing your templates.--pattern: (Optional) File pattern to match templates, e.g.,*.html.--data: (Optional) JSON data file for all templates.--settings: (Optional) Jinja environment settings file.--output-dir: Directory to save rendered templates.--force: (Optional) Overwrite existing output files.
Python Library Usage
You can also use Escapist as a Python library for programmatic rendering.
from escapist import Escapist
# Initialize renderer with optional settings
renderer = Escapist(settings="path/to/settings.json")
# Load template (file path or template string)
renderer.load_template("path/to/template.jinja")
# Render with data (dict or path to JSON file)
output = renderer.render(data={"name": "Alice", "version": "1.0.0"})
print(output)
Settings Format
Escapist supports flexible Jinja2 environment configuration via JSON settings files. Below is an example structure of a settings JSON file you can use to customize the rendering environment:
{% raw %}
{
"environment": {
"block_start_string": "{%",
"block_end_string": "%}",
"variable_start_string": "{{",
"variable_end_string": "}}",
"comment_start_string": "{#",
"comment_end_string": "#}",
"line_statement_prefix": null,
"line_comment_prefix": null,
"trim_blocks": false,
"lstrip_blocks": false,
"newline_sequence": "\n",
"keep_trailing_newline": false
},
"globals": {
"app_name": "Escapist",
"version": "0.0.1"
},
"autoescape": {
"enabled_extensions": ["html", "htm", "xml"],
"disabled_extensions": [],
"default_for_string": true,
"default": false
},
"escape_sequences": {
">": ">",
"<": "<",
"&": "&",
"\"": """,
"'": "'"
},
"treat_missing_variable_as_missing": true
}
{% endraw %}
- environment: Configures Jinja2 delimiters, whitespace trimming, newline behavior, and other environment options.
- globals: Defines default variables accessible in templates; if a variable is missing from provided data, the value here is used.
- autoescape: Controls autoescaping of output based on file extensions. Can also be a boolean (
trueorfalse). Default isfalse. Enable to prevent HTML/XSS injection. - escape_sequences: Maps characters to their escaped representations (e.g., replacing
>with>). - treat_missing_variable_as_missing: Determines how missing variables in the template data are handled (e.g., treat as missing instead of erroring).
License
escapist is distributed under the terms of the MIT license.
Contact
Created by Jitesh Sahani (JD) Email: jitesh.sahani@outlook.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file escapist-1.0.2.tar.gz.
File metadata
- Download URL: escapist-1.0.2.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e12403fee152ff250a2333acdab38af736ac30815e924083c213185fb6c4b484
|
|
| MD5 |
816b37272cc281d118a428c723bf8ebd
|
|
| BLAKE2b-256 |
9363f87f73f2a1f6795facade159fa07903d3ffdcd9cf5e159c3005539084d0a
|
File details
Details for the file escapist-1.0.2-py3-none-any.whl.
File metadata
- Download URL: escapist-1.0.2-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7af689ec860173b2959ac71f5c52dccd9126b889b1f626a29dc64f0f787c703b
|
|
| MD5 |
95611780b49118f3a511a0be2011ea50
|
|
| BLAKE2b-256 |
241fee3f074ef692c73a2f15af4cd3cfbb40429078c48719372d674861e907ba
|