jinjarope¶
How to install¶
pip¶
The latest released version is available at the Python package index.
With CLI:Quick guide¶
Jinjarope contains a range of Jinja2 loaders (including fsspec-based ones) as well as a jinja2.Environment
subclass with added functionality.
For debugging purposes, an FsSpec filesystem implementation for jinja2 loaders is also included.
FsSpecFileSystemLoader¶
This loader can be used like a FileSystemLoader, but also works on any fsspec-supported
remote path.
Using the dir::
prefix, any folder can be set as root.
# protocol path
loader = jinjarope.FsSpecFileSystemLoader("dir::github://phil65:jinjarope@main/tests/testresources")
env = jinjarope.Environment(loader=loader)
env.get_template("testfile.jinja").render()
# protocol and storage options
loader = jinjarope.FsSpecFileSystemLoader("github", org="phil65", repo="jinjarope")
env = jinjarope.Environment(loader=loader)
env.get_template("README.md").render()
# fsspec filesystem
fs = fsspec.filesystem("github", org="phil65", repo="jinjarope")
loader = jinjarope.FsSpecFileSystemLoader(fs)
env = jinjarope.Environment(loader=loader)
env.get_template("README.md").render()
FsSpecProtocolPathLoader¶
This loader accepts any FsSpec protocol path to be used directly. A complete protocol URL to the template file is required.
loader = jinjarope.FsSpecProtocolPathLoader()
env = jinjarope.Environment(loader=loader)
env.get_template("github://phil65:jinjarope@main/tests/testresources/testfile.jinja").render()
NestedDictLoader¶
content = tomllib.load(toml_file)
loader = jinjarope.NestedDictLoader(content)
env = jinjarope.Environment(loader=loader)
env.get_template("example/template")
General loader information¶
jinjarope also contains subclasses for all default jinja2 loaders. These loaders
have implementations for some magic methods (__eq__
, __hash__
, __repr__
, , __getitem__
).
The loaders can also get ORed to return a ChoiceLoader.
Prefix loaders can get created using pathlib-style string concatenations
Additional filters / tests¶
Check out the documentation for a list of built-in filters and tests!