FastAPI is a modern web framework for building APIs with Python. It is designed to be fast and easy to use, leveraging Python’s type hints to provide features like:
- Automatic generation of OpenAPI documentation.
- Input data validation based on Python’s type annotations.
- Asynchronous request handling with native support for
asyncio
. - High performance, as it is built on Starlette and Pydantic.
Key Features
- Automatic validation: Based on type hints and Pydantic models.
- Interactive API docs: Automatically generated Swagger UI and ReDoc.
- Asynchronous support: Full support for async functions.
- Dependency injection: Built-in support for dependencies.
How to Run
==In ML_Tools see: FastAPI_Example.py== ← see this
-
Save the script as
main.py
. -
Install FastAPI and Uvicorn:
pip install fastapi uvicorn
-
Run the server:
ren FastAPI_Example.py main.py # possibly change to uvicorn FastAPI_Example:app --reload
-
Open the browser and navigate to:
- API documentation (Swagger UI):
http://127.0.0.1:8000/docs
- ReDoc documentation:
http://127.0.0.1:8000/redoc
- API documentation (Swagger UI):