Plugins System
Base Petal
- class petal_app_manager.plugins.base.Petal[source]
Bases:
ABCPetal authors only inherit this; NO FastAPI import, no routers.
- async async_shutdown() None[source]
Called before shutdown to handle async operations like MQTT unsubscriptions.
- async async_startup() None[source]
Called after startup to handle async operations like MQTT subscriptions.
Decorators
- petal_app_manager.plugins.decorators.http_action(method: Literal['GET', 'POST'], path: str, **kwargs)[source]
Marks a petal method as an HTTP endpoint.
- petal_app_manager.plugins.decorators.mqtt_action(command: str, *, cpu_heavy: bool = False, **kwargs)[source]
Marks a petal method as an MQTT command handler.
The decorated method must be
async defand accept(self, topic: str, message: dict)—exactly the same signature that the legacy_command_handlersdict values have today.- Parameters:
command (str) – The suffix of the MQTT command, for example
"mission_plan"or"fetch_flight_records". At runtime the framework prefixes the petal’snameattribute automatically, producing"petal-leafsdk/mission_plan"etc.cpu_heavy (bool) – If
Truethe entire handler invocation will be offloaded to the proxy’s thread-pool executor so CPU-intensive work (e.g. NumPy) does not block the event loop. Defaults toFalse.
Loader
- petal_app_manager.plugins.loader.initialize_petals(petal_name_list: List[str], proxies: Dict[str, BaseProxy], logger: Logger) List[Petal][source]
Initialize petals without starting them up. Loads petal classes, instantiates them, and injects proxies. Does NOT call petal.startup().
Returns a list of initialized (but not started) Petal objects.
- petal_app_manager.plugins.loader.load_petals(app: FastAPI, petal_name_list: List[str], proxies: Dict[str, BaseProxy], logger: Logger) List[Petal][source]
Load, initialize, and start petals (convenience function). This is a wrapper that calls initialize_petals() and startup_petals().
For more control over the initialization and startup process, use initialize_petals() and startup_petals() separately.
- petal_app_manager.plugins.loader.startup_petals(app: FastAPI, petal_list: List[Petal], logger: Logger) List[Petal][source]
Start up initialized petals and mount them to the FastAPI app. Calls petal.startup() and mounts static files, templates, and routers.
Returns the list of successfully started petals.