Skip to content

SimpleJWTExtension class

esmerald_simple_jwt.extension.SimpleJWTExtension

SimpleJWTExtension(app=None, **kwargs)

Bases: Extension

The pluggable version of Esmerald Simple JWT.

This Pluggable can and should be used if you want to add the package independently as a ChilEsmerald.

Example

from esmerald import Esmerald, Pluggable
from esmerald_simple_jwt.extension import SimpleJWTExtension


app = Esmerald(
    pluggables={
        "simple-jwt": Pluggable(SimpleJWTExtension, path="/auth"),
    },
)
PARAMETER DESCRIPTION
app

TYPE: Optional[Esmerald] DEFAULT: None

**kwargs

TYPE: Any DEFAULT: {}

Source code in esmerald_simple_jwt/extension.py
38
39
40
41
def __init__(self, app: Optional["Esmerald"] = None, **kwargs: Any):
    super().__init__(app, **kwargs)
    self.app = app
    self.kwargs = kwargs

app instance-attribute

app = app

kwargs instance-attribute

kwargs = kwargs

extend

extend(path='/simple-jwt', name=None, settings_module=None, middleware=None, dependencies=None, exception_handlers=None, interceptors=None, permissions=None, include_in_schema=True, enable_openapi=True)

The extend() default from the Pluggable interface allowing to pass extra parameters to the initialisation.

Example

from esmerald import Esmerald, Pluggable
from esmerald_simple_jwt.extension import SimpleJWTExtension


app = Esmerald(
    pluggables={
        "simple-jwt": Pluggable(
            SimpleJWTExtension,
            path="/auth",
            settings_module=...,
            middleware=...,
            permissions=...,
            interceptors=...,
        ),
    },
)
PARAMETER DESCRIPTION
path

Relative path of the Plugable. The path can contain parameters in a dictionary like format and if the path is not provided, it will default to /.

Example

Pluugable(SimpleJWTExtension, path="/{age: int}"))

TYPE: Optional[str] DEFAULT: '/simple-jwt'

name

The name for the Gateway. The name can be reversed by url_path_for().

TYPE: Optional[str] DEFAULT: None

settings_module

Alternative settings parameter. This parameter is an alternative to ESMERALD_SETTINGS_MODULE way of loading your settings into an Esmerald application.

When the settings_module is provided, it will make sure it takes priority over any other settings provided for the instance.

Read more about the settings module and how you can leverage it in your application.

Tip

The settings module can be very useful if you want to have, for example, a ChildEsmerald that needs completely different settings from the main app.

Example: A ChildEsmerald that takes care of the authentication into a cloud provider such as AWS and handles the boto3 module.

TYPE: Optional[SettingsType] DEFAULT: None

middleware

A list of middleware to run for every request. The middlewares of a Gateway will be checked from top-down or Starlette Middleware as they are both converted internally. Read more about Python Protocols.

TYPE: Optional[Sequence[Middleware]] DEFAULT: None

dependencies

A dictionary of string and Inject instances enable application level dependency injection.

TYPE: Optional[Dependencies] DEFAULT: None

exception_handlers

