Automatically generate files based on Jinja templates. Use it to easily generate complex Home Assistant dashboards!
Project description
Docs | Example | Templating
makejinja is a CLI tool and Python library to automatically generate files from templates.
makejinja
makejinja can be used to automatically generate files from Jinja templates. This allows you to load variables from external files or create repeating patterns via loops. It is conceptually similar to gomplate, but is built on Python and Jinja instead of Go. A use case for this tool is generating config files for Home Assistant: Using the same language that the built-in templates use, you can greatly simplify your configuration. An example for Home Assistant can be found in the tests directory.
Features
- Recursively convert nested directories containing template files. One can even specify a pattern to specify relevant files in a folder.
- Load data files containing variables to use in your Jinja templates from YAML, TOML, and Python files.
- Use custom functions in your Jinja templates by loading custom filters and/or globals.
- Easily load bundled as well as custom Jinja extensions.
- Tailor the whitespace behavior to your needs.
- Use custom delimiters for Jinja blocks/comments/variables.
- Modify all init options for the Jinja environment.
- Write custom Python loaders that implement a subset of our fully typed abstract loader class
Installation
The tool is written in Python and can be installed via pip, nix, and docker. It can be used as a CLI tool or as a Python library. Please refer to the installation instructions for details.
PIP
makejinja is available via pip
and can be installed via
pip install makejinja
Beware that depending on other packages installed on your system via pip, there may be incompatibilities.
Thus, we advise leveraging pipx
instead:
pipx install makejinja
You can then directly invoke the app as follows:
makejinja --input ./data/input --output ./data/output
Nix
If you use the nix
package manager, you can add this repository as an input to your flake and use makejinja.packages.${system}.default
.
You can also run it directly
nix run github:mirkolenz/makejinja -- --input ./data/input --output ./data/output
Docker
We automatically publish an image at ghcr.io/mirkolenz/makejinja
.
To use it, mount a folder to the container and pass the options as the command.
docker run --rm -v $(pwd)/data:/data ghcr.io/mirkolenz/makejinja:latest --input /data/input --output /data/output
Usage in Terminal / Command Line
In its default configuration, makejinja searches the input folder recursively for files ending in .jinja
.
It then renders these files and writes them to the output folder, preserving the directory structure.
Our documentation contains a detailed description of all options and can also be accessed via makejinja --help
.
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
Hashes for makejinja-2.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f88769fa18f6f955808732d6e38597e1c5741c52b65151a40a9879bd387f756 |
|
MD5 | 2cb892bf7220da6519da05d735dc7c3a |
|
BLAKE2b-256 | bd107aaf0fd7b6849666850923541f28ca24cad2a410b0fa474f86e73de43d16 |