Skip to main content

xyberos-templates

Server-rendered pages for a Xyberos application, with the render off the event loop and escaping that is stated rather than inherited.

starlette.templating.Jinja2Templates is nearly this, and the two places it is not are the whole reason this package exists.

  • TemplateResponse renders synchronously inside __init__, so the entire render cost lands on the event loop before any response bytes move. This package renders through anyio.to_thread.run_sync(template.render, ...), and switches to Jinja2's enable_async=True with await template.render_async(...) when a template itself awaits. The two paths differ in a way worth knowing: render_async yields to the loop between its awaits, but it does not reduce CPU time — the render is still the loop's work.
  • select_autoescape() decides by file extension, so a template named page.j2 is silently unescaped while page.html is not. Autoescape here is a stated policy: every template is escaped, whatever it is called, and the only unescaped output is markup that was marked safe on purpose.

The seam is a Protocol, not a base class. A handler depends on Templates; Jinja2 is the engine this package ships, and a team that would rather write typed components implements the same three members instead of forking this package.

Install

pip install xyberos-templates

Register it

Settings are explicit, frozen, and validated where a bad value would otherwise fail on the first request rather than at startup.

from starlette.requests import Request
from starlette.responses import Response

from xyberos_templates import Jinja2Templates, TemplatesSettings

templates = Jinja2Templates(
    TemplatesSettings(directory="templates", static_path="/static")
)


@app.get("/")
async def index(request: Request) -> Response:
    return await templates.render("index.html", {"title": "Home"})

directory, autoescape, enable_async, and static_path are the whole of the configuration. New filters and globals go on the Jinja environment those settings built:

templates.environment.filters["money"] = format_money

The other two members of the contract are static files and forms:

asgi_app = HttpAdapter(app).asgi_app
templates.mount_static(asgi_app, "static")  # returns "/static"


@app.post("/signup")
async def signup(request: Request) -> Response:
    form = await templates.read_form(request)  # python-multipart, declared by this package
    return await templates.render("thanks.html", {"email": form["email"]})

Rendering a template that itself awaits — an async callable in the context, say — needs enable_async=True, which moves the render onto the loop on purpose:

templates = Jinja2Templates(TemplatesSettings(directory="templates", enable_async=True))

What it does not do

  • No caching layer. Jinja2 compiles and caches templates itself. There is nothing above it, and no render cache keyed by template and context.
  • No second engine. Jinja2 is the one engine shipped. Bringing another is implementing the Templates protocol, not configuring this package.
  • No asset pipeline. mount_static serves a directory; hashing, bundling, and CDN URLs stay with the application.
  • No request-scoped helpers. The context is exactly what the caller passes; nothing is injected behind its back.
  • No root key in Settings. Settings are passed in, so nothing outside the application's own code decides where its pages come from.

Metadata

Release files for xyberos-templates 0.1.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 xyberos-templates 0.1.0
File Size Uploaded Provenance Actions
xyberos_templates-0.1.0.tar.gz 11.0 kB With provenance Details for xyberos_templates-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xyberos-templates 0.1.0
File Interpreter ABI Platform Actions
xyberos_templates-0.1.0-py3-none-any.whl Python 3 none any Details for xyberos_templates-0.1.0-py3-none-any.whl

Total release size: 19.1 kB

Release files / xyberos_templates-0.1.0.tar.gz

Download URL xyberos_templates-0.1.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9ef47938806be1a4899daee774193bcb20268af69dfc8fbd9f3e361422916937
BLAKE2b-256 checksum
How to use checksums
3032827b85be5c1d997e4b432aa8867a483c764d8fa4485adcab535da6ce2eaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / xyberos_templates-0.1.0-py3-none-any.whl

Download URL xyberos_templates-0.1.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
856ecf76be2c88a1929aa384c20627ac31f5aa6b4171c9e725d5b1dfa2130d6e
BLAKE2b-256 checksum
How to use checksums
32f53850138c72cee1c14058d859c946341e4ae374aab2deb30578eed4bd800a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Security for xyberos-templates 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for xyberos_templates-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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