Skip to main content

Jinja2 utilities, loaders & fsspec integration.

Project description

jinjarope

JinjaRope

PyPI License Package status Daily downloads Weekly downloads Monthly downloads Distribution format Wheel availability Python version Implementation Releases Github Contributors Github Discussions Github Forks Github Issues Github Issues Github Watchers Github Stars Github Repository size Github last commit Github release date Github language count Github commits this week Github commits this month Github commits this year Package status Code style: black PyUp

Read the documentation!

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinjarope-1.0.1.tar.gz (2.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jinjarope-1.0.1-py3-none-any.whl (2.7 MB view details)

Uploaded Python 3

File details

Details for the file jinjarope-1.0.1.tar.gz.

File metadata

  • Download URL: jinjarope-1.0.1.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jinjarope-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8de86a0c3781ea8cdd6bd7f93f3f2fac957eb1f5b80c2a7cb3a0cd3fd72324d2
MD5 f9805294dc2fa70ad7d18544ccc3fbc4
BLAKE2b-256 e9482c70eebbc98d27e82c996688fcbe1eb351e72d8317ed4c5e348476c254ef

See more details on using hashes here.

File details

Details for the file jinjarope-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: jinjarope-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jinjarope-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 13e34d25dadaffd9a30b225bd53404ba3cf380d840f535bd294ec304520e8709
MD5 f16904734e37ecd6d86a2de5b7eb007f
BLAKE2b-256 12af7bc9383db1b6864a3a315bdbbe72110df82a8ffd7f9ee281f45f5c204699

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page