Skip to content

AsyncAPI#

FastStream generates an AsyncAPI document of the service. Subscribers appear with their subscription and topic, publishers with their topic.

service.py
from faststream import FastStream

from faststream_gcp_pubsub import PubSubBroker

broker = PubSubBroker(
    project_id="my-project",
    description="Orders of the shop",
)
app = FastStream(broker)

shipments = broker.publisher("shipments", description="Orders ready to ship")


@broker.subscriber("orders-billing", topic="orders", description="Bills an order")
@shipments
async def bill(order: dict[str, int]) -> dict[str, int]:
    return {"order_id": order["id"]}

Serve the document in the browser:

faststream docs serve service:app

Write it to a file:

faststream docs gen service:app

title, description and include_in_schema of subscribers and publishers set the text of the operations. The broker's description, tags, specification_url and protocol set the server entry. The server entry carries the coordinate the broker connects to and never credentials.