Extensions
Extensions are python packages that provide additional functionality or integrate external libraries into the framework.
Current builtin extensions are:
- Databases
- Template engines
Activating extensions
Extensions need to be activated in settings.yaml
, in the extensions
property:
Creating extensions
An extension is a python package or module that contains a function named init_extension
with arguments selva.di.Container
and selva.configuration.Settings
. It is called
during the startup phase of the application and may also be a coroutine.
from selva.configuration import Settings
from selva.di import Container
async def init_extension(container: Container, settings: Settings):
pass
# # init_extension can also be sync
# def init_extension(container: Container, settings: Settings): ...
The function can then access values in the settings object, register new services, retrieve the router service to register new routes, etc.