Web Development · WDC-102

FastAPI with MS SQL Server

FastAPI with MS SQL Server is a hands-on course in building RESTful APIs with Python and FastAPI on a Microsoft SQL Server database through SQLAlchemy, covering Pydantic, CRUD, migrations and JWT login. It suits programmers and system developers who can write Python, and you leave able to build an authenticated API backed by SQL Server.

Updated
From 9,450 THB / person 10,500 −10% excl. VAT 7% · group rates available
PDFDownload the course outline
  • Duration18 hours · 3 days
  • FormatOnsite / live online
  • Next round17–19 Nov 26
  • CertificateIncluded

Course overview

FastAPI is a popular framework for building APIs in Python because it is concise, fast, validates data automatically from type hints and generates API documentation straight away. At the same time, many organisations keep their core data in Microsoft SQL Server, so connecting the two the right way is a skill development teams need. Yet many examples still use Pydantic v1, older SQLAlchemy patterns, or JWT and password-hashing libraries that are no longer recommended.

This course shows learners how to build RESTful APIs with the current FastAPI on Python 3.13 or later, from routing, Pydantic v2, error handling, forms and file uploads to structuring a project with APIRouter. Learners then connect to SQL Server 2025 through SQLAlchemy 2.0 and ODBC Driver 18, manage the schema with Alembic, build CRUD for a TODO project, add OAuth2 and JWT login following the approach in the FastAPI documentation, write tests with pytest and bring everything together with Docker Compose. (3 days, 6 hours per day, 18 hours in total, Intermediate level.)

What you’ll gain

  • Build RESTful APIs with FastAPI and test them through Swagger UI and Postman
  • Validate and convert data with Pydantic v2 and define clear response models
  • Structure a project with APIRouter, version the API and configure CORS
  • Connect to Microsoft SQL Server with SQLAlchemy 2.0 and ODBC Driver 18
  • Manage the schema with Alembic and build CRUD endpoints with pagination
  • Implement authentication and authorisation with OAuth2 and JSON Web Tokens (JWT)
  • Write API tests with pytest and run the system with Docker Compose

Who this course is for

  • Programmers and system developers who need to build APIs in Python
  • Developers in organisations that use Microsoft SQL Server as their main database
  • Backend developers moving from Flask or Django to FastAPI
  • Developers who learned an older version of FastAPI and want to update to current practice

Prerequisites

  • Able to program in Python, including variables, functions, classes and installing libraries
  • A basic understanding of HTTP, such as methods, status codes and JSON
  • Basic SQL, such as SELECT, INSERT, UPDATE and DELETE
  • A laptop that can run Python, Docker Desktop and VS Code, with permission to install software

Curriculum

Course Details

This course is the 2026 edition of FastAPI with MS SQL Server. It has been rewritten for the current FastAPI with Pydantic v2, SQLAlchemy 2.0, SQL Server 2025 and ODBC Driver 18, and moves JWT handling to PyJWT and password hashing to Argon2, as the FastAPI documentation recommends. It runs for 3 days, 6 hours per day (18 hours in total, 09:00-16:00), as lectures with labs built on a single TODO project that grows throughout the course. Intermediate level. New content covers Alembic, pagination, user permissions, pytest and Docker Compose. Learners take home a lab guide, source code and database scripts.

Day 1 FastAPI and RESTful API Fundamentals

Section 1: Lab: Setting Up Tools and a First API

  • What FastAPI is and how it differs from Flask and Django
  • Install Python 3.13 or later and create a project with uv
  • Install fastapi[standard] and run with the fastapi dev command
  • Explore the automatic API documentation in Swagger UI and ReDoc
  • Lab: build a first API and test it with Postman or Bruno

Section 2: Routing and Receiving Input

  • Declare HTTP GET, POST, PUT, PATCH and DELETE
  • Receive path parameters and query strings with type hints
  • Use Annotated with Path, Query and Header to validate values
  • Read JSON from the HTTP body and return the right status codes
  • Lab: a product API that searches and filters with query strings

Section 3: Lab: Pydantic v2 and Response Models

  • Create separate models for requests and responses
  • Validate data with Field, validators and types such as EmailStr
  • Set response_model and return types to filter outgoing data
  • Nested models, lists and optional values
  • Lab: a sign-up API with a complete set of validation rules

Section 4: Error Handling, Forms and File Upload

  • HTTPException and a central custom exception handler
  • A consistent error response format across the system
  • Receive form data and URL-encoded input
  • Upload files with UploadFile, checking type and size
  • Serve a static file folder for images and documents

Section 5: Lab: Structuring the Project

  • Split routes across files with APIRouter, prefixes and tags
  • Version the API, for example /api/v1
  • Configure CORS so a frontend can call the API safely
  • Read settings from a .env file with pydantic-settings
  • Lab: structure the TODO project ready to connect to a database
Day 2 Connecting to Microsoft SQL Server

Section 6: Lab: SQL Server 2025 for Developers

  • Run SQL Server 2025 on Docker and connect from VS Code
  • Design tables with primary keys, IDENTITY and foreign keys
  • Store Thai text with NVARCHAR and a suitable collation
  • Create indexes on frequently searched columns
  • Lab: create the database and tables for the TODO project

Section 7: Connecting with SQLAlchemy 2.0

  • Install ODBC Driver 18 and pyodbc on Windows, macOS and Linux
  • The mssql+pyodbc connection URL and encryption settings
  • Engines, connection pools and sessions
  • Provide a session to routes with a yield dependency
  • An overview of async connections with aioodbc and when to use them

