FastAPI Plugin for FastStream
A plugin that allows you to use Depends and FastAPI other objects in the FastStream
Features
Use FastAPI Dependency Injection
In FastStream handlers, it will be possible to use the familiar DI from FastAPI
from fastapi import Path, Body, Header, Depends
class BodyModel(BaseModel):
field: int
@broker.subscriber("subject.{num}")
async def subscriber_handler(
num: Annotated[int, Path()],
body: Annotated[BodyModel, Body()],
x_user_id: Annotated[int, Header()],
my_dep: Annotated[int, Depends(int)],
) -> None:
...
Сan use FastAPI dependency overrides
fastapi = FastAPI()
fastapi.dependency_overrides[Dep] = lambda: "Dep"
@broker.subscriber("subject")
async def subscriber(dep: Annotated[str, De[]]) -> None:
assert dep == "Dep"
Using the FastStream Context
from faststream import Context
@broker.subscriber("subject")
async def subscriber_handler(context_data: Annotated[int, Context("data")]) -> Response: ...
Use FastAPI Request and Response
from fastapi import Request, Response
from fastapi.responses import JSONResponse
@broker.subscriber("subject")
async def subscriber_handler(request: Request) -> Response:
return JSONResponse({"data": 1})
Minimalistic plugin connection to your application
All you need to do is wrap the FastAPI with the FastStreamAPI object from the plugin
application = FastStreamAPI(
NatsBroker(),
application=FastAPI(),
)
uvicorn.run(application)
Managing a lifespan state
Now the lifespan state is also available in FastStream handlers
@asynccontextmanager
async def lifespan(app: FastAPI):
yield {"lifespan_data": "LIFESPAN DATA"}
@broker.subscriber("subject")
async def subscriber(request: Request) -> None:
assert request.state.lifespan_data == "LIFESPAN DATA"
The ability to configure AsyncAPI
The ability to configure AsyncAPI using SpecificationFactory from FastStream and AsyncAPIConfig from the plugin
FastStreamAPI(
...,
specification=AsyncAPI(
title="My app",
version="1.0.0",
description="...",
...,
),
asyncapi_path="/fs_docs",
# or
asyncapi_path=AsyncAPIRouter(
"/fs_docs",
description="...",
...
),
)
Backgrounds tasks
You can use BackgroundTasks from FastAPI in FastStream handlers
@broker.subscriber("subject")
async def handler1(
tasks: BackgroundTasks,
) -> None:
tasks.add_task(...)
Metadata
Release files for faststream_fastapi 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| faststream_fastapi-1.4.0.tar.gz | 12.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| faststream_fastapi-1.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.6 kB
Release files / faststream_fastapi-1.4.0.tar.gz
| Download URL | faststream_fastapi-1.4.0.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd1fad0d8ce3846f1f26eb4e0fd2eed6d878d51d78b4112d6375402d24985599
|
|
BLAKE2b-256 checksum How to use checksums |
0e80fc244a37a6d453d126862c58e2571bacb3b29b3cdaf2056bdcd89fb21d4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.
Transparency logRelease files / faststream_fastapi-1.4.0-py3-none-any.whl
| Download URL | faststream_fastapi-1.4.0-py3-none-any.whl |
|---|---|
| Size | 20.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
825f3ac86217dfdeb603b68b513ac98b818e18efa5de63b73a902196c42ffbab
|
|
BLAKE2b-256 checksum How to use checksums |
59ea379cbe571524bd2415e721c9b9bd0cb10a949a4be88b2862ce21c3255966
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.
Transparency log