Перейти к содержанию

Pluggable class

Warning

The current page still doesn't have a translation for this language.

But you can help translating it: Contributing.

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)
# or
# pluggable = Pluggable("path.to.MyExtension", config=my_config)

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

TYPE: type[ExtensionProtocol] | str

**options

TYPE: Any DEFAULT: {}

Source code in esmerald/pluggables/base.py
62
63
64
def __init__(self, cls: type[ExtensionProtocol] | str, **options: Any):
    self.cls_or_string = cls
    self.options = options

cls_or_string instance-attribute

cls_or_string = cls

options instance-attribute

options = options

cls property

cls