Section 8: Lab: ORM Models and Alembic

  • Declare models with DeclarativeBase, Mapped and mapped_column
  • A one-to-many relationship between users and TODO items
  • Create and update the schema with Alembic migrations
  • Keep Pydantic schemas separate from ORM models
  • Lab: create the users and todos tables through migrations

Section 9: Lab: CRUD for the TODO Project

  • GET all items and GET by ID
  • POST new items, validating data before saving
  • PUT and PATCH to update, DELETE to remove
  • Pagination with OFFSET FETCH, plus filtering and sorting
  • Lab: a complete TODO API that stores data in SQL Server

Section 10: Advanced Queries and Transactions

  • Join several tables and select only the columns you need
  • Transactions and rolling back when an error occurs
  • Call an organisation's existing views and stored procedures
  • Prevent SQL injection with bound parameters
  • Lab: an API that summarises outstanding tasks per user
Day 3 Authentication, Testing and Workshop

Section 11: Lab: Getting Started with Authentication

  • Authentication and authorisation concepts
  • The OAuth2 password flow with OAuth2PasswordBearer
  • Hash passwords with pwdlib and Argon2 instead of passlib
  • Sign-up and login endpoints that store users in SQL Server
  • Lab: a basic registration and login system

Section 12: Lab: JSON Web Tokens (JWT)

  • JWT structure: header, payload and signature
  • Encode JWTs with PyJWT and set an expiry time
  • Decode and verify JWTs in a get_current_user dependency
  • Access tokens and refresh tokens
  • Keep the secret key safe in an environment variable

Section 13: Authorisation and Scalable Routers

  • Protect a whole router with a dependency
  • Role-based permissions such as Admin and User
  • Let users see and edit only their own TODO items
  • Separate auth and todos files so the system is easy to extend
  • Lab: secure every TODO endpoint with JWT and user permissions

Section 14: Lab: Testing and Logging

  • Write tests with pytest and TestClient
  • Replace dependencies during tests with dependency_overrides
  • Test against a separate SQL Server database on Docker
  • Log requests and errors systematically

Section 15: Workshop: A Production-Ready TODO API

  • Combine the API, authentication and database into one system
  • Write a Dockerfile and Docker Compose for the API and SQL Server
  • Run with multiple workers behind a reverse proxy
  • A security and performance checklist before going to production
  • Present the work and plan next steps

Schedule & training options

For individuals — public rounds

17–19November
Classroom17–19 Nov 26
20 seats left
19–21January
Classroom19–21 Jan 27
20 seats left
2–4March
Classroom2–4 Mar 27
20 seats left
7–9April
Classroom7–9 Apr 27
20 seats left
8–10June
Classroom8–10 Jun 27
20 seats left
17–19August
Classroom17–19 Aug 27
20 seats left
5–7October
Classroom5–7 Oct 27
20 seats left
14–16December
Classroom14–16 Dec 27
20 seats left

For organisations — in-house / private

  • Tailor the content to your team’s tools and projects
  • Your dates, at your office or live online
  • Quotation with tax ID for procurement
Corporate training quote

Instructors

Frequently asked questions

What is FastAPI, and why is it popular for building APIs in Python?

FastAPI is a framework for building web APIs in Python that uses type hints to validate and convert data automatically through Pydantic. Code is concise and fast, async is supported, and Swagger UI and ReDoc documentation is generated straight from the code, which cuts documentation work and errors from badly formed data. Current versions use Pydantic v2, and the standard toolset installs with fastapi[standard], which includes the fastapi dev command for development.

How do I connect FastAPI to MS SQL Server through an ORM?

Install Microsoft ODBC Driver 18 and pyodbc, then use SQLAlchemy 2.0 to create an engine with an mssql+pyodbc connection URL that names the driver and encryption settings. Declare models with DeclarativeBase, Mapped and mapped_column, then create a dependency that opens a session with yield for each request and closes it afterwards. Use Alembic to manage schema changes, and always use bound parameters to prevent SQL injection.

How does JWT authentication work in FastAPI?

The user sends a username and password to a login endpoint. The system checks the password against the stored hash, for which the FastAPI documentation recommends pwdlib with Argon2, and if it matches it issues a JWT with PyJWT containing the user's identity and an expiry time. The user sends the token as a Bearer header on every call, and FastAPI uses OAuth2PasswordBearer with a get_current_user dependency to verify the token and load the user before allowing access to protected endpoints.

Who is the FastAPI with MS SQL Server course for, and what should I know beforehand?

It suits programmers and system developers who need to build APIs in Python, especially in organisations that use Microsoft SQL Server as their main database, as well as developers moving from Flask or Django and those who used an older FastAPI. You should be able to program in Python, understand the basics of HTTP and JSON, and write basic SQL.

What will I be able to do after the FastAPI with MS SQL Server course?

You will be able to build RESTful APIs with FastAPI and Pydantic v2, structure them with APIRouter and CORS, connect to SQL Server with SQLAlchemy 2.0, build CRUD with pagination, manage the schema with Alembic, add OAuth2 and JWT login with user permissions, write tests with pytest and run the system with Docker Compose. Participants who complete the training receive a Certificate of Completion with its own number, which can be verified online.

Can the FastAPI with MS SQL Server course be run in-house for our team?

Yes. It can be run in-house for your team, with examples adapted to your work, such as connecting to tables, views or stored procedures in the style your team uses, or focusing on permissions and deployment for your environment. You can request a quotation from this page, or contact us on LINE @itgenius or by phone on 02-570-8449.

Related articles

Articles are published in Thai.