Python Template Processor for Jinja templates
Project description
antp
Module & app for processing Jinja template files with json data and environment variables.
Installation
python3 -m pip install antp
Usage
python3 -m antp -t|--template <templatefile> [-o|--output <outputfile>] [-d|--data <json_datafile1,json_datafile2,...,json_datafileN>]
Templatefile is the jinja-template. Parameter can be omitted or parameter value set to dash to read template from stdin.
Outputfile is the filename where the output will be written. Parameter can be omitted or parameter value can be set to dash to write the output to stdout.
Json_datafile is the json-file with the data to be accessed in the templates. The data-parameter can have multiple datafiles, use comma to separate filenames.
Data from datafiles will be in the data variable. Variables from environment will be in the envvariable.
Examples
data1.json
{
"colors": {
"black": "#000000",
"white": "#FFFFFF",
"red": "#FF0000",
"green": "#00FF00",
"blue": "#0000FF"
},
"food": [
"vegetables",
"meat",
"fish"
]
}
data2.json
{
"capitals": {
"Finland": "Helsinki",
"Sweden": "Stockholm",
"Denmark": "Copenhagen"
}
}
template.jinja
The capital of Finland is {{ data["capitals"]["Finland"] }}.
Typical foods: {{ data["food"]|join(", ") }}.
Black is {{ data["colors"]["black"] }}.
Environment variable FOO is {{ env["FOO"] }}.
Run command:
FOO=bar python3 -m antp -t template.jinja -d data1.json,data2.json -o out.txt
out.txt
The capital of Finland is Helsinki.
Typical foods: vegetables, meat, fish.
Black is #000000.
Environment variable FOO is bar.
Docker container
Containerized version of antp is also available from anttin/antp.
Container usage
Sample template:
Our message to you is: {{ env["Message"] }}
Sample run:
docker run --rm -it -v /local/path/template:/antp/template -v /local/path/output_directory:/antp/output -e MESSAGE="Hello world" antp:latest
Sample output:
Our message to you is: Hello world
You can use ANTP_TEMPLATE, ANTP_OUTPUT and ANTP_DATA environment variables to override the default paths. Datafiles are not used by default, so this env variable is needed if you want to use data files.
Use cases
This container can be useful as a k8s init-container. Input files can be ConfigMaps. Values can be fed through ConfigMaps or env variables. Output can be set to an emptyDir volume that is shared between the containers.
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
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 antp-0.1.1.tar.gz.
File metadata
- Download URL: antp-0.1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
568bb2e4f18e079c34092ffcbacbac5dde81e8f911e7a319f1c9c9ab166d9e4e
|
|
| MD5 |
e0f8088fbe3554e8564be1dd17373cd0
|
|
| BLAKE2b-256 |
5d458761411f3c3f107938da24030268702f1fc47b77fac253de1c763ab63a22
|
File details
Details for the file antp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: antp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78775e2296c83abb2ba903915958cf845b60179422269a02b0d6b1047eca3c6b
|
|
| MD5 |
ad4e4682ebc355ca2931f9dc36f4913f
|
|
| BLAKE2b-256 |
6598a0cc109b58009457e3279d8baae60bb6297f216533092c61f92d69728df9
|