Jinjanator Plugins API
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
- breaking Python 3.9 support was removed, and minimum Python version is now 3.10 as of version 25.1.0. Python 3.8 support was removed, and 3.13 was added in version 24.2.0. Users on older Python versions must upgrade to use recent `jinjanator-plugins` versions.
- gotcha It is strongly recommended to pin the dependency for `jinjanator-plugins` to a specific version or a narrow 'year.release' version range (e.g., `==25.1.*`) in your plugin projects. The API can change in a non-backward-compatible fashion, which may lead to breakage if not pinned.
- breaking The 'formats' API underwent a redesign in version 23.4.0 to better support formats that need to store data for their parsers. Plugins implementing custom data formats might require updates.
Install
-
pip install jinjanator-plugins
Imports
- plugin_filters_hook
from jinjanator_plugins import plugin_filters_hook
- plugin_tests_hook
from jinjanator_plugins import plugin_tests_hook
- plugin_globals_hook
from jinjanator_plugins import plugin_globals_hook
- plugin_formats_hook
from jinjanator_plugins import plugin_formats_hook
- plugin_extensions_hook
from jinjanator_plugins import plugin_extensions_hook
- plugin_identities_hook
from jinjanator_plugins import plugin_identities_hook
- Format
from jinjanator_plugins import Format
Quickstart
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