AsgiFastStream
faststream.asgi.app.AsgiFastStream #
AsgiFastStream(
*brokers: BrokerUsecase[Any, Any, Any],
asgi_routes: Sequence[tuple[str, ASGIApp]] = (),
logger: Optional[LoggerProto] = logger,
provider: Provider | None = None,
serializer: Optional[SerializerProto] = EMPTY,
context: ContextRepo | None = None,
lifespan: Optional[Lifespan] = None,
on_startup: Sequence[AnyCallable] = (),
after_startup: Sequence[AnyCallable] = (),
on_shutdown: Sequence[AnyCallable] = (),
after_shutdown: Sequence[AnyCallable] = (),
specification: Optional[SpecificationFactory] = None,
asyncapi_path: str | AsyncAPIRoute | None = None,
)
Bases: Application
Source code in faststream/asgi/app.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
lifespan_context instance-attribute #
lifespan_context = apply_types(
func=lifespan,
serializer_cls=self.config._serializer,
cast_result=False,
context__=self.context,
)
from_app classmethod #
from_app(
app: Application,
asgi_routes: Sequence[tuple[str, ASGIApp]],
asyncapi_path: str | AsyncAPIRoute | None = None,
) -> Self
Source code in faststream/asgi/app.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
mount #
mount(path: str, route: ASGIApp) -> None
Source code in faststream/asgi/app.py
189 190 191 192 | |
run async #
run(
log_level: int = INFO,
run_extra_options: dict[str, SettingField]
| None = None,
) -> None
Source code in faststream/asgi/app.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
exit #
exit() -> None
Manual stop method.
Source code in faststream/asgi/app.py
245 246 247 | |
start_lifespan_context async #
start_lifespan_context(
run_extra_options: dict[str, SettingField]
| None = None,
) -> AsyncGenerator[None, None]
Source code in faststream/asgi/app.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
lifespan async #
lifespan(
scope: Scope, receive: Receive, send: Send
) -> None
Handle ASGI lifespan messages to start and shutdown the app.
Source code in faststream/asgi/app.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
not_found async #
not_found(
scope: Scope, receive: Receive, send: Send
) -> None
Source code in faststream/asgi/app.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
set_broker #
set_broker(broker: BrokerUsecase[Any, Any, Any]) -> None
Set already existed App object broker.
Useful then you create/init broker in on_startup hook.
Source code in faststream/_internal/application.py
108 109 110 111 112 113 114 115 116 | |
add_broker #
add_broker(broker: BrokerUsecase[Any, Any, Any]) -> None
Source code in faststream/_internal/application.py
118 119 120 121 122 123 124 125 | |
start async #
start(**run_extra_options: SettingField) -> None
Executes startup hooks and start broker.
Source code in faststream/_internal/application.py
219 220 221 222 223 224 225 | |
stop async #
stop() -> None
Executes shutdown hooks and stop broker.
Source code in faststream/_internal/application.py
268 269 270 271 272 | |
on_startup #
on_startup(
func: Callable[P_HookParams, T_HookReturn],
) -> Callable[P_HookParams, T_HookReturn]
Add hook running BEFORE broker connected.
This hook also takes an extra CLI options as a kwargs.
Source code in faststream/_internal/application.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
on_shutdown #
on_shutdown(
func: Callable[P_HookParams, T_HookReturn],
) -> Callable[P_HookParams, T_HookReturn]
Add hook running BEFORE broker disconnected.
Source code in faststream/_internal/application.py
321 322 323 324 325 326 327 328 329 330 331 332 333 | |
after_startup #
after_startup(
func: Callable[P_HookParams, T_HookReturn],
) -> Callable[P_HookParams, T_HookReturn]
Add hook running AFTER broker connected.
Source code in faststream/_internal/application.py
335 336 337 338 339 340 341 342 343 344 345 346 347 | |
after_shutdown #
after_shutdown(
func: Callable[P_HookParams, T_HookReturn],
) -> Callable[P_HookParams, T_HookReturn]
Add hook running AFTER broker disconnected.
Source code in faststream/_internal/application.py
349 350 351 352 353 354 355 356 357 358 359 360 361 | |