REST APIs with Flask and Python in 2023

Video description

A REST API is an application that accepts data from clients and returns data back. For example, a REST API could accept text data from the client, such as a username and password, and return whether that is a valid user in the database.

The cover takes you through a Python refresher that will take you from the very basics to some of the most advanced features of Python—that’s all the Python you need to complete the course. Further, you will move on to create resource-based, production-ready REST APIs using Python, Flask, and popular Flask extensions.Learn to handle secure user registration and authentication with Flask. Learn to use SQLAlchemy and Flask-SQLAlchemy to easily and efficiently store resources in a database; understand the complex intricacies of deployments of Flask REST APIs.

You will also investigate essential technologies such as Git and database migrations with Alembic. Together, we will develop a REST API that not only allows clients to authenticate but also store and retrieve any data you want from a database. Learning this will help you develop any REST API that you need for your own projects!

By the end of the course, you will have understood and developed your skills in web and REST API development with Python, Flask, and Docker.

What You Will Learn

  • Connect your web or mobile applications to databases and servers through REST APIs
  • Create secure and reliable REST APIs
  • Understand how web applications interact with each other
  • Handle user authentication with advanced features such as token refresh
  • Handle logouts in your REST APIs with JWT blacklisting
  • Develop professional-grade REST APIs with expert guidance


This course is for students and software developers who want to enhance their mobile and web applications using server-side technologies or expand their skillset by learning how to develop professional-grade REST APIs. Those looking to explore Python for catering to web services specifically will also find this course useful. Familiarity with the basics of programming and knowledge of the Python programming language will help you grasp the concepts quickly.

About The Author

Jose Salvatierra Fuentes: Jose Salvatierra has been teaching online for over seven years, and he loves helping students learn to code and master software development. He founded Teclado to bring software development to everyone; his objective is for you to truly understand everything that goes on behind the scenes.

Coding is extremely rewarding. As you learn, things start to click and make sense. You can join the dots of all the things that weren’t quite clear before.

Jose can help you with Python and JavaScript issues, particularly in web and backend development. He is experienced with programming libraries and frameworks such as Flask, React, React Native, and AngularJS. He has worked extensively with UNIX systems, MongoDB, PostgreSQL, and advanced system architecture design.

Publisher resources

Download Example Code

