KevsRobots Learning Platform
33% Percent Complete
By Kevin McAleer, 3 Minutes

FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python type hints. Its key features include automatic API documentation, data validation, serialization, and asynchronous request handling. FastAPI is designed to make it easy to create a web API that is fast to code, easy to understand, and ready for production.
Choosing FastAPI for user authentication in your project comes with several benefits:
Letβs create a simple FastAPI application to understand its structure:
In your project directory, ensure you have a file named main.py. This file will be the entry point for your FastAPI application.
Open main.py and add the following code:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
Use the following command to run your application:
uvicorn main:app --reload
The --reload flag makes the server restart after code changes. This is useful during development but should be removed in production.
With your FastAPI application running, visit http://127.0.0.1:8000 in your web browser. You should see a response from your API.
FastAPI automatically generates documentation for your API. Access this documentation by visiting http://127.0.0.1:8000/docs for the Swagger UI or http://127.0.0.1:8000/redoc for ReDoc.
Youβve now created your first FastAPI application and explored some of its core features. In the coming lessons, weβll dive deeper into building a user authentication system, starting with modeling our user data.
Experiment with adding another route to your FastAPI application. Try returning different types of data, such as a list or a dictionary with nested data. Reflect on how FastAPIβs automatic documentation updates with your changes.
You can use the arrows β β on your keyboard to navigate between lessons.
Comments