Interactive API documentation and exploration web user interfaces. As the framework is based on OpenAPI, there are multiple options, 2 included by default.
Swagger UI, with interactive exploration, call and test your API directly from the browser.
It's all based on standard Python 3.6 type declarations (thanks to Pydantic). No new syntax to learn. Just standard modern Python.
If you need a 2 minute refresher of how to use Python types (even if you don't use FastAPI), check the short tutorial: Python Types.
You write standard Python with types:
fromdatetimeimportdatefrompydanticimportBaseModel# Declare a variable as a str# and get editor support inside the functiondefmain(user_id:str):returnuser_id# A Pydantic modelclassUser(BaseModel):id:intname:strjoined:date
All the framework was designed to be easy and intuitive to use, all the decisions were tested on multiple editors even before starting development, to ensure the best development experience.
You will get completion in code you might even consider impossible before. As for example, the price key inside a JSON body (that could have been nested) that comes from a request.
No more typing the wrong key names, coming back and forth between docs, or scrolling up and down to find if you finally used username or user_name.
It has sensible defaults for everything, with optional configurations everywhere. All the parameters can be fine-tuned to do what you need and to define the API you need.
Or in other way, no need for them, import and use the code you need.
Any integration is designed to be so simple to use (with dependencies) that you can create a "plug-in" for your application in 2 lines of code using the same structure and syntax used for your path operations.
FastAPI is fully compatible with (and based on) Pydantic. So, any additional Pydantic code you have, will also work.
Including external libraries also based on Pydantic, as ORMs, ODMs for databases.
This also means that in many cases you can pass the same object you get from a request directly to the database, as everything is validated automatically.
The same applies the other way around, in many cases you can just pass the object you get from the database directly to the client.
With FastAPI you get all of Pydantic's features (as FastAPI is based on Pydantic for all the data handling):
No brainfuck:
No new schema definition micro-language to learn.
If you know Python types you know how to use Pydantic.
Plays nicely with your IDE/linter/brain:
Because pydantic data structures are just instances of classes you define; auto-completion, linting, mypy and your intuition should all work properly with your validated data.
Validate complex structures:
Use of hierarchical Pydantic models, Python typing’s List and Dict, etc.
And validators allow complex data schemas to be clearly and easily defined, checked and documented as JSON Schema.
You can have deeply nested JSON objects and have them all validated and annotated.
Extensible:
Pydantic allows custom data types to be defined or you can extend validation with methods on a model decorated with the validator decorator.