We may earn an affiliate commission when you visit our partners.
Alan Simpson

FastAPI and SQLModel are two of the hottest new Python technologies for developing asynchronous APIs with modern Python. If you're struggling with wrapping your head around how it all works, this course is for you. Here you'll learn all the most important fundamentals for creating APIs that support all database CRUD operations for adding, editing, and deleting database tables and rows.

Read more

FastAPI and SQLModel are two of the hottest new Python technologies for developing asynchronous APIs with modern Python. If you're struggling with wrapping your head around how it all works, this course is for you. Here you'll learn all the most important fundamentals for creating APIs that support all database CRUD operations for adding, editing, and deleting database tables and rows.

The course takes a very hands-on approach. That’s because most of us learn by doing. All of the code generated in the course is also available for download, so you can use it for future reference when trying to remember how to accomplish some goal. Topics and techniques covered include:

· Creating SQLModel databases and tables

· Creating FastAPI routes and functions for posting, retrieving, updating, and deleting data

· Customizing API Request and Response Schemas

· Using RegEx validation in SQLModel

· Designing re-usable server-side validators

· Sorting and Searching with SQLModel

· Working with virtual deletes and undeletes

· Joining tables

· Customizing column names in responses

· Using HTML forms for database interactions

· Debug FastAPI and SQLModel with VS Code Breakpoints

In short, the course is all about learning how to do all the common day-to-day operations found in apps that allow users to interact with databases. All the code in the course is also available for download, and organized in a way to help students look up the code they need, on-the-fly, as-needed with minimum fuss.

Students need not already be familiar with FastAPI or SQLModel. However, students should already be familiar with basic Python programming. Some familiarity with SQL and databases also helpful.

Enroll now

What's inside

Learning objectives

  • Use fastapi and sqlmodel to create modern python apis
  • Create routes and functions for high-performance json database interactions
  • Develop a library of code for working with multiple related tables
  • Use fastapi templating to use html forms for data entry and editing

Syllabus

Introduction

This lesson overviews what you need to get started creating modern asynchronous APIs with Python, FastAPI, and SQLModel.

Create a modern API that accepts, and returns, data in JSON format
Read more

Here you'll learn how to set up a virtual environment for working with FastAPI and SQLModel.

Here you'll create a models.py file and to define the data models for your application.

Here you'll create your app's database.py file and a live SQLite database for development and testing.

Here you'll learn to use a database browser to help with testing and debugging your API.

Here you'll learn how to design an API be designing and declaring some routes and functions for database interactions.

This lesson shows how to define functions within your API to accept data from API requests, and return data in a response.

Many modern APIs accept and return data in JSON format. But sometimes it's handy to just return some HTML. This lessons shows you how and why.

Posting Data through the API

As your code increases in complexity, you'll need the ability to step through the code with breakpoints. This lesson shows you how to do that using VS Code.

Here you'll learn skills for controlling exactly how your API responds to a request, and how things look in the automatic FastAPI documentation.

Once you API for posting new data is working, you can create routes for retrieving data. This lesson shows you how.

This lesson shows you how to create an API route to allow users to update data that's already in the database.

This lesson shows you how to set up and API route for physically deleting a row from a table.

FastAPI's automatic documentation is a great convenience for API developers. But it's default schemas aren't always ideal. This lesson shows you how to improve those,  to better serve your API users.

Often we need the same kind of server-side validation across multiple routes and functions. This lesson provides a way to centralize those with simple Python functions, so you don't have to repeat the same over and over again throughout your routes and functions.

Putting things in alphabetical or numeric order, and performing complex queries are common tasks for developers. This lesson shows you how to do those things in FastAPI and SQLModel.

In this section you'll add a second table to your database. The table includes a foreign key field relating it to the categories. This will allow us to get into more advanced topics.

Once you've understood the basics of using routes with a simple database table, you're ready to move on to more complex data types. This lesson shows you how to add another table with a foreign key to the Category model. It also shows you how to work with Booleans and Datetimes in SQLModel.

RegEx is a great tool for validating data based on content, size, and pattern. This lesson shows you how to use RegEx for validation in your FastAPI and SQLModel models.

Once you have your new, related table defined, you can start creating routes for it. This lesson shows you how to create a route for adding rows to the Video table.

Virtual deleting allows auditors to keep track of what's been deleted in the past. It also provides the option to undelete. This lesson shows you how to set up routes for virtual deletes and undeletes.

When retrieving rows from the Videos table, you must exclude rows that have been virtually deleted. This lesson shows you how.

Our Video model includes a field to tracking when a row was last updated. This lesson shows you how to update a row, and also update the change date automatically.

There may be times when you want a route to contain data from two or more tables. This lesson shows you how to join tables so you can make that happen.

