Skip to main content

Jinjapy

New hybrid file format combining a Jinja template with Python code in a frontmatter.

Installation

pip install jinjapy

Usage

A jinjapy file is a standard python module which is attached to a jinja template.

A folder containing multiple jinjapy files is registered as a python package using register_package(). This returns a Jinja loader than can be used to create a Jinja environment.

from jinja2 import Environment
import jinjapy

loader = jinjapy.register_package("my_package")
env = Environment(loader=loader)

# execute the module + render the template
# the module globals are used as the template context
template_output = jinjapy.execute_module(env, "my_package.module")

# module is available like any other import
import foo from my_package.module

my_package/module.jpy:

---
foo = "bar"
---
{{ foo }}

Specification

A jinjapy file contains 2 sections:

  • A frontmatter with some Python code (enclosed by lines containg 3 dashes "---")
  • A body containing some Jinja template code

Both are optional:

  • If the frontmatter is missing, the file only contains a Jinja template. It won't be available as a python module.
  • If the frontmatter is left unclosed (the file starts with "---" on a single line followed by some python code), the file has no template

Editor support

A VS Code extension is available to add syntax highlighting for jinjapy files.

Syntax highlighting

A pyment lexer is provided, named "jinjapy" or "jpy". It will also match .jpy files.

How does it work

A custom package finder and package loader is added to python search path. The loader extracts the python code from the frontmatter on load.

The returned Jinja loader does the same for the jinja template: it removes the frontmatter and only returns the remplate code.

Metadata

Release files for jinjapy 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinjapy 0.2.0
File Size Uploaded
jinjapy-0.2.0.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jinjapy 0.2.0
File Interpreter ABI Platform
jinjapy-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 kB

Release files / jinjapy-0.2.0.tar.gz

Download URL jinjapy-0.2.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
260c3000403b14506693b2f41710e2ff086c4325ed3dc2cc3d6f0cd0e7a998a6
BLAKE2b-256 checksum
How to use checksums
040c4fa62493c4c7c2bbc8c2bffbcedb225c05eb51c3215471029dc1583625dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / jinjapy-0.2.0-py3-none-any.whl

Download URL jinjapy-0.2.0-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87524183ed9e47718bf602dd97bbc32c1cf3a4f687f8a6ea5d6c564b389e88f9
BLAKE2b-256 checksum
How to use checksums
3c24e19ce6258dc25f7dcd52d8188a411e74508c6fd19d369f619b1d5147c3b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page