Jinjanator Plugins API

25.1.0 · active · verified Sun Apr 12

Jinjanator-plugins is a Python package, currently at version 25.1.0, that provides the essential plugin API (types and decorators) for extending the `jinjanator` CLI tool. This library allows developers to create custom plugins that add new data formats, Jinja2 filters, tests, globals, and extensions. It maintains an active development status with frequent releases, often tied to Python version support updates or API refinements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a minimal Jinjanator plugin that registers custom Jinja2 filters. It defines a `my_plugin.py` file using the `@plugin_filters_hook` decorator to expose 'scream' and 'reverse' filters. For Jinjanator to discover this plugin, it would typically be packaged as a Python project (e.g., using `pyproject.toml` with an entry-point) and installed into the same environment as `jinjanator`.

import os
from jinjanator_plugins import plugin_filters_hook

# my_plugin_example/pyproject.toml (illustrative, not run directly)
# [project]
# name = "jinjanator-my-plugin"
# version = "0.1.0"
# dependencies = [
#   "jinjanator-plugins==25.1.*", # Pinning recommended
# ]
#
# [project.entry-points."jinjanator.plugins"]
# my_plugin = "my_plugin_example.my_plugin"

# my_plugin_example/my_plugin.py

@plugin_filters_hook
def plugin_filters():
    """Registers custom Jinja2 filters."""
    def scream_filter(value):
        return str(value).upper() + "!!!"

    def reverse_filter(value):
        return str(value)[::-1]

    return {
        "scream": scream_filter,
        "reverse": reverse_filter,
    }

# Example usage within a Jinjanator template (template.j2) and CLI
# Assuming `my_plugin_example` is installed as a package and discoverable by jinjanator:
#
# template.j2:
# Hello {{ name | scream }}
# Message: {{ 'dlrow olleh' | reverse }}
#
# CLI command:
# $ jinjanate --data-var name="World" template.j2
# Output:
# Hello WORLD!!!
# Message: hello world

view raw JSON →