Modules¶
Modules are Python packages that provide additional services and handlers. They can be used to integrate external libraries into the framework.
During application startup, modules are scanned in order to find services and handlers declared in them.
Using modules¶
Modules need to be activated in settings.toml, in the modules property:
modules = [
"zayt_contrib.sqlalchemy",
"zayt_contrib.jinja",
]
Note
The application.py (or application package) is a module itself and is
loaded by default as the last module in the list, if it is not declared.
Dynamic services and handlers¶
Services and handlers can be registered dynamically in modules.
To do this, we just need to create function called init() and inject
it with zayt.di.Container or zayt.web.routing.Router.
from zayt import di, web
from zayt.web import routing
class SomeService:
...
async def some_handler(request):
...
def init(container: di.Container, router: routing.Router):
container.register(di.service(SomeService))
router.route(web.get("/")(some_handler))
zayt-contrib¶
zayt-contrib provides modules for common libraries like sqlalchemy, redis, memcached and jinja.