Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
FastAPI with Python: Build REST API Using Clean Architecture
32 students

FastAPI with Python: Build REST API Using Clean Architecture

Build scalable REST APIs with FastAPI, Python, JWT auth, SQLAlchemy, PostgreSQL & Docker using Clean Architecture
Created byRichard Dewan
Last updated 3/2026
English

What you'll learn

  • Fast API
  • SQLAlchemy
  • Alembic
  • Docker

Course content

3 sections • 47 lectures • 9h 9m total length
  • How To Download Source Code1:17

    Download the source code for this course from the GitHub repository by selecting the main branch, browsing files, and downloading specific tags or commits and starring the repo.

  • Introduction & Setup Virtual Environment9:28
  • Setup FastAPI And Docs7:11

    Install dependencies from requirements.txt and scaffold a clean architecture with an app directory and main.py. Create a get root endpoint returning a status and welcome message, and explore OpenAPI docs.

  • FastAPI HTTP Methods(GET- POST - PUT - PATCH - DELETE)22:23

    Learn to build a simple FastAPI rest API with in-memory users, implementing post to create, get to fetch, put and patch for updates, and delete to remove.

  • Clean Architecture22:34

    Explore clean architecture with domain-driven design, detailing the four layers—domain core, application, infrastructure, and interface—and how they interconnect while preserving core stability and minimizing external dependencies.

  • Folder Structure11:33

    Learn to implement a clean architecture in FastAPI project by structuring folders into core, common, and features, including admin and client, with authentication and four-layer layout (interface, application, infrastructure, domain).

  • Setup SQLAlchemy5:46
  • Country Model12:25
  • Country Entity4:01
  • Country Mappers - Model & Entity6:19
  • Environment Variables6:14

    Install dependencies from requirements.txt and create a .env file, loading environment variables into a base config using pylantic settings to configure the database user, password, host, port, and name.

  • Setup Database Connection13:21

    Set up a Postgres database connection in a FastAPI project by installing the psycopz adapter and SQLHelpsMeUtils, then build the URL, engine, and session.

  • Postgres Docker Container13:42

    Configure docker desktop to run a postgres docker container with docker compose, using an env file, volume persistence, and mapped ports for a reusable development database.

  • Country Repository Interface5:35

    Define a country repository interface in Python using the ABC module, declaring abstract methods to get all countries, get a country by id, create, update, and delete a country entity.

  • Country Repository13:04

    Create the country repository in the infrastructure layer using a SQLAlchemy session, mapping country entities to models, and implement CRUD operations with dependency injection.

  • Code Formatter and Lint Rules13:54

    Install the Python extension for VS Code to enable intellisense, debugging, and linting, then configure PyRite with a settings.json and add cspell and Black to enforce type checking and formatting.

  • Country Service-Dependency Inversion Principle (DIP)13:02

    Build a country service in a clean architecture using dependency injection of the I country repository, implementing CRUD operations for countries with docstrings and exception handling.

  • EnvConfig and Database Provider7:55

    Create providers for envconfig and database, implement a get_db_session generator, and cache the envconfig with an lru cache singleton to enable clean dependency injection for repositories and services.

  • Dependency Injection9:29
  • API Endpoint17:58
  • Run API Server and Swagger8:52

    Start the FastAPI server and expose the versioned admin country router through clean imports; enable the Swagger doc to explore endpoints and validate routing.

  • Alembic Setup & Migration25:59

    Set up Alembic for database migrations by installing Alembic, initializing config, wiring env.py with .env, importing base metadata and models, and running online migrations to create tables.

  • pgAdmin Database GUI Tool4:58

    Install and set up PgAdmin to manage a Postgres database, connect to a local server on port 5437, explore schemas and tables (alembic_version, countries), and run queries to seed data.

  • Insert Record To Database9:50

    Learn to insert a country record into a database using fastapi and clean architecture, including schema to entity mapping, optional fields, and dependency-injected db sessions.

  • Patch Record To Database17:45

    Patch batch records to the database by updating fields of the country entity, such as name, country code, or currency code, using an update country schema and committing via session.

  • Get and Delete Record From Database4:27
  • Pagination11:55
  • Register Exception Handler12:16

    centralize exception handling in a FastAPI project by creating repository exceptions, building an HTTP errors registrar, and mapping database failures to a 503 response.

  • Repository Exception Handler9:08

    Implement repository exception handling to centralize http errors. Map operational and integrity sql errors to a 503 response with code and message, and rollback pending transactions on failures.

  • Domain Exception Handler19:10
  • Sort and Search11:19

    Add an optional search parameter to the get all countries endpoint, filtering by name, country code, or currency code, and sort results by name ascending with pagination.

Requirements

  • Basic Of Python and Backend Development

Description

Are you ready to build production-ready REST APIs using FastAPI and Python?

In this course, you will learn how to design, develop, and deploy scalable backend applications using FastAPI, one of the fastest-growing Python frameworks for modern web development. We won’t just build simple CRUD apps — you’ll learn how to structure real-world projects using Clean Architecture and industry best practices.

FastAPI combines high performance, automatic documentation, and modern Python features like type hints to help you build robust APIs quickly and efficiently. By the end of this course, you’ll be able to confidently design and implement secure, maintainable backend systems.

What You’ll Learn:

  • Build RESTful APIs with FastAPI

  • Apply Clean Architecture principles to real-world projects

  • Work with SQLAlchemy and PostgreSQL

  • Handle request validation and error management

  • Structure scalable and maintainable backend applications

  • Use Docker to containerize your FastAPI app

  • Generate automatic API documentation with Swagger & OpenAPI

  • Follow best practices for production deployment

Who This Course Is For:

  • Python developers who want to build modern APIs

  • Backend developers transitioning to FastAPI

  • Developers who want to learn Clean Architecture

  • Anyone preparing for backend developer roles

This course focuses on practical implementation, clean code, and professional project structure — so you can move from beginner to confident FastAPI backend developer.

Start building high-performance APIs today!

Who this course is for:

  • Beginner Python Developer
  • Beginner Backend Developer