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
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.
NestedDictLoader
[example]
template = "{{ something }}"
content = tomllib.load(toml_file)
loader = NestedDictLoader(content)
env = Environment(loader=loader)
env.get_template("example/template")
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 = FsSpecFileSystemLoader("dir::github://phil65:jinjarope@main/tests/testresources")
env = Environment(loader=loader)
env.get_template("testfile.jinja").render()
# protocol and storage options
loader = FsSpecFileSystemLoader("github", org="phil65", repo="jinjarope")
env = Environment(loader=loader)
env.get_template("README.md").render()
# fsspec filesystem
fs = fsspec.filesystem("github", org="phil65", repo="jinjarope")
loader = FsSpecFileSystemLoader(fs)
env = 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 = FsSpecProtocolPathLoader()
env = Environment(loader=loader)
env.get_template("github://phil65:jinjarope@main/tests/testresources/testfile.jinja").render()
Additional filters
pformat
: pprint.pformatrepr
: reprrstrip
: str.rstriplstrip
: str.lstripremovesuffix
: str.removesuffixremoveprefix
: str.removeprefixadd
: Optionally add a prefix / suffix to a value if value is truth-yissubclass
: issubclassisinstance
: isinstanceimport_module
: importlib.import_modulehasattr
: hasattrevaluate
: Evaluate text as python code and return last statementpartial
: functools.partialdump_json
: json.dumpsload_json
: json.loadsload_toml
: tomllib.loadsload_file
: Accepts a path or a fsspec protocol URL and returns content as strpath_join
: os.path.joinformat_js_map
: format_js_map (format a dictionary as JavaScript map)check_output
: subprocess.check_output (as str)getenv
: os.getenv
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
Hashes for jinjarope-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fe47b05609da8b5fd85c4951abc85a8c8beb4725b52d4d43b73d9a0fa63e429 |
|
MD5 | 70cb3ed1f5b94177c1af3c8172678396 |
|
BLAKE2b-256 | 98e4549aa439496b9ed478ada3cab632b563d1daa73800e2bd69cfd2fbe6e3d3 |