Skip to content

Pluggable class

This is the reference for the wrapper object Pluggable that contains all the parameters, attributes and functions. It wraps an Extension.

esmerald.Pluggable

Pluggable(cls, **options)

The Pluggable is a wrapper around an Extension to initialize it lazily.

Read more about the Pluggables and learn how to use them.

Example

from typing import Optional

from loguru import logger
from pydantic import BaseModel

from esmerald import Esmerald, Extension, Pluggable
from esmerald.types import DictAny


class PluggableConfig(BaseModel):
    name: str


class MyExtension(Extension):
    def __init__(
        self,
        app: Optional["Esmerald"] = None,
        config: PluggableConfig = None,
        **kwargs: "DictAny",
    ):
        super().__init__(app, **kwargs)

    def extend(self, config: PluggableConfig) -> None:
        logger.success(f"Successfully passed a config {config.name}")


my_config = PluggableConfig(name="my extension")

pluggable = Pluggable(MyExtension, config=my_config)

app = Esmerald(routes=[], extensions={"my-extension": pluggable})
PARAMETER DESCRIPTION
cls

TYPE: type[ExtensionProtocol]

**options

TYPE: Any DEFAULT: {}

Source code in esmerald/pluggables/base.py
57
58
59
def __init__(self, cls: type["ExtensionProtocol"], **options: Any):
    self.cls = cls
    self.options = options

cls instance-attribute

cls = cls

options instance-attribute

options = options