Skip to main content

A stand-alone renderer for Jinja2 templates

Project description

# `hokora` is a [Jinja2][jinja-main] standalone template parser

You might be familiar with Jinja2 templates if you've worked with Flask, Ansible, Salt or dbt. hokora is a tool for rendering Jinja templates on the command line, or as part of a bash pipeline.

README.md in this repository is itself generated by hokora, from the README.md.in.

Usage

usage: hokora [-h] [--context CONTEXT] [--environ] [-C C] [--no-include-env]
              [--no-include-cwd] [--no-include-template-dir]
              [--include INCLUDE] [--autoescape | --no-autoescape]
              [--strip-shebang | --no-strip-shebang]
              [--clean-whitespace | --no-clean-whitespace | -w]
              [--line-endings [LINE_ENDINGS]]
              [template]

Hokora: Standalone Jinja2 template renderer

positional arguments:
  template              path to template to render

options:
  -h, --help            show this help message and exit
  --autoescape, --no-autoescape
                        whether to escape HTML entities in jinja expressions
  --strip-shebang, --no-strip-shebang
                        remove the first line of the output if it is a bash
                        shebang
  --clean-whitespace, --no-clean-whitespace, -w
                        Remove trailing whitespace from lines of the output
  --line-endings [LINE_ENDINGS]
                        Normalize line endings of the output. Options
                        includeCRLF (windows), LF (unix, modern mac), CR
                        (classic mac).If passed without an argument, the
                        default for your platformwill be used

Jinja Context Variables:
  --context, -c CONTEXT
                        Read the given file for context values to supply as
                        jinja variables. Use key=filename if you want to
                        namespace the data, like {{key.somevar}}. See
                        AVAILABLE CONTEXT FORMATS below for supported file
                        extensions.
  --environ, -e         Make environment variables available as jinja
                        variables

Template search paths:
  -C C                  Change directories to this folder and interpret all
                        paths as relative to it.
  --no-include-env      Don't parse $JINJA_TEMPLATE_DIRS for include folders
  --no-include-cwd      Don't include the current working directory in the
                        search path
  --no-include-template-dir
                        Don't include the template's folder in the search
                        path.
  --include, -I INCLUDE
                        Add this folder to the template include path


ENVIRONMENT VARIABLES

  $JINJA_TEMPLATE_DIRS
    A :-separated list of additional template include paths, which
    will be searched to handle {%extends %}, {%include %} and {%import %}
    tags unless --no-include-env is passed at the command line.

  $HOKORA_MODULES
    Additional python modules (honoring $PYTHONPATH) to import at load time.
    These can be used to extend the functionality of hokora if they contain
    subclasses of DataFormat or HokoraFeature.


AVAILABLE CONTEXT FORMATS

  json                {{ ... | json }}                                *.json
  python              {{ ... | python }}            *.py, *.pyc, *.pyd, *.so
  pickle              {{ ... | pickle }}                     *.pkl, *.pickle
  toml                {{ ... | toml }}                                *.toml
  yaml                {{ ... | yaml }}                         *.yaml, *.yml

Installation

hokora requires Python >=3.10.

Standalone script via uv

If you're on a Unix-like operating system, the ./hokora script in the root of this repo can just be copied into ~/.local/bin or some appropriate place on your $PATH. uv will reach out to gitlab and grab the latest version the first time you run it.

Local install via pipx

pipx install hokora

Local install via pip

python3 -m pip install hokora

Metadata

License

hokora is licensed under a BSD 3-Clause License, like Jinja itself.

hokora's icon is licensed under creative commons attribution share-alike 4.0 international with a hat tip to wikimedia user Immanuelle who made the original.

Name

Jinja itself says it's named for a Shinto shrine because the word "template" sounds vaguely like the word "temple." Well, two can play the Wikipedia game. A Hokora is a miniature Shinto shrine, and hokora is a miniature wrapper around Jinja.

Contributing

Issues and MRs are welcome.

  • The main branch is kept stable. Tinker in topic branches.

  • Don't edit README.md directly; edit README.md.in.

  • Update version numbers as necessary. Follow semver

  • Make sure your code is sane:

    ruff format
    ruff check
    mypy --check-untyped-defs .
    

Project details


Download files

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

Source Distribution

hokora-0.1.4.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hokora-0.1.4-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file hokora-0.1.4.tar.gz.

File metadata

  • Download URL: hokora-0.1.4.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for hokora-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f0f5dc0e4d887cb711d4e2d006c4e02114925a4dd0cedd36f5db22affbe350b0
MD5 5c1eab42a71f643df87818f1a191389b
BLAKE2b-256 5a086a7e5b1c92d43c5ac7cf23a6e9d5ed3963d2df1025d77baa8ec47f9b5293

See more details on using hashes here.

File details

Details for the file hokora-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: hokora-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for hokora-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f3c294debba8afa9bb2e1d84d15cd95216a95b462971ca790dd9b7b751066c54
MD5 cb919564efb8ef7b94ab8c0a36d260e1
BLAKE2b-256 2090911059da10b3ac7647349ea6dc21c8e76bb93bcab863e1a63463d7feda52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page