A CLI tool for generating files from Jinja2 templates and environment variables.
Project description
A CLI tool for generating files from Jinja2 templates and environment variables.
Installation
pip install template[all]
This will install Template along with the dependencies for all of the filters available with it. However, you can use narrower specifiers if you want to avoid a specifc dependency (the filters listed below include the needed specifier). In previous versions of Template all of the dependencies were required, so to avoid breakage this behavior will be be kept. However, this will change in a later release so the keep the expected behavior please update your project’s dependencies.
Examples
$ template -h
usage: template [-h] [-o OUTPUT] [filename]
A CLI tool for generating files from Jinja2 templates and environment
variables.
positional arguments:
filename Input filename
optional arguments:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output to filename
$ export name='John'
$ echo 'Hello {{ name if name is defined else 'world' }}. | template
Hello John.
$ echo '{{ USER }}' > username.j2
$ template --output username.txt username.j2
$ cat username.txt
John
Jinja filters
The following Jinja filters were added:
to_yaml
: Convert to yaml (requires theyaml
package specifier).from_yaml
: Convert from yaml (requires theyaml
package specifier).to_json
: Convert to json.from_json
: Convert from json.to_toml
: Convert to toml (requires thetoml
package specifier).from_toml
: Convert from toml (requires thetoml
package specifier).jmespath
: Queries data using the JMESPath query language (requires thejmespath
package specifier).run
: Runs a command and returns the stdout, stderr and returncode using run.ipaddress
: Returns an IPAddress object from the netaddr library (requires thenetaddr
package specifier).ipnetwork
: Returns an IPNetwork object from the netaddr library (requires thenetaddr
package specifier).iprange
: Returns an IPRange object from the netaddr library. (requires thenetaddr
package specifier).ipglob
: Returns an IPGlob object from the netaddr library (requires thenetaddr
package specifier).
Example usage can be seen in tests
and for specific filters in the
docstrings in template/filters.py
.
Testing
Tests require Pipenv and Bats. Run the tests with the following commands:
pipenv run lint # Pre-commit hooks.
pipenv run doctest # Doc tests.
pipenv run bats # Bats tests.
pipenv run check # Twine check.
Also, GitLab CI is setup for this project so every push to this repository is checked with all Python 2.7, Python 3.6 and later and all supported versions of PyPy.
Release
Release requires Pipenv. To bump the version run
pipenv run bumpversion major|minor|patch
to update the version and git
commit and tag the changes, then run git push --follow-tags
to push the
git commit and tag. The GitLab CI will then build and upload a release to PyPI.
To manually upload to PyPI run pipenv run build
to build the Python
package and pipenv run upload -s dist/*
to upload a signed version.
License
This software is licensed under the AGPL 3+ license (see the LICENSE.txt
file).
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 Distributions
Built Distribution
Hashes for template-0.7.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfd45cb725f1af159b55920cd2567de4db67167ba86099ec0770a187460c7cfa |
|
MD5 | e96b1c2052d83b753a26619536adb726 |
|
BLAKE2b-256 | ee675dcb88a42684c426e3dc72e5597c9d8704ddb3a32596209af335e5219ad2 |