Flask: Building Python Web Services

Unleash the full potential of the Flask web framework by creating small to large and powerful web applications
Preview in Mapt

Flask: Building Python Web Services

Gareth Dwyer, Shalabh Aggarwal, Jack Stouffer

1 customer reviews
Unleash the full potential of the Flask web framework by creating small to large and powerful web applications
Mapt Subscription
FREE
$29.99/m after trial
eBook
$56.00
RRP $79.99
Save 29%
Print + eBook
$99.99
RRP $99.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$56.00
$99.99
$29.99p/m after trial
RRP $79.99
RRP $99.99
Subscription
eBook
Print + eBook
Start 30 Day Trial

Frequently bought together


Flask: Building Python Web Services Book Cover
Flask: Building Python Web Services
$ 79.99
$ 56.00
Building RESTful Python Web Services with Django [Video] Book Cover
Building RESTful Python Web Services with Django [Video]
$ 124.99
$ 106.25
Buy 2 for $35.00
Save $169.98
Add to Cart
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 

Book Details

ISBN 139781787288225
Paperback770 pages

Book Description

Are you a fan of Python? Want to use it to create powerful web applications? Then Flask is the perfect choice for you. This course will take you through the intricacies of the Flask Microframework, covering all it's components and elements and how to integrate it with useful third party libraries. Dive deep into what Flask has to offer and then you will create multiple Python apps from scratch on your own.

The first module will introduce you to web development using Flask to building fully functional web applications. Hands-on and pragmatic, this tutorial goes right to the crux of Flask by showing you how to build challenging real-world applications.

The second module introduces you to a number of recipes that will help you understand the power of Flask and its extensions. Start by seeing the different configurations that a Flask application can make use of. By the end of this module, you will have gained all the knowledge required to write Flask applications in the best possible way, and scale them with best practices.

The final module will walk you through advanced Flask topics while providing practical examples of for all your lessons learned. The module closes with a discussion of the different platforms that are available to deploy a Flask app on, the pros and cons of each one, and how to deploy on each one.

This Learning Path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products:

  • Flask By-Example: Gareth Dwyer
  • Flask Framework Cookbook: Shalabh Aggarwal
  • Mastering Flask: Jack Stouffer

Table of Contents