A dictionary of exception types (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of handler(request, exc) -> response and may be be either standard functions, or async functions.

TYPE: Optional[ExceptionHandlerMap] DEFAULT: None

interceptors

A list of interceptors to serve the application incoming requests (HTTP and Websockets).

TYPE: Optional[List[Interceptor]] DEFAULT: None

permissions

A list of permissions to serve the application incoming requests (HTTP and Websockets).

TYPE: Optional[List[Permission]] DEFAULT: None

include_in_schema

Boolean flag indicating if it should be added to the OpenAPI docs.

TYPE: Optional[bool] DEFAULT: True

enable_openapi

Boolean flag indicating if the OpenAPI documentation should be generated or not.

When False, no OpenAPI documentation is accessible.

Tip

Disable this option if you run in production and no one should access the documentation unless behind an authentication.

```

TYPE: Optional[bool] DEFAULT: True

Source code in esmerald_simple_jwt/extension.py
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def extend(
    self,
    path: Annotated[
        Optional[str],
        Doc(
            """
            Relative path of the Plugable.
            The path can contain parameters in a dictionary like format
            and if the path is not provided, it will default to `/`.

            **Example**

            ```python
            Pluugable(SimpleJWTExtension, path="/{age: int}"))
            ```
            """
        ),
    ] = "/simple-jwt",
    name: Annotated[
        Optional[str],
        Doc(
            """
            The name for the Gateway. The name can be reversed by `url_path_for()`.
            """
        ),
    ] = None,
    settings_module: Annotated[
        Optional["SettingsType"],
        Doc(
            """
            Alternative settings parameter. This parameter is an alternative to
            `ESMERALD_SETTINGS_MODULE` way of loading your settings into an Esmerald application.

            When the `settings_module` is provided, it will make sure it takes priority over
            any other settings provided for the instance.

            Read more about the [settings module](https://esmerald.dev/application/settings/)
            and how you can leverage it in your application.

            !!! Tip
                The settings module can be very useful if you want to have, for example, a
                [ChildEsmerald](https://esmerald.dev/routing/router/?h=childe#child-esmerald-application) that needs completely different settings
                from the main app.

                Example: A `ChildEsmerald` that takes care of the authentication into a cloud
                provider such as AWS and handles the `boto3` module.
            """
        ),
    ] = None,
    middleware: Annotated[
        Optional[Sequence["Middleware"]],
        Doc(
            """
            A list of middleware to run for every request. The middlewares of a Gateway will be checked from top-down or [Starlette Middleware](https://www.starlette.io/middleware/) as they are both converted internally. Read more about [Python Protocols](https://peps.python.org/pep-0544/).
            """
        ),
    ] = None,
    dependencies: Annotated[
        Optional["Dependencies"],
        Doc(
            """
            A dictionary of string and [Inject](https://esmerald.dev/dependencies/) instances enable application level dependency injection.
            """
        ),
    ] = None,
    exception_handlers: Annotated[
        Optional["ExceptionHandlerMap"],
        Doc(
            """
            A dictionary of [exception types](https://esmerald.dev/exceptions/) (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of `handler(request, exc) -> response` and may be be either standard functions, or async functions.
            """
        ),
    ] = None,
    interceptors: Annotated[
        Optional[List["Interceptor"]],
        Doc(
            """
            A list of [interceptors](https://esmerald.dev/interceptors/) to serve the application incoming requests (HTTP and Websockets).
            """
        ),
    ] = None,
    permissions: Annotated[
        Optional[List["Permission"]],
        Doc(
            """
            A list of [permissions](https://esmerald.dev/permissions/) to serve the application incoming requests (HTTP and Websockets).
            """
        ),
    ] = None,
    include_in_schema: Annotated[
        Optional[bool],
        Doc(
            """
            Boolean flag indicating if it should be added to the OpenAPI docs.
            """
        ),
    ] = True,
    enable_openapi: Annotated[
        Optional[bool],
        Doc(
            """
            Boolean flag indicating if the OpenAPI documentation should
            be generated or not.

            When `False`, no OpenAPI documentation is accessible.

            !!! Tip
                Disable this option if you run in production and no one should access the
                documentation unless behind an authentication.
            ```
            """
        ),
    ] = True,
) -> None:
    """
    The extend() default from the Pluggable interface allowing to pass extra parameters
    to the initialisation.

    **Example**

    ```python
    from esmerald import Esmerald, Pluggable
    from esmerald_simple_jwt.extension import SimpleJWTExtension


    app = Esmerald(
        pluggables={
            "simple-jwt": Pluggable(
                SimpleJWTExtension,
                path="/auth",
                settings_module=...,
                middleware=...,
                permissions=...,
                interceptors=...,
            ),
        },
    )

    ```
    """
    simple_jwt = ChildEsmerald(
        routes=[
            Include(namespace="esmerald_simple_jwt.urls"),
        ],
        middleware=middleware,
        dependencies=dependencies,
        exception_handlers=exception_handlers,
        interceptors=interceptors,
        permissions=permissions,
        include_in_schema=include_in_schema,
        enable_openapi=enable_openapi,
        settings_module=settings_module,
    )
    self.app.add_child_esmerald(
        path=path,
        child=simple_jwt,
        name=name,
        include_in_schema=include_in_schema,
    )