https://github.com/evindunn/jinplate
A command line Jinja2 renderer
https://github.com/evindunn/jinplate
ansible cli devops jinja2 template tools
Last synced: about 2 months ago
JSON representation
A command line Jinja2 renderer
- Host: GitHub
- URL: https://github.com/evindunn/jinplate
- Owner: evindunn
- License: mit
- Created: 2024-07-04T03:49:24.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-19T15:15:52.000Z (over 1 year ago)
- Last Synced: 2025-10-25T19:31:13.899Z (6 months ago)
- Topics: ansible, cli, devops, jinja2, template, tools
- Language: Python
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# jinplate
[](https://github.com/psf/black)
[](https://github.com/pylint-dev/pylint)
A command line [Jinja2](https://github.com/pallets/jinja) renderer inspired
by [gomplate](https://github.com/hairyhenderson/gomplate)
jinplate can read from local and remote variable files in a number of formats and use them
to render a local Jinja2 template file.
jinplate uses URIs to identify how to fetch and parse Jinja2 variable files.
# Installation
```
pip install jinplate
```
To install with support for the tests and filters included with ansible, use
```
pip install jinplate[ansible]
```
# Usage
```
jinplate --help
Usage: jinplate [OPTIONS] TEMPLATE_FILE DATASOURCES...
A command line renderer for jinja2 templates. If ansible is available,
jinplate uses its template engine. If not, uses plain jinja2.
TEMPLATE_FILE is the path to a jinja template file to render
DATASOURCES is a list of URIs to data sources supported by jinplate which
contain the template variables
-e allows specifying individual vars in the format key=value. Example: -e
test1=1 -e test2=2
--jinja-ext allows specifying a comma-separated list of import paths
containing jinja extensions. Example: --jinja-ext jinja2.ext.i18n
Options:
--jinja-ext TEXT A comma-separated list of jinja extensions to load
-e TEXT Individual template vars in the format key=value
--help Show this message and exit.
```
# Local Vars Example
test.j2
```yaml
---
key: {{ test1.key }}
arr: {{ test2.arr }}
```
vars.json
```json
{
"test1": {
"key": "val"
},
"test2": {
"arr": [1, 2, 3]
}
}
```
```
jinplate test.j2 "file:///$(pwd)/vars.json"
---
key: val
arr: [1, 2, 3]
```
# Remote Vars example
```
python -m http.server
```
```
jinplate test.j2 "http://127.0.0.1:8000/vars.json"
---
key: val
arr: [1, 2, 3]
```
# Supported Vars File Schemes
| URI Scheme | Plugin | Example |
|------------|--------------------------------|-------------------------------------|
| file | `jinplate.plugins.scheme.file` | `file:////path/to/vars.yaml` |
| http | `jinplate.plugins.scheme.http` | `http://127.0.0.1:8000/vars` |
# Supported Vars File Types
File types are determined by extension, but can also be overridden by appending
`+` to the datasource URI scheme, as in `http+json://`
| File type | Matching extensions | Plugin | Example |
|-----------|---------------------|------------------------------------|------------------------------------------------------------------|
| json | `.json` | `jinplate.plugins.filetype.json` | `http+json://127.0.0.1:8000/vars` |
| yaml | `.yaml`, `.yml` | `jinplate.plugins.filetype.yaml` | `http://127.0.0.1:8000/vars.yml`
`file:////path/to/vars.yaml` |
| dotenv | `.env` | `jinplate.plugins.filetype.dotenv` | `file+env:////path/to/vars` |