There may be times when the label you gave a table field isn't ideal for data you're returning. In this lesson you'll learn how to control the names of columns returned by your API.

Sometimes your app needs to know how many rows exist in a table. This lesson shows you how to obtain such counts within your API.

While many modern APIs work strictly with JSON requests and responses, you still have the option of working with HTML and HTML forms. This section shows you how.

When you use FastAPI templating to return HTML, you typically need static CSS and JavaScript files, as on a standard website. This lesson shows you how to set up a folder for static files in FastAPI.

This lesson shows you how to set up a templates folder for use with Jinja2 and FastAPI templating.

If you use templates and HTML forms for your front-end, you may want to serve entire pages to each request. This lesson shows you how to set up a layout page to accomplish just that.

In this lesson you'll learn to create an HTML form for entering new rows into a database table.

Your new form can send data to your API. This lesson shows how to write the code to accept the data, and put it in the database.

In this lesson we'll add a little CSS to make the pages easier on the eyes.

Dropdown lists and other controls often need to get their date from a database upon request. This lesson shows you how to population a dropdown list with data from the Category table.

In this lesson you'll learn to copy items from a database to an HTML form that can list them on a page, with click-to-edit buttons for each row.

With the forms in place for allowing updates, you just need a route on the server side to accept those updates and persist to the database. This lesson shows you how to write that code.

When a function completes some job, such as saving new or edited data, you may want to return them to the list of items rather then the form from which they came. That's called a redirect, and this lesson shows you how to do that in FastAPI.

This lesson shows you how to allow users to delete a row (with confirmation), and how to customize each page's title. To put the finishing touches on our FastAPI templating example.

Save this course

Save Hands-On Beginner FastAPI and SQLModel to your list so you can find it easily later:
Save

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Hands-On Beginner FastAPI and SQLModel with these activities:
Review Basic SQL Concepts
Reinforce your understanding of SQL fundamentals, including creating tables, inserting data, and writing basic queries, to better grasp SQLModel concepts.
Show steps
  • Review SQL syntax for SELECT, INSERT, UPDATE, and DELETE statements.
  • Practice writing SQL queries on sample databases.
  • Familiarize yourself with database normalization concepts.
Brush Up on Python Fundamentals
Strengthen your Python foundation, focusing on data structures, functions, and object-oriented programming, to facilitate a smoother learning experience with FastAPI and SQLModel.
Browse courses on Python Basics
Show steps
  • Review Python syntax and data types.
  • Practice writing functions and classes in Python.
  • Work through basic Python tutorials and exercises.
Read 'FastAPI: The Definitive Guide'
Deepen your understanding of FastAPI by exploring advanced features and best practices covered in this comprehensive guide.
View Melania on Amazon
Show steps
  • Read the book cover to cover.
  • Experiment with the code examples provided in the book.
  • Take notes on key concepts and techniques.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Build a Simple CRUD API
Solidify your knowledge by building a CRUD (Create, Read, Update, Delete) API for a simple data model using FastAPI and SQLModel.
Show steps
  • Define a data model using SQLModel.
  • Create FastAPI routes for CRUD operations.
  • Implement database interactions using SQLModel.
  • Test the API endpoints using a tool like Postman.
Write a Blog Post on FastAPI and SQLModel
Reinforce your learning by writing a blog post explaining the benefits of using FastAPI and SQLModel for building modern APIs.
Show steps
  • Choose a specific topic related to FastAPI and SQLModel.
  • Research and gather information on the chosen topic.
  • Write a clear and concise blog post explaining the topic.
  • Include code examples and illustrations to support your explanations.
Contribute to SQLModel Documentation
Deepen your understanding of SQLModel by contributing to its open-source documentation, improving clarity and providing examples.
Show steps
  • Identify areas in the SQLModel documentation that need improvement.
  • Fork the SQLModel repository on GitHub.
  • Make the necessary changes to the documentation.
  • Submit a pull request with your changes.
Read 'SQLAlchemy 2.0'
Gain a deeper understanding of the underlying database interactions by studying SQLAlchemy, the foundation upon which SQLModel is built.
View Essential SQLAlchemy on Amazon
Show steps
  • Read the book cover to cover.
  • Experiment with the code examples provided in the book.
  • Take notes on key concepts and techniques.

Career center

Learners who complete Hands-On Beginner FastAPI and SQLModel will develop knowledge and skills that may be useful to these careers:

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Hands-On Beginner FastAPI and SQLModel.
SQLAlchemy is the foundation upon which SQLModel is built. provides a deep dive into SQLAlchemy's core concepts and features. It is useful for understanding the underlying mechanisms of SQLModel and for tackling more complex database interactions. This book is more valuable as additional reading for those who want to become experts.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser