0%

Book Description

Learn to build modern, secure, highly available web MVC applications and API's using Python`s Flask framework.

Key Features

  • Create production-ready MVC and REST API with the dynamic features of Flask
  • Utilize the various extensions like Flask-JWT and Flask-SQLAlchemy to develop powerful applications
  • Deploy your flask application on real-world platforms like AWS and Heroku on VM's or Docker containers

Book Description

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

You'll begin by learning about the installation of Flask and basic concepts such as MVC and accessing a database using an ORM. You will learn how to structure your application so that it can scale to any size with the help of Flask Blueprints. You'll then learn how to use Jinja2 templates with a high level of expertise. You will also learn how to develop with SQL or NoSQL databases, and how to develop REST APIs and JWT authentication. Next, you'll move on to build role-based access security and authentication using LDAP, OAuth, OpenID, and database. Also learn how to create asynchronous tasks that can scale to any load using Celery and RabbitMQ or Redis. You will also be introduced to a wide range of Flask extensions to leverage technologies such as cache, localization, and debugging. You will learn how to build your own Flask extensions, how to write tests, and how to get test coverage reports. Finally, you will learn how to deploy your application on Heroku and AWS using various technologies, such as Docker, CloudFormation, and Elastic Beanstalk, and will also learn how to develop Jenkins pipelines to build, test, and deploy applications.

What you will learn

  • Develop a Flask extension using best practices
  • Implement various authentication methods: LDAP, JWT, Database, OAuth, and OpenID
  • Learn how to develop role-based access security and become an expert on Jinja2 templates
  • Build tests for your applications and APIs
  • Install and configure a distributed task queue using Celery and RabbitMQ
  • Develop RESTful APIs and secure REST API's
  • Deploy highly available applications that scale on Heroku and AWS using Docker or VMs

Who this book is for

