
Begin your journey building a Flask API with a practical, project-based approach. Gain hands-on skills to create, manage, and serve dynamic data from API endpoints for real-world projects.
Access the single source code file for the whole project from this section's resources, download it, compare with your work, and copy needed sections; updates will add the latest code.
Install python on Windows from python.org, add to path, customize installation, install to the C drive, disable path length limit, and verify with cmd shows python 3.12.1.
Install python on macOS using python.org or homebrew, then verify the installation in the terminal by running python3 --version.
Install Visual Studio Code on Windows, customize initial settings like zoom and terminal font size, enable auto save, and create a Python project with a script that prints hello.
Install and launch Visual Studio Code on macOS, choose Apple Silicon or Intel, configure initial settings, create a project folder, add Hello.py, and run it in the terminal.
Learn how Python virtual environments create isolated spaces for each project, letting you manage specific packages and versions without affecting other work, and reproduce environments with a requirements.txt.
Learn to create and manage Python virtual environments on Windows using venv, activate and deactivate scripts, install packages with pip, and troubleshoot execution policy safely.
Create a new Flask project using Python 3.x, set up a virtual environment, install Flask, and build a simple app with a route that returns hello world, run on localhost:5000.
Learn how to manage dependencies with pip, create and reuse a virtual environment, and generate a requirements.txt with pip freeze to replicate Flask app’s setup using pip install -r requirements.txt.
Set up a project-level Visual Studio Code workflow with Python and Ruff to auto format on save, enforce an 88-character line length, and organize imports for clean linted code.
dockerize a postgres relational database for your flask app using docker compose and postgres images, manage with adminer, expose ports, and run via docker desktop for isolated, portable containers.
Centralize environment variables with a docker environment variables file, such as a dot env, to configure Postgres containers via docker compose and avoid sensitive data in the compose file.
Learn to automate a PostgreSQL setup in Docker by writing a Bourne shell script to create a database, install the uuid extension, and run on container startup.
Explore the Flask API factory approach as a flexible design pattern that initializes and configures the Flask app for scalable, maintainable RESTful APIs.
Organize a Flask commerce API by creating a core folder and an inventory app with routes, models, and schemas. Embrace an API factory approach and Docker Compose for project structure.
Design an entry point for a Flask API using a create_app factory in the core package, initialize app in app.py, expose with __init__.py, and run via flask run.
Learn to secure your Flask API by moving sensitive data into environment variables, loading them with python-dotenv, and using a dot env file across the app for modular access.
Define a modular Flask project configuration using a factory approach, with environment-based configs, a shared base configuration, and secret keys loaded from environment variables.
Integrate SQLAlchemy with a Flask app to build tables and models, sync the database, configure a URL from environment variables, and initialize the extension.
Learn to map Python objects to database tables with SQLAlchemy ORM in a Flask app, translating Python into SQL to build tables and query a relational database defined by ERD.
Create a category model with SQLAlchemy in the core folder, defining id, name, slug, and a self-referencing parent_id foreign key for hierarchical categories.
Define the product table with fields and a relation to category, using a uuid as product id, plus slug, name, description, is_digital flag, timestamps, and stock status.
Build the product line model with a foreign key to product, including id, decimal price with precision and scale, uuid sku, stock quantity, and created at.
Create a product image table linked to product lines that stores a url reference and alt text, with an order column and a foreign key to the product line.
Create a seasonal event table with start and end dates and a unique name, then make a nullable foreign key from product to seasonal event, and test relationships and queries.
Implement and manage database migrations with Alembic for SQLAlchemy, generating Python migration scripts that create, alter, or drop tables, and enable rollback in Flask apps.
Migrate your models to the database with SQLAlchemy and Alembic, using Docker to run migrations and verify tables in Adminer.
Finalize the data model by implementing many-to-many relationships with tables for products and product types, and for product lines and attribute values, then migrate the schema and prepare API routes.
Create and register a Flask blueprint to modularize the API, define routes and views for the category table, and expose endpoints under /api to interact with the database.
Create marshmallow schemas in a flask api to serialize database data and deserialize client input, shaping json responses for endpoints like /api/category.
Learn to build RESTful APIs quickly with the minimalistic API fairy framework on Flask and Marshmallow, linking schemas to endpoints via blueprints and decorators, serializing multi-object queries.
Build an API route in Flask to return all categories by querying the database, set up migrations, initialize endpoints and blueprint routes, and test with Thunder Client.
Implement swagger ui to automatically generate and test api documentation for your flask endpoints, providing an interactive interface to visualize endpoints, parameters, requests, responses, and authentication.
Learn to insert data across related tables by starting with category, then product, product line, and product image, while managing mandatory and optional foreign keys and relationships.
Insert a new category into the category table via a post request, set parent_id nullable and is_active default false, then validate with marshmallow and commit via SQLAlchemy.
Learn to build a Flask API route for inserting a product by creating a product blueprint, defining a marshmallow insert schema, managing category foreign keys, and testing with docs.
Build an api route to insert a new product line in Flask by creating a blueprint, a product line insert schema, and its endpoint with a foreign key to product.
Insert a new product line image via a Flask API route using a dedicated blueprint and post request, with schema validation and foreign keys to product lines and categories.
Build a flask api route to insert inventory attributes. Define an attribute schema and link attributes to values with a many-to-many table to normalize data and avoid duplication.
Develop and register a seasonal api blueprint with a seasonal insert schema (id, start date, end date, name) to insert events into the inventory database.
build an api route to add a new product type record, using a self-referencing parent id and a type insert schema, and resolve endpoint conflicts by explicit endpoint naming.
Create a Flask API endpoint and schema to insert attribute value records with a foreign key to attributes, wiring a new attribute value route into a many-to-many product type workflow.
Learn how to model many-to-many relationships using a link table in SQLAlchemy, define relationships with secondary and back_populates, and insert a product with associated product types via a through table.
Learn to implement a many-to-many relationship between product lines and attribute values using SQLAlchemy, define the product line attribute value link table, and populate associations via the product line endpoint.
Master data creation & management with Flask APIs and a modern workflow
This project-based course delves into building a full-fledged Flask API application, empowering you to effectively create, manage, and serve dynamic data. By the end, you'll have a robust API and the hands-on skills to tackle real-world data-driven projects.
What you'll learn:
Solid foundations: Set up your Flask project, manage dependencies, and implement linting for professional code.
Modern containerisation: Leverage Docker to manage your database (PostgreSQL) and environment variables seamlessly.
Structured & scalable: Follow the Flask API factory approach for a well-organised and maintainable project structure.
Powerful ORM: Utilise SQLAlchemy to map your data models to the database and ensure seamless interaction.
Data modelling: Design and implement comprehensive models to represent your data entities effectively.
Migrations & version control: Manage database schema changes using Alembic for a smoother workflow.
API construction: Build robust API endpoints using best practices, blueprints, and data validation with Marshmallow.
Comprehensive documentation: Integrate Swagger-UI to provide API documentation for easy consumption and usage.
Course outline:
Project Setup: Learn how to set up a Flask project, manage dependencies, and configure linting.
Docker & Database: Discover containerisation with Docker, explore PostgreSQL setup, and utilise environment variables effectively.
Flask API Factory: Understand the factory approach, implement the project structure, and configure the entry point.
Models & Database: Dive into SQLAlchemy, design your data model, create models for various entities, and leverage Alembic for migrations.
Building an API: Register blueprints, utilise Marshmallow for data validation, create your first API endpoint, and integrate Swagger-UI documentation.
Who should take this course:
Anyone new to Flask looking to take their first steps building an API in Flask.
By the end of this course, you'll be able to:
Confidently build Flask APIs that interact with databases.
Design and implement data models using SQLAlchemy.
Create well-structured and documented API endpoints.
Utilise Docker for streamlined workflow management.
Ready to create data-driven solutions with Flask APIs? Enrol today!