Jinja2 utilities, loaders & fsspec integration.
Project description
jinjarope
How to install
pip
The latest released version is available at the Python package index.
pip install jinjarope
With CLI:
pip install jinjarope[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
[example]
template = "{{ something }}"
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__
).
loader = jinjarope.FileSystemLoader(...)
template_source = loader["path/to/template.jinja"]
The loaders can also get ORed to return a ChoiceLoader.
choice_loader = jinjarope.FileSystemLoader(..) | jinjarope.PackageLoader(...)
Prefix loaders can get created using pathlib-style string concatenations
prefix_loader = "path_prefix" / jinjarope.FileSystemLoader(...)
Additional filters / tests
Check out the documentation for a list of built-in filters and tests!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file jinjarope-0.16.0.tar.gz
.
File metadata
- Download URL: jinjarope-0.16.0.tar.gz
- Upload date:
- Size: 2.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.4.30
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c1b4cfda5d26be3f0f6a8749cd8162a4e3aef61e86a1b9d2c0cdb6521d02b51 |
|
MD5 | d695cd01a88577302412d7fb7a960afb |
|
BLAKE2b-256 | 8f7ad991b5fe4c1f5ae0022bcf6c54190de8f7b2e58af3ec6b37f1c146c58c15 |
File details
Details for the file jinjarope-0.16.0-py3-none-any.whl
.
File metadata
- Download URL: jinjarope-0.16.0-py3-none-any.whl
- Upload date:
- Size: 2.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.4.30
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e57878505bbe1fff86785978776e029036db422d6f31be6d0aa298f7b867943 |
|
MD5 | 6e52cc7d9e3e2edd59b2668c2b706ac3 |
|
BLAKE2b-256 | 16952006c7a771525ebd2d003e9376f2e62bc918c18cd280319878b1e58c99b6 |