Skip to content

starlite_saqlalchemy

starlite-saqlalchemy

An implementation of a Starlite application configuration plugin.

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()])

ConfigureApp

ConfigureApp(config=PluginConfig())

Starlite application configuration.

Parameters:

Name Type Description Default
config PluginConfig

Provide a config object to customize the behavior of the plugin.

PluginConfig()

__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_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)

Adds the health check controller.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_logging

configure_logging(app_config)

Configures application logging if it has not already been configured.

Parameters:

Name Type Description Default
app_config AppConfig

The Starlite application config object.

required

configure_openapi

configure_openapi(app_config)

Configures the OpenAPI docs if they have not already been configured.

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_static_files

configure_static_files(app_config)

Configure static files for the application.

No-op if AppConfig.static_files_config is not None.

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_sqlalchemy_plugin class-attribute

do_sqlalchemy_plugin: bool = True

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

do_static_files class-attribute

do_static_files: bool = True

Set the static files config object to AppConfig.static_files_config.

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.

worker_functions class-attribute

worker_functions: list[WorkerFunction | tuple[str, WorkerFunction]] = []

Queue worker functions.