Package: template
A CLI tool for generating files fromJinja2templates and environment variables.Installationpipinstalltemplate[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 specific dependency (the filters listed below include the needed specifier).
In previous releases of Template all of the dependencies were required. To not
break existing templates, for the foreseeable future those dependencies will
remain a requirement and new dependencies for specific filters will be optional.
This will change in the 0.9 release where all filter specific dependencies will
be optional. Please update your project before that happens.Examples$template-husage:template[-h][-oOUTPUT][filename]ACLItoolforgeneratingfilesfromJinja2templatesandenvironmentvariables.positionalarguments:filenameInputfilenameoptionalarguments:-h,--helpshowthishelpmessageandexit-oOUTPUT,--outputOUTPUTOutputtofilename$exportname='John'$echo'Hello {{ name if name is defined else 'world' }}. | template
Hello John.
$ echo '{{USER}}'>username.j2$template--outputusername.txtusername.j2$catusername.txtJohnJinja filtersThe following Jinja filters were added:combine: Merges 2 dictionaries with the 2nd overriding the 1st.
Returns the result.to_yaml: Convert to yaml (requires theyamlpackage
specifier).from_yaml: Convert from yaml (requires theyamlpackage
specifier).to_json: Convert to json.from_json: Convert from json.to_toml: Convert to toml (requires thetomlpackage
specifier).from_toml: Convert from toml (requires thetomlpackage
specifier).jmespath: Queries data using theJMESPathquery language (requires thejmespathpackage specifier).run: Runs a command and returns the stdout, stderr and returncode
usingrun. This filter is replaced with therunfunction and will
be removed in the 0.10 release.ipaddress: Returns an IPAddress object from thenetaddrlibrary
(requires thenetaddrpackage specifier).ipnetwork: Returns an IPNetwork object from thenetaddrlibrary
(requires thenetaddrpackage specifier).iprange: Returns an IPRange object from thenetaddrlibrary.
(requires thenetaddrpackage specifier).ipglob: Returns an IPGlob object from thenetaddrlibrary (requires
thenetaddrpackage specifier).ipset: Returns an IPSet object from thenetaddrlibrary (requires
thenetaddrpackage specifier).Example usage can be seen intestsand for specific filters in the
docstrings intemplate/filters.py.Jinja functionsrun: Runs a command and returns the stdout, stderr and returncode
usingrun. This function replaces therunfilter.readfile: Returns the contents of a file.Example usage can be seen intestsand for specific filters in the
docstrings intemplate/functions.py.TestingTests requirePipenvandBats. Run the tests with the
following commands:pipenvrunlint# Pre-commit hooks.pipenvrundoctest# Doc tests.pipenvrunbats# Bats tests.pipenvruncheck# 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.ReleaseRelease requiresPipenvand Python 3.6 or later. To bump the version runpipenv run bumpversion major|minor|patchto update the version and git
commit and tag the changes, then rungit push --follow-tagsto push the
git commit and tag. The GitLab CI will then build and upload a release to PyPI.
To manually upload to PyPI runpipenv run buildto build the Python
package andpipenv run upload -s dist/*to upload a signed version.LicenseThis software is licensed under the AGPL 3+ license (see theLICENSE.txtfile).AuthorNimrod Adar,contact meor visit mywebsite. Patches are welcome viagit send-email. The repository is located
at:https://git.shore.co.il/nimrod/.