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, Response
from patera.controller import path
from patera.injectable import Inject
from patera.joltui import (
    ComponentGroup, JoltuiController, JoltuiGroupHandler, PateraJoltui,
    component, dispatcher, 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]

@path("/joltui")
class JoltuiComponentsController(JoltuiController):
    joltui: Inject[JoltuiInterface]

    @dispatcher("/components")
    async def components(self, req: Request) -> Response:
        return await self.joltui.dispatch(req)

JoltuiInterface is an injectable service; the application owns the endpoint. @dispatcher registers the POST route of a JoltuiController subclass that receives the component requests, in place of @post: bare @dispatcher serves the controller's path, @dispatcher("/components") a path below it. The route stays out of OpenAPI unless open_api_spec=True. It calls dispatch(req) on the controller's single injected PateraJoltui attribute and returns its response. A controller has one @dispatcher endpoint; its other endpoints are ordinary and keep their usual decorators. A JoltuiController with no injected interface, or several, fails at build. Injecting the interface creates its app-wide instance; the controller registers the dispatch middleware. Set JoltUI's serverComponentsUrl to the endpoint's URL (here /joltui/components, including Patera's URL_PREFIX, if configured).

The controller's @before_request/@after_request hooks run around dispatch. Put @login_required(), @role_required(), @transactional, @cors and @no_cors on groups or components. They are not supported on the @dispatcher endpoint or on the JoltuiController: it would be ambiguous whether they guard the component request or the component, so the application refuses to build. A second @dispatcher, another route decorator on it, or one outside a JoltuiController also fails at build. Calling dispatch anywhere but the @dispatcher endpoint raises RuntimeError.

Upgrading: the auto-registered controller and JoltuiConfig.COMPONENTS_PATH were removed. Add the controller above with your previous URL and delete the setting (configuring it raises an error).

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 in a middleware before CORS, database, authentication, and application middleware. They see the selected bound component as req.route_handler and its group as current_request.controller; req.endpoint remains the component endpoint. 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 of an interface share its HTTP POST URL: @path/HTTP method decorators on groups do not create additional component URLs, and WebSocket transport is not provided. OpenAPI metadata can be attached, but individual RPC components are not separate OpenAPI routes. OPTIONS preflights have no component body, so they use the 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 RequestBody[Model] (from patera.controller) 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
from patera.controller import RequestBody

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: RequestBody[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 RequestBody[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.5.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 patera-joltui 0.5.0
File Size Uploaded Provenance Actions
patera_joltui-0.5.0.tar.gz 12.4 kB Without provenance Details for patera_joltui-0.5.0.tar.gz

Built distribution (wheel)

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

Total release size: 25.5 kB

Release files / patera_joltui-0.5.0.tar.gz

Download URL patera_joltui-0.5.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
729466d8e8b417dbb7bd5fc32973a02c9c9c3b1bbcabce5d06c13cd8bfd6b2ef
BLAKE2b-256 checksum
How to use checksums
faa1db9883afb71e8971e10f6616b6e13829ee6141135ffd2783ca9369951bdf
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.5.0-py3-none-any.whl

Download URL patera_joltui-0.5.0-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
978ebeee8228e403271b8c678ae7c83605f5116ed1a5421a1e8afeeba346f50d
BLAKE2b-256 checksum
How to use checksums
03b6ee06f37fdc8cff690cbc8f72905c906fa38b19f9d21668f886cd82dd5f6a
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.5.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.

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