Chapter 1: Hello, World!
Introducing Flask
Creating our development environment
Writing "Hello, World!"
Deploying our application to production
Summary
Chapter 2: Getting Started with Our Headlines Project
Setting up our project and a Git repository
Creating a new Flask application
Introduction to RSS and RSS feeds
Summary
Chapter 3: Using Templates in Our Headlines Project
Introducing Jinja
Basic use of Jinja templates
Advanced use of Jinja templates
Summary
Chapter 4: User Input for Our Headlines Project
Getting user input using HTTP GET
Getting user input using HTTP POST
Adding weather and currency data
Summary
Chapter 5: Improving the User Experience of Our Headlines Project
Adding cookies to our Headlines application
Adding CSS to our Headlines application
Summary
Chapter 6: Building an Interactive Crime Map
Setting up a new Git repository
Understanding relational databases
Installing and configuring MySQL on our VPS
Creating our Crime Map database in MySQL
Creating a basic database web application
Summary
Chapter 7: Adding Google Maps to Our Crime Map Project
Running a database application locally
Adding an embedded Google Maps widget to our application
Adding an input form for new crimes
Displaying existing crimes on our map
Summary
Chapter 8: Validating User Input in Our Crime Map Project
Choosing where to validate
Trying out an XSS example
Validating and sanitizing
Summary
Chapter 9: Building a Waiter Caller App
Setting up a new Git repository
Using Bootstrap to kick-start our application
Adding user account control to our application
Summary
Chapter 10: Template Inheritance and WTForms in Waiter Caller Project
Adding the Account and Dashboard pages
Shortening URLs using the bitly API
Adding functionality to handle attention requests
Adding user feedback with WTForms
Summary
Chapter 11: Using MongoDB with Our Waiter Caller Project
Introducing MongoDB
Installing MongoDB
Using the MongoDB shell
Introducing PyMongo
Testing our application in production
Adding some finishing touches
Summary
Chapter 12: Flask Configurations
Introduction
Environment setup with virtualenv
Handling basic configurations
Class-based settings
Organization of static files
Being deployment specific with instance folders
Composition of views and models
Creating a modular web app with blueprints
Making a Flask app installable using setuptools
Chapter 13: Templating with Jinja2
Introduction
Bootstrap layout
Block composition and layout inheritance
Creating a custom context processor
Creating a custom Jinja2 filter
Creating a custom macro for forms
Advanced date and time formatting
Chapter 14: Data Modeling in Flask
Introduction
Creating a SQLAlchemy DB instance
Creating a basic product model
Creating a relational category model
Database migration using Alembic and Flask-Migrate
Model data indexing with Redis
Opting the NoSQL way with MongoDB
Chapter 15: Working with Views
Introduction
Writing function-based views and URL routes
Class-based views
URL routing and product-based pagination
Rendering to templates
Dealing with XHR requests
Decorator to handle requests beautifully
Creating custom 404 and 500 handlers
Flashing messages for better user feedback
SQL-based searching
Chapter 16: Webforms with WTForms
Introduction
SQLAlchemy model data as form representation
Validating fields on the server side
Creating a common forms set
Creating custom fields and validation
Creating a custom widget
Uploading files via forms
Cross-site Request Forgery protection
Chapter 17: Authenticating in Flask
Introduction
Simple session-based authentication
Authenticating using the Flask-Login extension
Using OpenID for authentication
Using Facebook for authentication
Using Google for authentication
Using Twitter for authentication
Chapter 18: RESTful API Building
Introduction
Creating a class-based REST interface
Creating an extension-based REST interface
Creating a SQLAlchemy-independent REST API
A complete REST API example
Chapter 19: Admin Interface for Flask Apps
Introduction
Creating a simple CRUD interface
Using the Flask-Admin extension
Registering models with Flask-Admin
Creating custom forms and actions
WYSIWYG for textarea integration
Creating user roles
Chapter 20: Internationalization and Localization
Introduction
Adding a new language
Lazy evaluation and the gettext/ngettext functions
Global language-switching action
Chapter 21: Debugging, Error Handling, and Testing
Introduction
Setting up basic file logging
Sending e-mails on the occurrence of errors
Using Sentry to monitor exceptions
Debugging with pdb
Creating our first simple test
Writing more tests for views and logic
Nose library integration
Using mocking to avoid real API access
Determining test coverage
Using profiling to find bottlenecks
Chapter 22: Deployment and Post Deployment
Introduction
Deploying with Apache
Deploying with uWSGI and Nginx
Deploying with Gunicorn and Supervisor
Deploying with Tornado
Using Fabric for deployment
S3 storage for file uploads
Deploying with Heroku
Deploying with AWS Elastic Beanstalk
Application monitoring with Pingdom
Application performance management and monitoring with New Relic
Chapter 23: Other Tips and Tricks
Introduction
Full-text search with Whoosh
Full-text search with Elasticsearch
Working with signals
Using caching with your application
E-mail support for Flask applications
Understanding asynchronous operations
Working with Celery
Chapter 24: Getting Started
Version control with Git
Python package management with pip
Dependency sandboxing with virtualenv
The beginning of our project
Summary
Chapter 25: Creating Models with SQLAlchemy
Setting up SQLAlchemy
Our first model
CRUD
Relationships between models
The convenience of SQLAlchemy sessions
Database migrations with Alembic
Summary
Chapter 26: Creating Views with Templates
Jinja's syntax
Creating our views
Flask WTForms
Summary
Chapter 27: Creating Controllers with Blueprints
Request setup, teardown, and application globals
Error pages
Class-based views
Blueprints
Summary
Chapter 28: Advanced Application Structure
The project as a module
Application factories
Summary
Chapter 29: Securing Your App
Setting up
Using the session
Flask Login
Summary
Chapter 30: Using NoSQL with Flask
Types of NoSQL databases
RDBMS versus NoSQL
MongoDB in Flask
Leveraging the power of NoSQL
Summary
Chapter 31: Building RESTful APIs
What is REST
Setting up a RESTful Flask API
GET requests
POST requests
PUT requests
DELETE requests
Summary
Chapter 32: Creating Asynchronous Tasks with Celery
What is Celery?
Setting up Celery and RabbitMQ
Creating tasks in Celery
Running Celery tasks
Monitoring Celery
Creating a reminder app
Creating a weekly digest
Summary
Chapter 33: Useful Flask Extensions
Flask Script
Flask Debug Toolbar
Flask Cache
Flask Assets
Flask Admin
Flask Mail
Summary
Chapter 34: Building Your Own Extension
Creating a YouTube Flask extension
Modifying the response with Flask extensions
Summary
Chapter 35: Testing Flask Apps
What are unit tests?
How does testing work?
Unit testing the application
User interface testing
Test coverage
Test-driven development
Summary
Chapter 36: Deploying Flask Apps
Deploying on your own server
Deploying on Heroku
Deploying on Amazon web services
Summary

