FastAPI
FastAPI is a modern, high-performance Python web framework for building
APIs.
It is built on Starlette and Pydantic(specialized libraries to provide
its high-performance web capabilities and data management), and uses
Python type hints for validation and automatic OpenAPI documentation.
Starlette (Web Network) + Pydantic (Data Validation) + Automatic
Documentation & Tools
Features:
1. Fast to run — comparable to Node.js and Go for API workloads.
2. Automatic request/response validation via Pydantic models.
3. Interactive API docs at /docs (Swagger UI) and
/redoc.
4. Native async/await support for I/O-bound endpoints.
Install
# In venv
pip3 install fastapi
pip3 install uvicorn # Install ASGI server called uvicorn to run FastAPI app
Create, Run FastAPI Project
Start Uvicorn from Command line
|
Starting Uvicorn Server Programmatically
|
Inbuilt Rest Endpoints
docs
No need to write documentation. Just open
http://127.0.0.1:8001/docs to get information of all REST
endpoints exposed by app.
FastAPI uses Swagger UI to produce this documentation.
http://127.0.0.1:8001/docs
|
Click on 'try it out' > 'Execute' > Curl command internally
executed The request URL, the response headers, and the JSON format of the servers response.
|