Skip to main content

Jinja Simple CLI

This project offers a way to easily compose templates directly from the command line, ideal to use in junction with other cli utilities.

You could check the examples under the examples directory and check the By running jinja-cli --help on your terminal, you'll get all the basic functioning for the tool.

Basics

If you know Jinja, you will get how this works easily.

  • INPUT or template, is the text stream or file that you are attempting to render by default stdin.
  • DATA or json-data, is the text stream or file that contains the data used in the template and it's dependencies, by default is an empty json.
  • ROOT or template-directory, is the search path for jinja's FileSystemLoader.
  • CONFIG or extensions-file, is a python file that contains functions that will be avalible to call from the templates, could be filters.
  • OUTPUT or output, is where to write the rendered template, by default is stdout.

Remark: This is more related to *sh scripting than this tool, but notice that we mention streams, so we could run the following commands and they would be equivalent in output.

cat examples/templates/users.htm | jinja-cli -j examples/data/users.json
cat examples/data/users.json | jinja-cli -j - -i examples/templates/users.htm
jinja-cli -i examples/templates/users.htm -j examples/data/users.json
jinja-cli -i <(cat examples/templates/users.htm) -j <(cat examples/data/users.json)

This is because the argument parsing for the input template and json data, was thinked in a way that you send any of does two as streams so we could use and compose with other cli tools.

Examples

All the examples could be reproduced with the files in the examples directory.

Curl in to a template

Using the data variables you could fill templates pulling data from any kind of source, and insert it using standard input

$ curl https://xkcd.com/2/info.0.json 2> /dev/null | jinja-cli -i examples/templates/xkcd.htm -j -
<article>
    <h2>Petit Trees (sketch)</h2>
    <img src="https://imgs.xkcd.com/comics/tree_cropped_(1).jpg"/>
    <p>'Petit' being a reference to Le Petit Prince, which I only thought about halfway through the sketch</p>
</article>

Using Jinja Filters

You could also use custom functions and call them as filters from your config file, eg.

# fragment of examples/extensions.py
import jinjasimplecli.extensions as je

@je.filter('issue')
def hello_world(issue_number):
    url = f"https://api.github.com/repos/ekiim/jinjasimplecli/issues/{issue_number}"
    data = requests.get(url).json()
    return f"Issue - {data['number']} - {data['title']}"

So now running $ echo "{{ 1|issue }}" | jinja-cli -c examples/extensions.py we get Issue - 1 - Merge Guide and Readme.

Jinja other features

When using template inheritance or referencing another template to import or include, you should make reference to it, considering the ROOT path you provided.

License

Jinja Simple CLI is licensed under the BSD 3-Clause license.

Metadata

Release files for jinjasimplecli 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinjasimplecli 1.0.7
File Size Uploaded Provenance
jinjasimplecli-1.0.7.tar.gz 5.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for jinjasimplecli 1.0.7
File Interpreter ABI Platform
jinjasimplecli-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / jinjasimplecli-1.0.7.tar.gz

Download URL jinjasimplecli-1.0.7.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
17b637048fc9741a45842771907f025c5bc2c8b8aec88de3494be768d49d743b
BLAKE2b-256 checksum
How to use checksums
b9412e0b7825eadc10b9acda46d5770ce49e216ea36c277480622d6303905088
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.3

Release files / jinjasimplecli-1.0.7-py3-none-any.whl

Download URL jinjasimplecli-1.0.7-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3996713dbe2730e0e9cfe25640414e4aa2843b2fa3ed7a3a01e42f3129b625d3
BLAKE2b-256 checksum
How to use checksums
fad5b099135913e8955204b7e53e7f0c357f46b66a86227a1d0e2ee416e2baee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.3

Security for jinjasimplecli 1.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page