Skip to main content

patera-joltui

Install patera-joltui (or patera[joltui]) and import from patera.joltui.

from html import escape
from patera import Request
from patera.injectable import Inject
from patera.joltui import (
    ComponentGroup, JoltuiGroupHandler, PateraJoltui,
    component, group, joltui_request,
)

@group("default")
class DefaultGroupHandler(JoltuiGroupHandler):
    @component("home-page")
    async def home_page(self, req: Request):
        return req.res.html_body("<h1>Welcome</h1>")

@group("user-group")
class UserGroupHandler(JoltuiGroupHandler):
    @component("user-page")
    async def user_page(self, req: Request):
        data = joltui_request(req)
        user_id = escape(str(data.route_parameters["user_id"]))
        return req.res.html_body(f"<h1>User {user_id}</h1>")

class JoltuiInterface(PateraJoltui):
    default_group: ComponentGroup[DefaultGroupHandler]
    user_group: ComponentGroup[UserGroupHandler]

Register JoltuiInterface in your application's app_extensions, or inject it with joltui: Inject[JoltuiInterface]. Set JoltUI's serverComponentsUrl to /joltui/components (including Patera's URL_PREFIX, if configured). Override the endpoint with application configuration: JOLTUI_INTERFACE = {"COMPONENTS_PATH": "/components"}. The extension registers its own controller automatically; no application controller or manual dispatch route is needed. JoltuiConfig.COMPONENTS_PATH defaults to /joltui/components.

JoltUI sends a JSON POST containing tagName, groupName, routeParameters, queryParameters, and attributes. Omitted/null groups default to default; omitted/null parameter mappings default to empty dictionaries. Tags are trimmed and lowercased, while group names remain case-sensitive.

Handlers receive the original Patera Request, retaining cookies, sessions, headers, request context, and response helpers. joltui_request(req) provides validated frontend metadata as tag_name, group_name, route_parameters, query_parameters, and attributes. HTTP URL parameters stay unchanged; frontend route parameters are accessed through this metadata. The original JSON is also available through await req.json().

Always return a Patera Response with content type text/html (for example, req.res.html_body(markup) or await req.res.html("user.html", ...)). Plain strings and non-HTML responses are rejected. Sync handlers are supported too. Malformed requests return 400; unknown groups/components return 404. Handler exceptions follow Patera's normal exception pipeline, including 401/403.

Groups are app-scoped and support Inject[T] dependencies. Do not store per-request data on group instances. Inherited component methods are exposed; overriding a method without @component removes its registration. Duplicate group names or component tags fail at initialization. Only decorated methods in explicitly declared groups are callable. Interface annotations may be inherited, overridden, or removed with a non-ComponentGroup annotation.

Group handlers are Patera controllers. Use the normal controller and endpoint decorators, including group/endpoint @login_required() and @role_required(), @after_init, @before_request, @after_request, @consumes, @produces, @cors, @no_cors, @max_content_length, @ignore, and @development. Authentication decorators require the application's usual authentication middleware. For example:

from patera.auth import login_required, role_required
from patera.controller import after_request, produces
from patera import MediaType

@group("user-group")
@login_required()
class UserGroupHandler(JoltuiGroupHandler):
    @after_request
    def prevent_caching(self, res):
        res.set_header("Cache-Control", "no-store")

    @component("user-page")
    @role_required("admin")
    @produces(MediaType.TEXT_HTML)
    async def user_page(self, req: Request):
        return req.res.html_body("<h1>Users</h1>")

Component selection runs before CORS, database, authentication, and application middleware. They see the selected bound component as req.route_handler and its group as current_request.controller. Normal controller hooks run once; after-request hooks receive the handler's HTML Response. Successful component responses must be HTML. Error responses (status 400 or higher), including @consumes' JSON 415 response and lifecycle-generated errors, retain their normal media type and status instead of being rejected as non-HTML. Decorators such as @produces that operate on a response expect handlers to return a Response, just as on ordinary endpoints. @consumes validates the original JSON envelope, not just its attributes field.

Response caching defaults to GET/HEAD. To cache a read-only component RPC, explicitly use @cache("PUBLIC_CACHE", methods=("POST",)); the default key includes the complete body digest, including group, tag and route parameters. Use a callable cache key for additional header-dependent variations.

All components share one HTTP POST URL: @path/HTTP method decorators do not create additional component URLs, and WebSocket transport is not provided by this endpoint. OpenAPI metadata can be attached, but individual RPC components are not separate OpenAPI routes. OPTIONS preflights have no component body, so they use the shared endpoint's global CORS policy; configure it to permit the frontend. Component CORS overrides apply to actual POST responses.

The application's body limit protects JSON envelope parsing. Component @max_content_length limits are additionally enforced after selection and cannot bypass that initial envelope limit. Frontend metadata is client input, not an authorization source. Escape values inserted into raw HTML, or use your application's templates.

Handlers may declare an optional third argument annotated with any Pydantic model. The extension validates the full JSON body into that model automatically; @consumes is not required. Model validation failures return 422 before the handler runs. Authentication and controller before-request hooks run first.

from pydantic import BaseModel, Field
from patera import Response

class UserRoute(BaseModel):
    user_id: int

class UserPageBody(BaseModel):
    route_parameters: UserRoute = Field(alias="routeParameters")
    # tagName and groupName need not be declared in a custom model.
    # Pydantic's default extra="ignore" ignores undeclared envelope fields.

@group("user-group")
class UserGroupHandler(JoltuiGroupHandler):
    @component("user-page")
    async def user_page(self, req: Request, body: UserPageBody) -> Response:
        return req.res.html_body(f"<h1>User {body.route_parameters.user_id}</h1>")

For example, the request body is:

{"tagName": "user-page", "groupName": "user-group", "routeParameters": {"user_id": "42"}}

body.route_parameters.user_id is validated and converted to the integer 42. The original Request and its JSON body remain available. Use JoltuiRequest as the third argument if its standard fields suffice, or define your own model with nested models and aliases as above. JoltuiRequest.tag_name defaults to None and group_name to "default", so neither field is required when constructing the model. The actual RPC envelope still requires tagName to select the handler; groupName may be omitted to select the default group. Custom models receive the original body and follow their own Pydantic defaults, coercion, extra-field policy, and validators.

Metadata

Release files for patera-joltui 0.2.5

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

Source distribution (sdist)

Source distribution for patera-joltui 0.2.5
File Size Uploaded Provenance Actions
patera_joltui-0.2.5.tar.gz 8.5 kB Without provenance Details for patera_joltui-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for patera-joltui 0.2.5
File Interpreter ABI Platform Actions
patera_joltui-0.2.5-py3-none-any.whl Python 3 none any Details for patera_joltui-0.2.5-py3-none-any.whl

Total release size: 18.5 kB

Release files / patera_joltui-0.2.5.tar.gz

Download URL patera_joltui-0.2.5.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fc7880afa7fe00d8b9e592db7d5605f32aacdd67ba1bf0129657f3c46ab6ed9c
BLAKE2b-256 checksum
How to use checksums
d5e568494d56f90a4896350d66b6724d04a457c088bb093c87e3e57fdc07070c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / patera_joltui-0.2.5-py3-none-any.whl

Download URL patera_joltui-0.2.5-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a65f6789356bd7da6306d919468f127131c810ecf78f4b1de3db717f30037518
BLAKE2b-256 checksum
How to use checksums
9d9410908508297119c499608726daedd3b4d8b5b2544c6b549d8845fe8cb033
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for patera-joltui 0.2.5

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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