What this book covers
Chapter 1, A Deep Dive into the Flask Framework, introduces Flask as a simple and lightweight Python framework for web applications and showcases the installation of Flask 3 to jumpstart web application development using a non-standard project directory structure with basic Flask features, such as the view functions, class-based views, database connectivity, built-in Werkzeug server and libraries, and custom environment variables.
Chapter 2, Adding Advanced Core Features, provides the Flask 3 core features of web applications, such as session management, data management using Object Relational Mapping (ORM), view rendition using Jinja2 templates, message flashing, error handling, software logging, adding static contents, and applying blueprint and application factory design to project structuring.
Chapter 3, Creating REST Web Services, introduces API development using Flask 3 with request and response handling, implementation of JSON encoders and decoders for parsing the incoming request body and outgoing response, access of request and application context using @before_request
and @after_request
events, exception handling, and implementation of client applications to consume the REST services.
Chapter 4, Utilizing Flask Extensions, discusses how to save development time and effort by using helpful and efficient Flask modules in replacement to their ground-up equivalents, such as Flask-Session for non-browser-based session handling, Bootstrap-Flask for providing the presentation layer, Flask-WTF for building model-based web forms, Flask-Caching for creating cache, Flask-Mail for sending emails, and Flask-Migrate for building the database schema from data models.
Chapter 5, Building Asynchronous Transactions, explains the asynchronous features of Flask 3, which includes creating asynchronous view and API endpoint functions, implementing an asynchronous repository layer using SQLAlchemy, building asynchronous background tasks using Celery and Redis, implementing WebSocket and Server-Sent Events (SSE) with asyncio
utilities, applying asynchronous signals for triggering transactions, and applying reactive programming, and introduces Quart as the ASGI-variant of Flask 3.
Chapter 6, Developing Computational and Scientific Applications, discusses the use of Flask in building scientific applications with XLSX and CSV uploading and tabular and graphical reports using popular Python libraries such as numpy
, pandas
, matplotlib
, seaborn
, scipy
, and sympy
, JavaScript libraries such as Chart.js, Bokeh, and Plotly, LaTeX tools for PDF generation, Celery and Redis for time-expensive background computations, and other scientific tools, such as Julia.
Chapter 7, Using Non-Relational Data Storage, explains how Flask can manage non-relational and big data using popular NoSQL databases, such as Apache HBase/Hadoop, Apache Cassandra, Redis, MongoDB, Couchbase, and Neo4J.
Chapter 8, Building Workflows with Flask, discusses how to implement non-BPMN and BPMN workflows with Flask 3, using Celery and Redis, SpiffWorkflow, Zeebe server from Camunda, Airflow 2, and Temporal.io.
Chapter 9, Securing Flask Applications, provides various ways to secure web-based and API-based Flask applications, such as implementing authentication and authorization mechanisms using HTTP Basic, Digest, and Bearer-token authentication schemes, OAuth2 authorization schemes, and Flask-Login; utilizing encoding/decoding and encryption/decryption libraries to protect user credentials; applying form validation and data sanitation to avoid different web attacks; replacing HTTP with the secured HTTPS to run applications; and controlling response headers to restrict or limit user access.
Chapter 10, Creating Test Cases for Flask, provides techniques for testing with or without mocking the Flask 3 components, such as model classes, repository transactions, native services, view and API endpoint functions, database connectivity, asynchronous processes, and WebSockets, using the PyTest framework.
Chapter 11, Deploying Flask Applications, discusses different options for deploying and running a web or API application, which includes using Gunicorn for standard and asynchronous Flask applications, uWSGI, the Docker platform through Docker Compose and Kubernetes deployments, and Apache HTTP Server.
Chapter 12, Integrating Flask with Other Tools and Frameworks, provides solutions for integrating Flask applications into different popular tools, such as GraphQL, React client applications, and Flutter mobile applications, and for building sub-applications built from Django, FastAPI, Tornado, and Flask frameworks within a microservice application using Flaskās interoperability feature.