Skip to content

init_plugin

The application configuration plugin and config object.

Example
from starlite import Starlite, get

from starlite_saqlalchemy import ConfigureApp


@get("/example")
def example_handler() -> dict:
    return {"hello": "world"}


app = Starlite(route_handlers=[example_handler], on_app_init=[ConfigureApp()])

The plugin can be configured by passing an instance of PluginConfig to ConfigureApp on

instantiation
app = Starlite(
    route_handlers=[example_handler],
    on_app_init[ConfigureApp(PluginConfig(do_openapi=False))],
)

The PluginConfig has switches to disable every aspect of the plugin behavior.

ConfigureApp

ConfigureApp(config=PluginConfig())

Starlite application configuration.

__call__

__call__(app_config)

Entrypoint to the app config plugin.

Receives the AppConfig object and modifies it.

Parameters:

Name Type Description Default
app_config AppConfig

Passed to the plugin from the Starlite instance on instantiation.

required

Returns:

Type Description
AppConfig

The modified AppConfig object.

configure_after_exception

configure_after_exception(app_config)

Add the logging after exception hook handler.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_cache

configure_cache(app_config)

Configure the application cache.

We only overwrite if DEFAULT_CACHE_CONFIG is the standing configuration object.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_collection_dependencies

configure_collection_dependencies(app_config)

Add the required Provide instances to the app dependency mapping.

If a dependency has already been provided with the same key we do not overwrite it.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_compression

configure_compression(app_config)

Configure application compression.

No-op if AppConfig.compression_config has already been set.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_debug

configure_debug(app_config)

Set Starlite's debug parameter.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_exception_handlers

configure_exception_handlers(app_config)

Add the handlers that translate service and repository exceptions into HTTP exceptions.

Does not overwrite handlers that may already exist for the exception types.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_health_check

configure_health_check(app_config)

Add health check controller.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_logging

configure_logging(app_config)

Configure application logging.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_openapi

configure_openapi(app_config)

Configure the OpenAPI docs.

We only overwrite if DEFAULT_OPENAPI_CONFIG is the standing configuration.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_response_class

configure_response_class(app_config)

Add the custom response class.

No-op if the AppConfig.response_class is not None.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_sentry

configure_sentry(app_config)

Add handler to configure Sentry integration.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_sqlalchemy_plugin

configure_sqlalchemy_plugin(app_config)

Configure SQLAlchemy for the application.

Adds a configured SQLAlchemyPlugin to AppConfig.plugins.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_worker

configure_worker(app_config)

Configure the SAQ async worker.

No-op if there are no worker functions set on PluginConfig.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

PluginConfig

Bases: BaseModel

Configure behavior of the ConfigureApp object.

Each feature that the plugin enables can be toggled with the do_<behavior> switch, e.g., PluginConfig(do_after_exception=False) will tell ConfigureApp not to add the after exception logging hook handler to the application.

do_after_exception class-attribute

do_after_exception: bool = True

Add the hook handler to AppConfig.after_exception.

do_cache class-attribute

do_cache: bool = True

Add configuration for the redis-backed cache to AppConfig.cache_config.

do_collection_dependencies class-attribute

do_collection_dependencies = True

Add the Provide's for collection route dependencies to AppConfig.dependencies.

do_compression class-attribute

do_compression: bool = True

Add configuration for gzip compression to AppConfig.compression_config.

do_exception_handlers class-attribute

do_exception_handlers: bool = True

Add the repository/service exception http translation handlers to AppConfig.exception_handlers.

do_health_check class-attribute

do_health_check: bool = True

Add the health check controller to AppConfig.route_handlers.

do_logging class-attribute

do_logging: bool = True

Set the logging configuration object to AppConfig.logging_config.

do_openapi class-attribute

do_openapi: bool = True

Set the OpenAPI config object to AppConfig.openapi_config.

do_response_class class-attribute

do_response_class: bool = True

Set the custom response class to AppConfig.response_class.

do_sentry class-attribute

do_sentry: bool = True

Configure the application to initialize Sentry on startup. Adds a handler to AppConfig.on_startup.

do_set_debug class-attribute

do_set_debug: bool = True

Allow the plugin to set the starlite debug parameter. Parameter set to value of [AppConfig.debug][starlite_saqlalchemy.settings.AppConfig.debug].

do_sqlalchemy_plugin class-attribute

do_sqlalchemy_plugin: bool = True

Set the SQLAlchemy plugin on the application. Adds the plugin to AppConfig.plugins.

do_worker class-attribute

do_worker: bool = True

Configure the async worker on the application. This action instantiates a worker instance and sets handlers for AppConfig.on_startup and AppConfig.on_shutdown that manage the lifecycle of the SAQ worker.

log_processors class-attribute

log_processors: Sequence[Processor] = log.default_processors

Chain of structlog log processors.

serializer class-attribute

serializer: Callable[[Any], Any] = default_serializer

The serializer callable that is used by the custom Response class that is created. If AppConfig.response_class is not None, this is ignored. If PluginConfig.do_response_class is False, this is ignored.

worker_functions class-attribute

worker_functions: list[Callable[..., Any] | tuple[str, Callable[..., Any]]] = [
    (make_service_callback.__qualname__, make_service_callback)
]

Queue worker functions.