Flask Blueprints
eBook - ePub

Flask Blueprints

  1. 198 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Flask Blueprints

Book details
Book preview
Table of contents
Citations

About This Book

Dive into the world of the Flask microframework to develop an array of web applications

About This Book

  • Structure, compose, and build powerful Flask HTML-based applications and JSON/XML-based APIs using advanced application design patterns
  • Integrate third-party Flask extensions for tasks such as social authentication, sending emails, and interacting with databases and cache layers
  • Build a series of Flask applications of increasing complexity

Who This Book Is For

If you are a Python web developer who has developed basic Flask applications and now wants to build a series of more complex web applications, then this is the book for you.

What You Will Learn

  • Use the virtualenv Python package to effectively isolate your development environments
  • Convert a simple one-file Flask application into a more full-fledged multi-package application
  • Integrate Flask-Login for simple user authentication, Flask-WTF for forms, and Flask-SQLAlchemy for database interactions
  • Explore URL routing and dispatching in a blueprint structured application
  • Create your own signals and consume them within your application
  • Learn to leverage Werkzeug, the WSGI library that powers much of Flask
  • Implement custom exceptions for handling non-20x response codes
  • Write your own CLI tools for administrative and development tasks of your Flask application using Flask-Script/Click
  • Build your Flask extensions to encapsulate reusable behaviors across your applications
  • Integrate your application with open source JavaScript-based graphing libraries to create simple data visualizations

In Detail

Flask is a small but powerful web development framework for Python. Though Flask is termed a micro-framework, it is no way lacking in functionality; there are many extensions available to Flask which helps it to function at the same level as other large frameworks such as Django and Ruby on Rails.

This book will demonstrate how to develop a series of web application projects with the Python web micro-framework, and leverage extensions and external Python libraries and APIs to extend the development of a variety of larger and more complex web applications.

The book will start by explaining Python's Virtualenv library and how to create and switch between multiple virtual environments. You'll first build an SQL database-backed application, which will use Flask-WTF, Flask-SQLAlchemy, Jinja templates, and other methods. Next you'll move on to a timeline application, built using concepts including pytest-Flask, the Blinker package, data modelling for user timelines, exception handling, and creating and organizing CLI tools.

Moving on, you'll discover how to implement a photo timeline application where you'll explore topics such as writing and running celery tasks, API error handling and testing, and Werkzeug middlewares.

Finally, the book walks you through creating an application which fetches data from GitHub and stores it locally. You will also learn how to install and configure Flask-Click extension.

Style and approach

This book covers how to effectively use the Flask micro-framework to develop a series of web applications. Each chapter focusses on the development of an application increasing in complexity with easy steps to follow.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Flask Blueprints by Joel Perras in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Python. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781784394783
Edition
1

Flask Blueprints


Table of Contents

Flask Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Starting on the Right Foot – Using Virtualenv
Setuptools and pip
Avoiding dependency hell, the Python way
Working with virtualenv
Creating a new virtual environment
Activating and deactivating virtual environments
Adding packages to an existing environment
Uninstalling packages from an existing environment
Simplifying common operations – using the virtualenvwrapper tool
Summary
2. Small to Big – Growing the Flask Application Structure
Your first Flask application structure
From module to package
From package to blueprint
Our first blueprint
Summary
3. Snap – the Code Snippet Sharing Application
Getting started
Flask-SQLAlchemy
Configuring Flask-SQLAlchemy
SQLAlchemy basics
Declarative mapping and Flask-SQLAlchemy
Snap data models
Flask-Login and Flask-Bcrypt for authentication
Flask-WTF – form validation and rendering
Hashing user passwords
Configure an application SECRET_KEY
Hook up the blueprint
Let's run this thing
The data model for snaps
Better defaults with content-sensitive default functions
Snap view handlers
Summary
4. Socializer – the Testable Timeline
Starting off
Application factories
The application context
Instantiating an app object
Unit and functional testing
Social features – friends and followers
Functional and integration testing
Publish/subscribe events with Blinker
Signals from Flask and extensions
Creating custom signals
Graceful handling of exceptions
Functional testing
Your newsfeed
Summary
5. Shutterbug, the Photo Stream API
Starting off
The application factory
Interlude – Werkzeug
Simple APIs with Flask-RESTful
Improved password handling with hybrid attributes
API authentication
Authentication protocols
Getting users
Creating new users
Input validation
API testing
Interlude – Werkzeug middlewares
Back to Shutterbug – uploading photos
File uploads in distributed systems
Testing the photo uploads
Fetching the user's photos
Summary
6. Hublot – Flask CLI Tools
Starting off
The manage.py file
The built-in default commands
The Flask-Script commands across Blueprints
Submanagers
The required and optional arguments
Flask extensions – the basics
When should an extension be used?
Our extension – GitHubber
Summary
7. Dinnerly – Recipe Sharing
First OAuth
Why use OAuth?
Terminology
So what's wrong with OAuth 1.0?
Three-legged authorization
Setting up the application
Declaring our models
Handling OAuth in our views
Creating recipes
Posting recipes to Twitter and Facebook
SQLAlchemy events
Finding common friends
Interlude – database migrations
Alembic
Summary
Index

Flask Blueprints

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2015
Production reference: 1251115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-478-3
www.packtpub.com

Credits

Author
Joël Perras
Reviewers
Shalabh Aggarwal
Christoph Heer
Andreas Porevopoulos
Commissioning Editor
Julian Ursell
Acquisition Editor
Meeta Rajani
Content Development Editor
Shweta Pant
Technical Editor
Bharat Patil
Copy Editor
Tasneem Fatehi
Project Coordinator
Sanjeet Rao
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Disha Haria
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite

About the Author

Joël Perras has been professionally involved in technology and computing for over 12 years. He got his start in the world of programming by attempting to teach himself Java at the tender age of 13 and got his first job at a small web development firm a few years later writing Java Server Pages. The first site he built is still running.
While studying physics and mathematics at McGill University in Montréal, he helped set up a Tier II analysis centre for the Worldwide LHC Computing Grid, which cemented his interest in distributed systems architecture and high performance computing.
Currently, his days are spent building infrastructure and Python applications with the incredible people at Fictive Kin, writing open source code, and trying to lift heavy weights over his head on a regular basis.

About the Reviewers

Shalabh Aggarwal has several years of experience in developing business systems and web applications for small-to-medium scale industries. He started his career working on Python, and although he works on multiple technologies, he remains a Python developer at heart. He is passionate about open source technologies and writes highly readable and quality code.
Shalabh is also active in voluntary training for engineering students on nonconventional and open source topics. When not working with full-time assignments, he acts as a consultant for start-ups on leveraging different technologies. He is pursuing his master's degree in business from IIT Delhi.
Christoph Heer is a passionate Python developer based in Germany. He likes to develop web applications and also tools and systems for infrastructure optimization, management, and monitoring. He is proud to be a part of the great Python community and wishes to have more time for open source contribution.
Andreas Porevopoulos has loved computers and programming since he was in high school and over the years he has developed many apps in different languages and systems, but Python was always his favorite. He has been working as a Full Stack Python developer for the last 7 years and has completed lots of projects in Django and Flask. He believes that these two frameworks are amon...

Table of contents

  1. Flask Blueprints