Table of contents

  1. Chapter 1 : Welcome!
    1. Promotion
  2. Chapter 2 : A Full Python Refresher
    1. Introduction to This Section
    2. Variables in Python
    3. Solution to Coding Exercise: Variables
    4. String Formatting in Python
    5. Getting User Input
    6. Writing Your First Python App
    7. Lists, Tuples, and Sets
    8. Advanced Set Operations
    9. Solution to Coding Exercise: Lists, Tuples, and Sets
    10. Booleans in Python
    11. If Statements
    12. The "in" Keyword in Python
    13. If Statements with the "in" Keyword
    14. Loops in Python
    15. Solution to Coding Exercise: Flow Control
    16. List Comprehensions in Python
    17. Dictionaries
    18. Destructuring Variables
    19. Functions in Python
    20. Function Arguments and Parameters
    21. Default Parameter Values
    22. Functions Returning Values
    23. Solution to Coding Exercise: Functions
    24. Lambda Functions in Python
    25. Dictionary Comprehensions
    26. Solution to Coding Exercise: Dictionaries and Students
    27. Unpacking Arguments
    28. Unpacking Keyword Arguments
    29. Object-Oriented Programming in Python
    30. Magic Methods: ..str.. and ..repr..
    31. Solution to Coding Exercise: Classes and Objects
    32. @classmethod and @staticmethod
    33. Solution to Coding Exercise: @classmethod and @staticmethod
    34. Class Inheritance
    35. Class Composition
    36. Type Hinting in Python 3.5+
    37. Imports in Python
    38. Relative Imports in Python
    39. Errors in Python
    40. Custom Error Classes
    41. First-Class Functions
    42. Simple Decorators in Python
    43. The "at" Syntax for Decorators
    44. Decorating Functions with Parameters
    45. Decorators with Parameters
    46. Mutability in Python
    47. Mutable Default Parameters (and Why They Are a Bad Idea)
  3. Chapter 3 : Your First REST API
    1. Overview of the Project We Will Build
    2. Initial Setup for a Flask App
    3. Your First REST API Endpoint
    4. What Is JSON?
    5. How to Interact with and Test Your REST API
    6. How to Create Stores in Our REST API
    7. How to Create Items in Each Store
    8. How to Get a Specific Store and Its Items
  4. Chapter 4 : Introduction to Docker
    1. What Are Docker Containers and Images?
    2. How to Run a Flask App in a Docker Container
  5. Chapter 5 : Flask-Smorest for More Efficient Development
    1. Data Model Improvements for Our API
    2. General Improvements to Our First REST API
    3. New Endpoints for Our First REST API
    4. How to Run the API in Docker with Automatic Reloading and Debug Mode
    5. How to Use Blueprints and MethodViews in Flask
    6. How to Write Marshmallow Schemas for Our API
    7. How to Perform Data Validation with Marshmallow
    8. Decorating Responses with Flask-Smorest
  6. Chapter 6 : Store Data in DQL Database with SQLAlchemy
    1. Overview and Why Use SQLAlchemy
    2. How to Code a Simple SQLAlchemy Model
    3. How to Write One-to-Many Relationships Using SQLAlchemy
    4. How to Configure Flask-SQLAlchemy with Your Flask App
    5. How to Insert Data into a Table Using SQLAlchemy
    6. How to Find Models in the Database by ID or Return a 404
    7. How to Update Models with SQLAlchemy
    8. How to Retrieve List of All Models
    9. How to Delete Models with SQLAlchemy
    10. Conclusion of This Section
  7. Chapter 7 : Many-to-Many Relationships with SQLAlchemy
    1. Changes in This Section
    2. One-to-Many Relationship Between Stores and Tags
    3. Many-to-Many Relationship Between Items and Tags
  8. Chapter 8 : User Authentication with Flask-JWT-Extended
    1. Who Uses the JWT?
    2. How to Set Up Flask-JWT-Extended with Our App
    3. Coding the User Model and Schema
    4. How to Add a Register Endpoint to the REST API
    5. How to Add a Login Endpoint to the REST API
    6. Protect Endpoints by Requiring a JWT
    7. JWT Claims and Authorization
    8. How to Add Logout to the REST API
    9. Request Chaining with Insomnia
    10. Token Refreshing with Flask-JWT-Extended
  9. Chapter 9 : Database Migrations with Alembic and Flask-Migrate
    1. How to Add Flask-Migrate to Our Flask App
    2. Initialize Your Database with Flask-Migrate
    3. Change SQLAlchemy Models and Generate a Migration
    4. Manually Review and Modify Database Migrations
  10. Chapter 10 : Git Crash Course
    1. What Are Git Repositories and Commits?
    2. Initialize a Git Repository for Our Project
    3. Writing Markdown for Documents and Commits
    4. Remote Repositories and How to Use Them
    5. Git Branches and Merging
    6. Merge Conflicts and How to Resolve Them
    7. Overview of the Final E-Book Chapters
  11. Chapter 11 : Deployments with
    1. Creating a Web Service
    2. How to Run Flask with gunicorn in Docker
    3. Get a Deployed PostgreSQL Database
    4. Use PostgreSQL Locally and in Production
    5. Test the Finished Production App
  12. Chapter 12 : Task Queues with rq and Sending Emails
    1. How to Send Emails with Python and Mailgun
    2. How to Send Emails When Users Register
    3. What Is a Task Queue and Setting Up a Redis Database
    4. How to Populate and Consume the Task Queue with rq
    5. How to Process Background Tasks with the rq Worker
    6. How to Send HTML Emails Using Mailgun and Python
    7. How to Deploy a Background Worker to

Product information

  • Title: REST APIs with Flask and Python in 2023
  • Author(s): Jose Salvatierra Fuentes
  • Release date: December 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781788621526