Skip to content

Actions

mountaineer.actions.passthrough_dec.passthrough

passthrough(*args, **kwargs)

Only functions that are explicitly marked as actions will be accessable by the frontend. The @passthrough decorator indicates that this function should be called by the frontend and will return an explicit data payload. It will NOT update the render() state of the frontend.

Decorate functions within your ControllerBase that you want to expose. Each of these functions should specify a return type. Normal passthrough endpoints can return with either a None, a BaseModel object, or a JSONResponse if you need full flexibility on return headers and content structure.

If you do return a JSONResponse note that we will handle the merging of the response for you - so on the client side you will still access your endpoint contents with:

const response = await serverState.my_action({});
console.log(response.passthrough);

Usage:

from pydantic import BaseModel

class ResponseModel(BaseModel):
    pass

class MyController(ControllerBase):
    @passthrough
    async def my_action(self) -> ResponseModel:
        ...
PARAMETER DESCRIPTION
exception_models

List of APIException subclasses that this function is known to throw. These will be parsed and available to frontend clients.

TYPE: list[Type[APIException]] | None

raw_response

If specified, you can return a generic fastapi.Response object. There's no constraint this endpoint returns JSON - you can return html or a custom protocol. This lets you treat this API as a generic POST endpoint for you to fully control the output.

TYPE: bool

RETURNS DESCRIPTION
BaseModel | None | fastapi.JSONResponse

The response model to use for this endpoint. If a BaseModel is not provided (you pass a dictionary or a SQLModel object ofr instance), we will try to convert the response object into the proper JSON response based on your typehint.

mountaineer.actions.sideeffect_dec.sideeffect

sideeffect(*args, **kwargs)

Mark a function as causing a sideeffect to the data. This will force a reload of the full (or partial) server state and sync these changes down to the client page.

Like passthroughs, @sideeffect accepts return values of None, BaseModel, or a JSONResponse if you need full flexibility on return headers and content structure. Unlike @passthrough, it does not allow you to provide a non-JSON response since we need to internally merge it with render() sideeffect update.

PARAMETER DESCRIPTION
exception_models

List of APIException subclasses that this function is known to throw. These will be parsed and available to frontend clients.

TYPE: list[Type[APIException]] | None

reload

If provided, will ONLY reload these fields on the client side. By default will reload all fields. Otherwise, why specify a sideeffect at all? Note that even if this is provided, we will still regenerate a fully full state on the server as if render() is called again. This parameter only controls the data that is streamed back to the client in order to help reduce bandwidth of data that won't be changed.

TYPE: tuple[FieldClassDefinition, ...] | None

experimental_render_reload

Experimental options. Disabled by default.

If True, will attempt to only execute the logic in render() that is required to calculate your reload parameters. Other logic will be short-circuited. If your render function has significant computation for other properties this can be a significant performance improvement. However, it is experimental and may not work in all cases.

TYPE: bool

RETURNS DESCRIPTION
BaseModel | None | fastapi.JSONResponse

The response model to use for this endpoint. If a BaseModel is not provided (you pass a dictionary or a SQLModel object ofr instance), we will try to convert the response object into the proper JSON response based on your typehint.