Registry / web-framework / jinja-partials

jinja-partials

JSON →
library0.3.2pypypi✓ verified 21d ago

Jinja Partials is a Python library designed for the simple reuse of partial HTML page templates within the Jinja template language, particularly for Python web frameworks. It addresses the 'long template problem' by enabling function-like reusability for HTML fragments. The library is currently active, with its latest version being 0.3.1, and shows a consistent release cadence.

pip install jinja-partials
INSTALL
IMPORT
SIG · JINJA-PARTIALS
J
jinja-partials
web-frameworkpythonv0.3.2
Install
1.8s avg
Import
323ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.344s · 19MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.302s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

register_extensions
from jinja_partials import register_extensions
For Flask applications.
register_fastapi_extensions
from jinja_partials import register_fastapi_extensions
For FastAPI applications.
register_starlette_extensions
from jinja_partials import register_starlette_extensions
For Starlette applications.
register_quart_extensions
from jinja_partials import register_quart_extensions
For Quart applications.
register_environment
from jinja_partials import register_environment
For standalone Jinja2 environments outside of a web framework.
PartialsJinjaExtension
from jinja_partials import PartialsJinjaExtension
For declarative registration as a Jinja2 extension (available since v0.3.0).

This quickstart demonstrates how to integrate `jinja-partials` with a Flask application. It shows how to register the extension and use the `render_partial` function in your templates. Create an `index.html` and a `partials/greeting.html` inside a `templates` directory, then run the Flask app.

import flask from jinja_partials import register_extensions import os app = flask.Flask(__name__) # Assuming templates are in a 'templates' directory and partials in 'templates/partials' register_extensions(app) @app.route('/') def index(): return flask.render_template('index.html', title='Home Page', user={'name': 'Alice'}) # Example template structure: # templates/ # index.html # partials/ # greeting.html # index.html content: # <!DOCTYPE html> # <html> # <head><title>{{ title }}</title></head> # <body> # <h1>Welcome!</h1> # {{ render_partial('greeting.html', name=user.name) }} # </body> # </html> # partials/greeting.html content: # <p>Hello, {{ name }} from a partial!</p> if __name__ == '__main__': # In a real app, you'd run with `flask run` or a WSGI server. # For this quickstart, we'll simulate rendering directly. # You would typically run `app.run(debug=True)` print("Quickstart setup complete. Run this with a Flask development server.")
Debug
Known issues
breakingThe minimum required Python version for `jinja-partials` is now 3.10.
fix
Ensure your project is running on Python 3.10 or newer. Upgrade your Python environment if necessary.
affects: >=0.3.0
gotchaAsync rendering issues, specifically `asyncio.run() cannot be called from a running event loop`, were fixed in v0.3.1 for async frameworks (Quart, FastAPI, Starlette).
fix
Upgrade to `jinja-partials` version 0.3.1 or newer to resolve issues with asynchronous rendering in async web frameworks.
affects: <0.3.1
gotchaThe `app` parameter for `register_starlette_extensions` became optional in v0.3.1. While often passed, its previous mandatory status might cause minor type-checking or linting issues if not updated.
fix
Review calls to `register_starlette_extensions`. The `app` parameter can now be omitted if not needed for lifecycle management.
affects: >=0.3.1
gotchaJinja's native `include` directive differs fundamentally from `jinja-partials`. `include` acts like a C++ preprocessor macro without parameters, merely inserting template content. `jinja-partials` provides function-like reusability with explicit parameters and local variable scope, offering a more robust way to manage reusable HTML fragments.
fix
Understand that `render_partial()` offers parameter passing and local scope, unlike `{% include '...' %}`. Use `jinja-partials` when you need to pass data specifically to a reusable fragment like a function.
affects: All versions
gotchaA new declarative approach using `PartialsJinjaExtension` was introduced in v0.3.0. This offers an alternative to the `register_..._extensions` functions, particularly useful for declarative Jinja2 environment configurations.
fix
Consider using `app.jinja_env.add_extension('jinja_partials.PartialsJinjaExtension')` (for Flask) or adding `"jinja_partials.PartialsJinjaExtension"` to your `extensions` list for standalone Jinja2 environments, especially if you prefer a declarative setup.
affects: >=0.3.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'jinja_partials'
The 'jinja-partials' library is not installed in your Python environment.
fix
pip install jinja-partials
jinja2.exceptions.UndefinedError: 'render_partial' is undefined
The 'jinja-partials' extension has not been correctly registered with your Jinja2 environment or web framework (e.g., Flask, FastAPI, Starlette, Quart).
fix
For Flask, add `import jinja_partials` and then call `jinja_partials.register_extensions(app)` after initializing your Flask app. For other frameworks, refer to the documentation for the appropriate registration function (e.g., `register_fastapi_extensions`).
AttributeError: module 'jinja_partials' has no attribute 'register_flask_extensions'
You are attempting to call a non-existent registration function, likely due to a typo or misunderstanding of the API for framework-specific registration.
fix
Use the correct registration function for your framework, such as `jinja_partials.register_extensions(app)` for Flask, `jinja_partials.register_fastapi_extensions(app, templates)` for FastAPI, `jinja_partials.register_starlette_extensions(templates, app=app)` for Starlette, or `jinja_partials.register_quart_extensions(app)` for Quart.
Upgrade
Version history
0.3.2latest on PyPI · released Jun 11, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources