Skip to content

Extension class

This is the reference for the main object Extension. It is optionally wrapped by a Pluggable.

esmerald.Extension

Extension(app=None, **kwargs)

Bases: ABC, ExtensionProtocol

Extension object is the one being used to add the logic that will originate the pluggable in the application.

The Extension must implement the extend function.

Read more about the Extension and learn how to use it.

Example

from typing import Optional

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


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

    def extend(self, **kwargs: "DictAny") -> None:
        '''
        Function that should always be implemented when extending
        the Extension class or a `NotImplementedError` is raised.
        '''
        # Do something here
PARAMETER DESCRIPTION
app

An Esmerald application instance or subclasses of Esmerald.

TYPE: Optional[Esmerald] DEFAULT: None

**kwargs

Any additional kwargs needed.

TYPE: Any DEFAULT: {}

Source code in esmerald/pluggables/base.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def __init__(
    self,
    app: Annotated[
        Optional["Esmerald"],
        Doc(
            """
            An `Esmerald` application instance or subclasses of Esmerald.
            """
        ),
    ] = None,
    **kwargs: Annotated[
        Any,
        Doc("""Any additional kwargs needed."""),
    ],
):
    super().__init__()
    self.app = app

app instance-attribute

app = app

extend abstractmethod

extend(**kwargs)
PARAMETER DESCRIPTION
**kwargs

TYPE: Any DEFAULT: {}

Source code in esmerald/pluggables/base.py
122
123
124
@abstractmethod
def extend(self, **kwargs: Any) -> None:
    raise NotImplementedError("Extension must be implemented by the subclasses.")