FastStream
faststream.app.FastStream #
FastStream(broker: Optional[BrokerAsyncUsecase[Any, Any]] = None, logger: Optional[Logger] = logger, lifespan: Optional[Lifespan] = None, title: str = 'FastStream', version: str = '0.1.0', description: str = '', terms_of_service: Optional[AnyHttpUrl] = None, license: Optional[Union[License, LicenseDict, AnyDict]] = None, contact: Optional[Union[Contact, ContactDict, AnyDict]] = None, identifier: Optional[str] = None, tags: Optional[Sequence[Union[Tag, TagDict, AnyDict]]] = None, external_docs: Optional[Union[ExternalDocs, ExternalDocsDict, AnyDict]] = None)
Bases: ABCApp
A class representing a FastStream application.
METHOD | DESCRIPTION |
---|---|
__init__ | initializes the FastStream application |
on_startup | adds a hook to run before the broker is connected |
on_shutdown | adds a hook to run before the broker is disconnected |
after_startup | adds a hook to run after the broker is connected |
after_shutdown | adds a hook to run after the broker is disconnected |
run | runs the FastStream application |
_start | starts the FastStream application |
_stop | stops the FastStream application |
_startup | runs the startup hooks |
_shutdown | runs the shutdown hooks |
__exit | exits the FastStream application |
Asynchronous FastStream Application class.
stores and run broker, control hooks
PARAMETER | DESCRIPTION |
---|---|
broker | async broker to run (may be TYPE: |
logger | logger object to log startup/shutdown messages ( |
lifespan | lifespan context to run application TYPE: |
title | application title - for AsyncAPI docs TYPE: |
version | application version - for AsyncAPI docs TYPE: |
description | application description - for AsyncAPI docs TYPE: |
terms_of_service | application terms of service - for AsyncAPI docs TYPE: |
license | application license - for AsyncAPI docs TYPE: |
contact | application contact - for AsyncAPI docs TYPE: |
identifier | application identifier - for AsyncAPI docs |
tags | application tags - for AsyncAPI docs TYPE: |
external_docs | application external docs - for AsyncAPI docs TYPE: |
Source code in faststream/app.py
lifespan_context instance-attribute
#
lifespan_context = apply_types(func=lifespan, wrap_model=drop_response_type) if lifespan is not None else fake_context
after_shutdown #
Add hook running AFTER broker disconnected.
PARAMETER | DESCRIPTION |
---|---|
func | async or sync func to call as a hook TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable[P_HookParams, T_HookReturn] | Async version of the func argument |
Source code in faststream/app.py
after_startup #
Add hook running AFTER broker connected.
PARAMETER | DESCRIPTION |
---|---|
func | async or sync func to call as a hook TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable[P_HookParams, T_HookReturn] | Async version of the func argument |
Source code in faststream/app.py
on_shutdown #
Add hook running BEFORE broker disconnected.
PARAMETER | DESCRIPTION |
---|---|
func | async or sync func to call as a hook TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable[P_HookParams, T_HookReturn] | Async version of the func argument |
Source code in faststream/app.py
on_startup #
Add hook running BEFORE broker connected.
This hook also takes an extra CLI options as a kwargs
PARAMETER | DESCRIPTION |
---|---|
func | async or sync func to call as a hook TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable[P_HookParams, T_HookReturn] | Async version of the func argument |
Source code in faststream/app.py
run async
#
run(log_level: int = logging.INFO, run_extra_options: Optional[Dict[str, SettingField]] = None) -> None
Run FastStream Application.
PARAMETER | DESCRIPTION |
---|---|
log_level | force application log level |
run_extra_options | extra options for running the app |
RETURNS | DESCRIPTION |
---|---|
None | Block an event loop until stopped |
Source code in faststream/app.py
set_broker #
set_broker(broker: BrokerAsyncUsecase[Any, Any]) -> None
Set already existed App object broker.
Useful then you create/init broker in on_startup
hook.