Render Jinja2 templates on the command line using a YAML, JSON or HCL file as input for the render context.
j2y
is installed using pip
:
$ pip install j2y
Note
The name of this Python package is j2y
, but it will be renamed to
j2-cli
with the next major release.
Alternatively you can install directly from Github master branch:
$ pip install git+https://github.com/chaudum/j2y.git@master
By default, the j2cli
command takes a YAML file as input:
$ j2cli template.j2 < values.yaml
Alternatively you can use JSON or HCL as input format:
$ j2cli template.j2 -f json < values.json $ j2cli template.j2 -f hcl < values.hcl
It's also possible to provide multiple input files:
$ j2cli template.j2 --context v1.yaml --context v2.yaml
Run j2cli -h
to see all available options.
Additionally to the variables provided by the input file, j2cli
also
provides built-in default variables. These variables are:
meta.date: | Type: Value: Current UTC datetime object |
---|---|
meta.platform: | Type: Value: Output of |
env: | Type: Value: All environment variables (output of |
Create a virtualenv and install the package as develop egg:
$ python -m venv env $ source env/bin/activate (env) $ pip install -e .
At the moment there are very simple test cases only. Test are written as Python doctests and run using pytest:
(env) $ pip install -e ".[test]" (env) $ pytest
Pytest additionally runs the black linter and mypy static type checker.
The tests located in the docs/
folder can also be built into HTML using
Sphinx:
(env) $ sphinx-build -E -W docs/ _build/