๐”– Scriptorium
โœฆ   LIBER   โœฆ

๐Ÿ“

Mastering Flask Web and API Development

โœ Scribed by Sherwin John C. Tragura


Publisher
Packt Publishing Pvt Ltd
Year
2024
Tongue
English
Leaves
599
Edition
`1
Category
Library

โฌ‡  Acquire This Volume

No coin nor oath required. For personal study only.

โœฆ Synopsis


Discover how to construct API and web components, build enterprise-grade applications, design and implement unit and behavioral testing, and plan deployment strategies for scalable Flask 3 applications

Key Features
- Implement web and API applications using both standard and asynchronous Flask components
- Improve your dev experience with signals, route decorators, async/await design patterns, context managers, and nested blueprints
- Tie all the features together in each chapter through practical, relatable applications

Book Description
Flask is a popular Python framework known for its lightweight and modular design. Mastering Flask Web and API Development will take you on an exhaustive tour of the Flask environment and teach you how to build a production-ready application.

You'll start by installing Flask and grasping fundamental concepts, such as MVC and ORM database access. Next, you'll master structuring applications for scalability through Flask blueprints. As you progress, you'll explore both SQL and NoSQL databases while creating REST APIs and implementing JWT authentication, and improve your skills in role-based access security, utilizing LDAP, OAuth, OpenID, and databases. The new project structure, managed by context managers, as well as ASGI support, has revolutionized Flask, and you'll get to grips with these crucial upgrades. You'll also explore out-of-the-box integrations with technologies, such as RabbitMQ, Celery, NoSQL databases, PostgreSQL, and various external modules. The concluding chapters discuss enterprise-related challenges where Flask proves its mettle as a core solution.

By the end of this book, you'll be well-versed with Flask, seeing it not only as a lightweight web and API framework, but also as a potent problem-solving tool in your daily work, addressing integration and enterprise issues alongside Django and FastAPI.

What You Will Learn
- Prepare, set up, and configure development environments for both API and web applications
- Explore built-in serializers and encoders that processes request and response data
- Solve big data issues by integrating Flask applications with NoSQL databases
- Apply various ORM and ODM techniques to build model and repository layers
- Integrate with OpenAPI, Circuit Breaker, ZooKeeper, and OpenTracing to build scalable API applications
- Use Flask middleware to provide CRUD transactions for Flutter-based mobile applications

Who this book is for
This book is for proficient Python developers seeking a deeper understanding of the Flask framework as a solution for tackling enterprise challenges. It is also a great resource for Flask-savvy readers eager to learn more about the framework's advanced capabilities and new features.

โœฆ Table of Contents


Mastering Flask Web and API Development
Contributors
About the author
About the reviewers
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Share Your Thoughts
Download a free PDF copy of this book
Part 1:Learning the Flask 3.x Framework
1
A Deep Dive into the Flask Framework
Technical requirements
Setting up the project baseline
Installing the latest Python version
Installing the Visual Studio (VS) Code editor
Creating the virtual environment
Installing the Flask 3.x libraries
Creating the Flask project
Creating routes and navigations
Creating static URLs
Assigning multiple URLs
Applying path variables
Assigning URLs externally
Implementing class-based views
Managing request and response data
Retrieving the request object
Creating the response object
Implementing page redirection
Implementing view templates
Creating web forms
Building the data layer with PostgreSQL
Setting up database connectivity
Implementing the repository layer
Creating the service layer
Managing the project structure
Building the directory structure
Setting up a development environment
Implementing the main.py module
Creating environment variables
Summary
2
Adding Advanced Core Features
Technical requirements
Structuring huge and scalable projects
Using the application factory
Using the Blueprint
Utilizing both the application factory and the Blueprint
Applying object-relational mapping (ORM)
Setting up the database connectivity
Building the model layer
Implementing the repository layer
Configuring the logging mechanism
Creating user sessions
Managing session data
Clearing all session data
Applying flash messages
Utilizing some advanced Jinja2 features
Applying with-blocks and macros
Applying filters
Adding comments
Implementing error-handling solutions
Using the register_error_handler method
Applying the @errorhandler decorator
Creating custom exceptions
Managing built-in exceptions
Triggering the error handlers
Adding static resources
Accessing the assets in the templates
Summary
3
Creating REST Web Services
Technical requirements
Setting up a RESTful application
Implementing API endpoints
Managing requests and responses
Utilizing response encoders and decoders
Filtering API requests and responses
Handling exceptions
Consuming API endpoints
Summary
4
Utilizing Flask Extensions
Technical requirements
Applying database migration with Flask-Migrate
Installing Flask-Migrate and Flask-SQLAlchemy
Setting up the Alembic configuration
Creating the migrations
Applying the database changes
Designing the UI using Bootstrap-Flask
Setting up the UI module
Applying the Bootstrap files and assets
Utilizing built-in features
Building Flask forms with Flask-WTF
Creating the form models
Rendering the forms
Applying CSRF
Submitting the form
Validating form fields
Building RESTful services with Flask-RESTful
Implementing session handling with Flask-Session
Applying caching using Flask-Caching
Adding mail features using Flask-Mail
Summary
Part 2:Building Advanced Flask 3.x Applications
5
Building Asynchronous Transactions
Technical requirements
Creating asynchronous Flask components
Implementing asynchronous views and endpoints
Implementing the async before_request and after_request handlers
Creating asynchronous error handlers
Building an asynchronous SQLAlchemy repository layer
Setting up the DB connectivity
Building the asynchronous repository layer
Utilizing the asynchronous DB transactions
Implementing async transactions with asyncio
Utilizing asynchronous signal notifications
Constructing background tasks with Celery and Redis
Setting up the Celery task queue
Installing the Redis DB
Setting up the Celery client configuration
Creating the Client instance
Implementing the Celery tasks
Running the Celery worker server
Utilizing the Celery tasks
Building WebSockets with asynchronous transactions
Creating the client-side application
Creating server-side transactions
Creating a Flask API client application
Implementing asynchronous SSE
Implementing the message publisher
Building the server push
Applying reactive programming with RxPy
Choosing Quart over Flask 2.x
Summary
6
Developing Computational and Scientific Applications
Technical requirements
Uploading CSV and XLSX documents for computing
Using the pandas module for data and graphical analysis
Utilizing the DataFrame
Rendering graphs and charts using matplotlib
Rendering multiple line graphs
Rendering a pie chart from a CSV file
Rendering multiple Axes plots
Implementing symbolic computation with visualization
Solving linear equations
Solving non-linear formulas
Finding solutions for a linear system
Plotting mathematical expressions
Creating and rendering LaTeX documents
Rendering LaTeX documents
Creating LaTeX documents
Building graphical charts with frontend libraries
Plotting with Chart.js
Creating graphs with Plotly
Visualizing data using Bokeh
Building real-time data plots using WebSocket and SSE
Utilizing the WebSocket
Using SSE
Using asynchronous background tasks for resource-intensive computations
Incorporating Julia packages with Flask
Creating a custom Julia package
Configuring Julia accessibility in a Flask project
Implementing Julia functions in the package
Creating the Julia service module
Summary
7
Using Non-Relational Data Storage
Technical requirements
Managing non-relational data using Apache HBase
Designing HBase tables
Setting up the baseline requirements
Configuring Apache Hadoop
Configuring Zookeeper and Apache HBase
Setting up the HBase shell
Creating the HBase tables
Establishing an HBase connection
Building the repository layer
Applying a repository to API functions
Running the thrift server
Utilizing the column storage of Apache Cassandra
Designing Cassandra tables
Installing and configuring Apache Cassandra
Running the CQL shell client
Establishing a database connection
Building the model layer
Implementing the repository layer
Storing search data in Redis
Installing the Redis server
Understanding the Redis database
Establishing a database connection
Implementing the model layer
Building the repository layer
Handling BSON-based documents with MongoDB
Installing and configuring the MongoDB server
Establishing a database connection
Building the model layer
Implementing the repository
Managing key-based JSON documents with Couchbase
Installing and configuring the database instance
Setting up the server connection
Creating the repository layer
Establishing a data relationship with Neo4J
Installing Neo4J Desktop
Establishing a connection to the database
Implementing the repository
Summary
8
Building Workflows with Flask
Technical requirements
Building workflows with Celery tasks
Creating task signatures
Utilizing Celery primitives
Implementing a sequential workflow
Passing inputs to signatures
Running independent and parallel tasks
Using callbacks to manage task results
Creating BPMN and non-BPMN workflows with SpiffWorkflow
Setting up the development environment
Creating a BPMN diagram
Implementing the BPMN workflow
Distinguishing between workflow specifications and instances
Identifying between task specifications and instances
Passing form data to UserTask
Adding input variables to ScriptTask
Managing the result of the workflow
Implementing a non-BPMN workflow
Running a non-BPMN workflow
Building service tasks with the Zeebe/Camunda platforms
Setting up the Zeebe server
Installing the pyzeebe library
Creating a BPMN diagram for pyzeebe
Creating a pyzeebe worker
Implementing the pyzeebe client
Building API endpoints
Using Airflow 2.x in orchestrating API endpoints
Installing and configuring Airflow 2.x
Creating tasks
Utilizing Airflow built-in REST endpoints
Implementing workflows using Temporal.io
Setting up the environment
Implementing activities and a workflow
Building a worker
Running activities
Summary
9
Securing Flask Applications
Technical requirements
Adding protection from web vulnerabilities
Applying form validation to request data
Sanitizing form inputs
Securing response data
Rendering Jinja2 variables
Adding security response headers
Using HTTPS to run request/response transactions
Managing user credentials
Encrypting user passwords
Using sqlalchemy_utils for encrypted columns
Utilizing the server-side sessions
Implementing web form authentication
Preventing CSRF attacks
Implementing user authentication and authorization
Utilizing the Flask-HTTPAuth module
Utilizing the Authlib module
Controlling the view or API access
Summary
Part 3:Testing, Deploying, and Building Enterprise-Grade Applications
10
Creating Test Cases for Flask
Technical requirements
Creating test cases for web views, repository classes, and native services
Testing the model classes
Testing the repository classes
Testing the native services
Testing the view functions
Applying the monkey patching
Creating test cases for components in application factory and Blueprints
Testing ORM transactions
Testing API functions
Implementing exception testing
Creating test cases for asynchronous components
Testing asynchronous views and API endpoint function
Testing the asynchronous repository layer
Testing Celery tasks
Testing asynchronous file upload
Creating test cases for secured API and web components
Testing secured API functions
Testing HTTP Basic authentication
Testing web logins
Creating test cases for MongoDB transactions
Creating test cases for WebSockets
Summary
11
Deploying Flask Applications
Technical requirements
Getting ready for deployment
Classes and methods for the standard Peewee ORM
Classes and methods for the Async Peewee ORM
Running the application on Gunicorn and uWSGI
Using the Gunicorn server
Using uWSGI
Deploying the application to Uvicorn
Deploying the application on the Apache HTTP Server
Deploying the application on Docker
Using Docker Compose
Deploying the application on Kubernetes
Creating an API gateway using NGINX
Summary
12
Integrating Flask with Other Tools and Frameworks
Technical requirements
Implementing microservice applications involving FastAPI, Django, and Tornado
Adding the Flask sub-application
Adding the FastAPI sub-application
Adding the Django sub-application
Putting it all together with Tornado
Implementing Flask instrumentation
Applying OpenAPI 3.x specification with Swagger
Providing REST services to a Flutter mobile application
Consuming REST endpoints with a React application
Building a GraphQL application
Summary
Index
Why subscribe?
Other Books You May Enjoy
Packt is searching for authors like you
Share Your Thoughts
Download a free PDF copy of this book


๐Ÿ“œ SIMILAR VOLUMES


Mastering Flask Web and API Development:
โœ Sherwin John C. Tragura ๐Ÿ“‚ Library ๐Ÿ“… 2024 ๐Ÿ› Packt Publishing ๐ŸŒ English

<p><span>Discover how to construct API and web components, build enterprise-grade applications, design and implement unit and behavioral testing, and plan deployment strategies for scalable Flask 3 applications</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Implement web and API app

Mastering REST APIs: Boosting Your Web D
โœ Sivaraj Selvaraj ๐Ÿ“‚ Library ๐Ÿ“… 2024 ๐Ÿ› Apress ๐ŸŒ English

Embark on a transformative journey into the nuances of API design and implementation. This comprehensive guide will equip you with the prowess to craft APIs that exemplify excellence, optimize performance, fortify security, and elevate user experience. From grasping the core tenets of REST archit