Skip to main content
In this project, you will build a complete Student CRUD API using FastAPI and a local Python dictionary. We will not use a database in this project.

Project Setup

In this project, you will create a FastAPI application using uv for package management and a virtual environment for dependency isolation.

Step 1: Create the Project Folder

Create a new project folder.

Step 2: Create a Virtual Environment

Create a virtual environment using uv.
This creates a virtual environment in the .venv folder.

Step 3: Activate the Virtual Environment

Windows (Command Prompt)
Windows (PowerShell)
macOS / Linux
After activation, your terminal prompt should display (.venv).

Step 4: Install the Required Packages

This command:
  • Installs FastAPI and Uvicorn
  • Creates pyproject.toml
  • Creates uv.lock

Step 5: Create the Project Structure

Step 6: Create the Application File

Create a file named main.py.

Step 7: Run the Application

The --reload option automatically restarts the server whenever you save changes.

Step 8: Open the Application

Home: http://127.0.0.1:8000 Swagger UI: http://127.0.0.1:8000/docs

Build the Student CRUD API

Step 1: Create the FastAPI Application

Create main.py and initialize the FastAPI application.
Run the application and verify the home page.

Step 2: Create the Student Model

Step 3: Create a Local Data Store

Step 4: Build the Create Student API

Endpoint: POST /students Sample Request
Test the endpoint from Swagger UI.

Step 5: Build the Get All Students API

Endpoint: GET /students

Step 6: Build the Get Student by ID API

Endpoint: GET /students/{student_id} Example: GET /students/1

Step 7: Build the Update Student API

Endpoint: PUT /students/{student_id} Sample Request

Step 8: Build the Delete Student API

Endpoint: DELETE /students/{student_id}

Step 9: Test the Complete CRUD Flow

Open Swagger UI: http://127.0.0.1:8000/docs Execute the APIs in this order:
  1. GET /students
  2. POST /students
  3. GET /students
  4. GET /students/{student_id}
  5. PUT /students/{student_id}
  6. GET /students/{student_id}
  7. DELETE /students/{student_id}
Observe how the dictionary changes after every operation.