The ideal target audience for this book would be Python developers who want to use Flask and its advanced features to create Enterprise grade and lightweight applications. The book is for those who have some exposure of Flask and want to take it from introductory to master level.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Mastering Flask Web Development Second Edition
  3. Packt Upsell
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Getting Started
    1. Version control with Git
      1. Installing Git
        1. Git on Windows
      2. Git basics
      3. Git branches and flow
    2. Python package management with pip
      1. Installing the Python package manager on Windows
      2. Installing pip Python package manager on macOS X and Linux
      3. Pip basics
    3. Dependency sandboxing with virtualenv
      1. Virtualenv basics
    4. Setting up Docker
    5. The beginning of our project
      1. Simple application
      2. Project structure
      3. Using Flask's command-line interface
    6. Summary
  7. Creating Models with SQLAlchemy
    1. Setting up SQLAlchemy
      1. Python packages
      2. Flask SQLAlchemy
    2. Our first model
      1. Creating the user table
    3. CRUD
      1. Creating models
      2. Reading models
        1. Filtering queries
      3. Updating models
      4. Deleting models
    4. Relationships between models
      1. One-to-many relationship
      2. Many-to-many relationship
    5. Constraints and indexing
    6. The convenience of SQLAlchemy sessions
    7. Database migrations with Alembic
    8. Summary
  8. Creating Views with Templates
    1. Jinja's syntax
      1. Filters
        1. The default filter
        2. The escape filter
        3. The float filter
        4. The int filter
        5. The join filter
        6. The length filter
        7. The round filter
        8. The safe filter
        9. The title filter
        10. The tojson filter
        11. The truncate filter
        12. Custom filters
      2. Comments
      3. Using if statements
      4. Loops
      5. Macros
      6. Flask-specific variables and functions
        1. The config object
        2. The request object
        3. The session object
        4. The url_for() function
        5. The get_flashed_messages() function
    2. Creating our views
      1. The view function
      2. Writing the templates and inheritance
        1. The base template
        2. The child templates
        3. Writing the other templates
    3. Flask WTForms
      1. WTForms basics
      2. Custom validations
      3. Posting comments
    4. Summary
  9. Creating Controllers with Blueprints
    1. Sessions and globals
    2. Request setup and teardown
    3. Error pages
    4. Class-based views
      1. Method class views
    5. Blueprints
    6. Summary
  10. Advanced Application Structure
    1. Modular application
      1. Refactoring the code
    2. Application factories
    3. Summary
  11. Securing Your App
    1. Authentication methods
      1. Basic authentication
      2. Remote-user authentication
      3. LDAP authentication
      4. Database user model authentication
      5. OpenID and OAuth
    2. Flask-Login overview
      1. Setting up
      2. Updating the models
      3. Creating the forms
      4. Protecting your form from spam
      5. Creating views
    3. OpenID
    4. OAuth
    5. Role-based access control (RBAC)
    6. Summary
  12. Using NoSQL with Flask
    1. Types of NoSQL database
      1. Key-value stores
      2. Document stores
      3. Column family stores
      4. Graph databases
    2. RDBMS versus NoSQL
      1. The strengths of RDBMS databases
        1. Data integrity
        2. Speed and scale
        3. Tools
      2. The strengths of NoSQL databases
      3. CAP theorem
      4. What database to use and when
    3. MongoDB in Flask
      1. Installing MongoDB
      2. Setting up MongoEngine
      3. Defining documents
        1. Field types
        2. Types of documents
        3. The meta attribute
      4. CRUD
        1. Create
          1. Write safety
        2. Read
          1. Filtering
        3. Update
        4. Delete
      5. Relationships in NoSQL
        1. One-to-many relationships
        2. Many-to-many relationships
    4. Leveraging the power of NoSQL
    5. Summary
  13. Building RESTful APIs
    1. What is REST?
      1. HTTP
      2. REST definition and best practices
    2. Setting up a RESTful Flask API
    3. JWT authentication
    4. Get requests
      1. Output formatting
      2. Request arguments
    5. Post requests
    6. Put requests
    7. Delete requests
    8. Summary
  14. Creating Asynchronous Tasks with Celery
    1. What is Celery?
    2. Setting up Celery and RabbitMQ
    3. Creating tasks in Celery
    4. Running Celery tasks
      1. Celery workflows
        1. Partials
        2. Callbacks
        3. Group
        4. Chain
        5. Chord
        6. Running tasks periodically
    5. Monitoring Celery
      1. Web-based monitoring with Flower
    6. Creating a reminder app
    7. Creating a weekly digest
    8. Summary
  15. Useful Flask Extensions
    1. Flask CLI
    2. Flask Debug Toolbar
    3. Flask Caching
      1. Caching views and functions
      2. Caching functions with parameters
      3. Caching routes with query strings
      4. Using Redis as a cache backend
      5. Using memcached as a cache backend
    4. Flask Assets
    5. Flask Admin
      1. Creating basic admin pages
      2. Creating database admin pages
      3. Enhancing administration for the post page
      4. Creating file system admin pages
      5. Securing Flask Admin
    6. Flask-Babel
    7. Flask Mail
    8. Summary
  16. Building Your Own Extension
    1. Creating a YouTube Flask extension
      1. Creating a Python package
      2. Creating blog posts with videos
    2. Modifying the response with Flask extensions
    3. Summary
  17. Testing Flask Apps
    1. What are unit tests?
    2. How does testing work?
    3. Unit testing the application
      1. Testing the route functions
      2. Testing security
      3. Testing the REST API 
    4. User interface testing
    5. Test coverage
    6. Test-driven development
    7. Summary
  18. Deploying Flask Apps
    1. Web servers and gateway interfaces
      1. Gevent
      2. Tornado
      3. Nginx and uWSGI
      4. Apache and uWSGI
    2. Deploying on Heroku
      1. Using Heroku Postgres
      2. Using Celery on Heroku
    3. Deploying on Amazon Web Services
      1. Using Flask on Amazon Elastic Beanstalk
      2. Using Amazon RDS
      3. Using Celery with Amazon SQS
    4. Using Docker
      1. Creating Docker images
      2. Docker Compose
      3. Deploying Docker containers on AWS
        1. CloudFormation Basics
        2. Create and update a CloudFormation stack
    5. Building and deploying highly available applications readily
      1. Building and deploying reliably
      2. Creating highly available applications that scale
      3. Monitoring and collecting logs
    6. Summary
  19. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.141.244.153