Application
AIOBoot uses an application class Application
that contains modules and other components.
Initialize and run as web application:
from aioboot.applications import Application app = Application() if __name__ == "__main__": app.run()
Initialize and run as CLI application:
from aioboot.applications import Application app = Application() if __name__ == "__main__": app.main()
Instantiating the application
class
aioboot.applications.Application
(debug=False, middleware=None, modules=None, auto_bind=False)Creates an application instance.
Parameters:
- debug - Debug exception traceback.
- modules - A list of modules to use when class
Application
is initialized. - auto_bing - Whether to automatically bind missing types.
Using lifespan events
from aioboot.applications import Application async def startup(): print("app: STARTUP") async def shutdown(): print("app: SHUTDOWN") app = Application() app.add_startup_event(startup) app.add_shutdown_event(shutdown) if __name__ == "__main__": app.main()
Or, using with decorators:
from aioboot.applications import Application app = Application() @app.on_startup() async def startup(): print("app: STARTUP") @app.on_shutdown() async def shutdown(): print("app: SHUTDOWN") if __name__ == "__main__": app.main()
Run and stop application:
$ python app.py
Output:
INFO: Started server process [1271] INFO: Uvicorn running on http://localhost:8000 (Press CTRL+C to quit) INFO: Waiting for application startup. app: STARTUP INFO: Application startup complete. ^CINFO: Shutting down INFO: Waiting for application shutdown. app: SHUTDOWN INFO: Application shutdown complete. INFO: Finished server process [1271]