Standalone Applications

Not every program that wants your modules wants an HTTP server: a CLI command, a queue worker, a one-off data migration. create_application_context() builds the module graph and runs the lifecycle hooks without FastAPI:

import asyncio
 
from austial import AustialFactory
 
from src.app.app_module import AppModule
from src.app.modules.reports.reports_service import ReportsService
 
 
async def main() -> None:
    ctx = await AustialFactory.create_application_context(AppModule)
    try:
        await ctx.get(ReportsService).run_nightly()
    finally:
        await ctx.close()
 
 
asyncio.run(main())

The returned AustialApplicationContext has:

MemberDoes
get(token)Resolves a provider (the same as app.get).
resolve(token, context_id=None)Resolves a provider of any scope, including request-scoped.
init()Runs the initialization hooks. Already done by create_application_context(); idempotent.
close(signal=None)Runs the termination hooks.
enable_shutdown_hooks(*signals)Closes the context on SIGTERM / SIGINT (or the signals you name).

AustialApplication, what AustialFactory.create() returns, extends this class, so everything above also works on a web application.