Skip to content

Controllers API

The Chartlets controllers API is used by application providers only. As an application contributor you do not need to care about it.

A controller implements the logic of a specific Chartlets web API endpoint. It is used to efficiently implement the Chartlets web API using any web framework such as FastAPI, Flask or Tornado.

Controllers are imported from the chartlets.components module, for example:

from chartlets.controllers import get_layout

chartlets.controllers.get_contributions(ext_ctx)

Generate the response for the endpoint GET /chartlets/contributions.

Parameters:

Name Type Description Default
ext_ctx ExtensionContext | None

Extension context. If None, the function returns a 404 error response.

required

Returns: A Response object. On success, the response is a dictionary that represents a JSON-serialized component tree.

chartlets.controllers.get_layout(ext_ctx, contrib_point_name, contrib_index, data)

Generate the response for the endpoint POST /chartlets/layout/{contrib_point_name}/{contrib_index}.

Parameters:

Name Type Description Default
ext_ctx ExtensionContext | None

Extension context. If None, the function returns a 404 error response.

required
contrib_point_name str

Contribution point name.

required
contrib_index int

Contribution index.

required
data dict[str, Any]

A dictionary deserialized from a request JSON body that may contain a key inputValues of type list.

required

Returns: A Response object. On success, the response is a dictionary that represents a JSON-serialized component tree.

chartlets.controllers.get_callback_results(ext_ctx, data)

Generate the response for the endpoint POST /chartlets/callback.

Parameters:

Name Type Description Default
ext_ctx ExtensionContext | None

Extension context. If None, the function returns a 404 error response.

required
data dict[str, Any]

A dictionary deserialized from a request JSON body that should contain a key callbackRequests of type list.

required

Returns: A Response object. On success, the response is a list of state-change requests grouped by contributions.

chartlets.ExtensionContext

load(app_ctx, extension_refs) classmethod

Create a new extension context from the given application context and list of extension references.

Parameters:

Name Type Description Default
app_ctx Any

Application context object passed to a contribution's layout factory and callback functions.

required
extension_refs list[str]

Extension references where each item must have the form "module.attribute".

required

Returns: A new extension context.

chartlets.Response