What You Will Learn

  • Build three web applications from the ground up using the powerful Python micro framework, Flask.
  • Extend your applications to build advanced functionality, such as a user account control system using Flask-Login
  • Learn about web application security and defend against common attacks, such as SQL injection and XSS
  • Integrate with technologies like Redis, Sentry, MongoDB and so on
  • Build applications with integrations to most of the login mechanisms available
  • Don't just stop at development. Learn about deployment and post-deployment
  • Use SQLAlchemy to programmatically query a database
  • Develop a custom Flask extension

Authors

Table of Contents

Chapter 1: Hello, World!
Introducing Flask
Creating our development environment
Writing "Hello, World!"
Deploying our application to production
Summary
Chapter 2: Getting Started with Our Headlines Project
Setting up our project and a Git repository
Creating a new Flask application
Introduction to RSS and RSS feeds
Summary
Chapter 3: Using Templates in Our Headlines Project
Introducing Jinja
Basic use of Jinja templates
Advanced use of Jinja templates
Summary
Chapter 4: User Input for Our Headlines Project
Getting user input using HTTP GET
Getting user input using HTTP POST
Adding weather and currency data
Summary
Chapter 5: Improving the User Experience of Our Headlines Project
Adding cookies to our Headlines application
Adding CSS to our Headlines application
Summary
Chapter 6: Building an Interactive Crime Map
Setting up a new Git repository
Understanding relational databases
Installing and configuring MySQL on our VPS
Creating our Crime Map database in MySQL
Creating a basic database web application
Summary
Chapter 7: Adding Google Maps to Our Crime Map Project
Running a database application locally
Adding an embedded Google Maps widget to our application
Adding an input form for new crimes
Displaying existing crimes on our map
Summary
Chapter 8: Validating User Input in Our Crime Map Project
Choosing where to validate
Trying out an XSS example
Validating and sanitizing
Summary
Chapter 9: Building a Waiter Caller App
Setting up a new Git repository
Using Bootstrap to kick-start our application
Adding user account control to our application
Summary
Chapter 10: Template Inheritance and WTForms in Waiter Caller Project
Adding the Account and Dashboard pages
Shortening URLs using the bitly API
Adding functionality to handle attention requests
Adding user feedback with WTForms
Summary
Chapter 11: Using MongoDB with Our Waiter Caller Project
Introducing MongoDB
Installing MongoDB
Using the MongoDB shell
Introducing PyMongo
Testing our application in production
Adding some finishing touches
Summary
Chapter 12: Flask Configurations
Introduction
Environment setup with virtualenv
Handling basic configurations
Class-based settings
Organization of static files
Being deployment specific with instance folders
Composition of views and models
Creating a modular web app with blueprints
Making a Flask app installable using setuptools
Chapter 13: Templating with Jinja2
Introduction
Bootstrap layout
Block composition and layout inheritance
Creating a custom context processor
Creating a custom Jinja2 filter
Creating a custom macro for forms
Advanced date and time formatting
Chapter 14: Data Modeling in Flask
Introduction
Creating a SQLAlchemy DB instance
Creating a basic product model
Creating a relational category model
Database migration using Alembic and Flask-Migrate
Model data indexing with Redis
Opting the NoSQL way with MongoDB
Chapter 15: Working with Views
Introduction
Writing function-based views and URL routes
Class-based views
URL routing and product-based pagination
Rendering to templates
Dealing with XHR requests
Decorator to handle requests beautifully
Creating custom 404 and 500 handlers
Flashing messages for better user feedback
SQL-based searching
Chapter 16: Webforms with WTForms
Introduction
SQLAlchemy model data as form representation
Validating fields on the server side
Creating a common forms set
Creating custom fields and validation
Creating a custom widget
Uploading files via forms
Cross-site Request Forgery protection
Chapter 17: Authenticating in Flask
Introduction
Simple session-based authentication
Authenticating using the Flask-Login extension
Using OpenID for authentication
Using Facebook for authentication
Using Google for authentication
Using Twitter for authentication
Chapter 18: RESTful API Building
Introduction
Creating a class-based REST interface
Creating an extension-based REST interface
Creating a SQLAlchemy-independent REST API
A complete REST API example
Chapter 19: Admin Interface for Flask Apps
Introduction
Creating a simple CRUD interface
Using the Flask-Admin extension
Registering models with Flask-Admin
Creating custom forms and actions
WYSIWYG for textarea integration
Creating user roles
Chapter 20: Internationalization and Localization
Introduction
Adding a new language
Lazy evaluation and the gettext/ngettext functions
Global language-switching action
Chapter 21: Debugging, Error Handling, and Testing
Introduction
Setting up basic file logging
Sending e-mails on the occurrence of errors
Using Sentry to monitor exceptions
Debugging with pdb
Creating our first simple test
Writing more tests for views and logic
Nose library integration
Using mocking to avoid real API access
Determining test coverage
Using profiling to find bottlenecks
Chapter 22: Deployment and Post Deployment
Introduction
Deploying with Apache
Deploying with uWSGI and Nginx
Deploying with Gunicorn and Supervisor
Deploying with Tornado
Using Fabric for deployment
S3 storage for file uploads
Deploying with Heroku
Deploying with AWS Elastic Beanstalk
Application monitoring with Pingdom
Application performance management and monitoring with New Relic
Chapter 23: Other Tips and Tricks
Introduction
Full-text search with Whoosh
Full-text search with Elasticsearch
Working with signals
Using caching with your application
E-mail support for Flask applications
Understanding asynchronous operations
Working with Celery
Chapter 24: Getting Started
Version control with Git
Python package management with pip
Dependency sandboxing with virtualenv
The beginning of our project
Summary
Chapter 25: Creating Models with SQLAlchemy
Setting up SQLAlchemy
Our first model
CRUD
Relationships between models
The convenience of SQLAlchemy sessions
Database migrations with Alembic
Summary
Chapter 26: Creating Views with Templates
Jinja's syntax
Creating our views
Flask WTForms
Summary
Chapter 27: Creating Controllers with Blueprints
Request setup, teardown, and application globals
Error pages
Class-based views
Blueprints
Summary
Chapter 28: Advanced Application Structure
The project as a module
Application factories
Summary
Chapter 29: Securing Your App
Setting up
Using the session
Flask Login
Summary
Chapter 30: Using NoSQL with Flask
Types of NoSQL databases
RDBMS versus NoSQL
MongoDB in Flask
Leveraging the power of NoSQL
Summary
Chapter 31: Building RESTful APIs
What is REST
Setting up a RESTful Flask API
GET requests
POST requests
PUT requests
DELETE requests
Summary
Chapter 32: Creating Asynchronous Tasks with Celery
What is Celery?
Setting up Celery and RabbitMQ
Creating tasks in Celery
Running Celery tasks
Monitoring Celery
Creating a reminder app
Creating a weekly digest
Summary
Chapter 33: Useful Flask Extensions
Flask Script
Flask Debug Toolbar
Flask Cache
Flask Assets
Flask Admin
Flask Mail
Summary
Chapter 34: Building Your Own Extension
Creating a YouTube Flask extension
Modifying the response with Flask extensions
Summary
Chapter 35: Testing Flask Apps
What are unit tests?
How does testing work?
Unit testing the application
User interface testing
Test coverage
Test-driven development
Summary
Chapter 36: Deploying Flask Apps
Deploying on your own server
Deploying on Heroku
Deploying on Amazon web services
Summary

Book Details

ISBN 139781787288225
Paperback770 pages
Read More
From 1 reviews

Read More Reviews

Recommended for You

Building RESTful Python Web Services with Django [Video] Book Cover
Building RESTful Python Web Services with Django [Video]
$ 124.99
$ 106.25
Building RESTful Python Web Services with Tornado [Video] Book Cover
Building RESTful Python Web Services with Tornado [Video]
$ 124.99
$ 106.25
Building RESTful Python Web Services Book Cover
Building RESTful Python Web Services
$ 39.99
$ 28.00
Flask - Building Web Applications Book Cover
Flask - Building Web Applications
$ 124.99
$ 106.25
Building Web Applications with Flask Book Cover
Building Web Applications with Flask
$ 27.99
$ 19.60
ASP.NET Web API: Build RESTful web applications and services on the .NET framework Book Cover
ASP.NET Web API: Build RESTful web applications and services on the .NET framework
$ 29.99
$ 21.00