FastAPI Instrumentation
FastAPI is a popular Python web framework developed by tiangolo.
The offering brands itself as
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints.
FastAPI plays very nicely with Fern because it has the power to output OpenAPI Specifications! Below we’ll outline some tips for generating a rich OpenAPI with FastAPI.
OpenAPI generation
By default, FastAPI will generate an OpenAPI Specification for you based on your routes and your data models! You can access this spec by visiting /docs
on your FastAPI server.
If you are not seeing any OpenAPI Specification (or the Swagger UI), you may need to review your FastAPI server configuration as the path may have been changed, or completely omitted.
Specifying servers
Fern will automatically generate clients that point to the servers you configure within your OpenAPI Specification, so it’s important to specify the servers that your API will be hosted on.
OpenAPI extensions
FastAPI allows you to add in extra OpenAPI configuration directly within your route, through the use of the openapi_extra
parameter.
Below, we’ve annotated a “good” route within FastAPI that has it’s typings as well as Fern extensions to assist in naming.
Specifying examples
FastAPI allows you to specify examples for your data models, which Fern will pick up and use within your generated SDKs and documentation automatically.
For more information on leveraging examples within Fern, please refer to the Fern documentation.
For more information on this FastAPI functionality, please refer to the FastAPI documentation.
Additional customization
FastAPI has a lot of flexibility in how you can customize your OpenAPI Specification. Please refer to the FastAPI documentation for more information.