How to Generate and Serve AsyncAPI Documentation#
In this guide, let's explore how to generate and serve AsyncAPI documentation for our FastStream application.
Writing the FastStream Application#
Here's an example Python application using FastStream that consumes data from a topic, increments the value, and outputs the data to another topic. Save it in a file called basic.py.
| basic.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
Generating the AsyncAPI Specification#
Now that we have a FastStream application and specification object, we can proceed with generating the AsyncAPI specification using a CLI command.
faststream docs gen basic:app
The above command will generate the AsyncAPI specification and save it in a file called asyncapi.json.
If you prefer yaml instead of json, please run the following command to generate asyncapi.yaml.
faststream docs gen --yaml basic:app
Tip
To generate the documentation in yaml format, please install the necessary dependency to work with the YAML file format first.
pip install PyYAML