Skip to main content

Jinja Simple CLI, is a tool that allows you to compose and insert data in to templates, with support for template inheritance and global functions. It uses json files as input for the data, and it can handle templates from standard input.

Project description

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.


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.


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 2> /dev/null | jinja-cli -i examples/templates/xkcd.htm -j -
    <h2>Petit Trees (sketch)</h2>
    <img src=""/>
    <p>'Petit' being a reference to Le Petit Prince, which I only thought about halfway through the sketch</p>

Using Jinja Filters

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

# fragment of examples/
import jinjasimplecli.extensions as je

def hello_world(issue_number):
    url = f"{issue_number}"
    data = requests.get(url).json()
    return f"Issue - {data['number']} - {data['title']}"

So now running $ echo "{{ 1|issue }}" | jinja-cli -c examples/ 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.


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

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jinjasimplecli, version 1.0.7
Filename, size File type Python version Upload date Hashes
Filename, size jinjasimplecli-1.0.7.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View
Filename, size jinjasimplecli-1.0.7-py3-none-any.whl (7.1 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page