2016-02-29T06:44:29Z

"Flask At Scale" tutorial at PyCon 2016 in Portland

Pycon 2016 Logo

The tutorial line up for PyCon 2016 in Portland, Oregon has been announced, and I'm excited to be part of it with yet another Flask tutorial. For some odd reason, not all the class information I provided with my proposal was published on the PyCon website, so I want to give you a good overview of the material I plan to cover here, to help you decide if this tutorial is for you.

My Flask tutorial is scheduled for Saturday, May 28th from 9am to 12:20pm. PyCon tutorials have a registration fee of $150 each if purchased ahead of time, or $200 if purchased the same day at the door. Note that tutorial fees are separate and not included in the conference registration. Your tutorial registration also gives you access to lunch on the tutorial day.

If you want to have an idea of what you get from one of my Flask tutorials, here are the two that I gave in past years:


Flask Workshop: A beginner's Flask tutorial I gave at PyCon 2015


Flask By Example: An intermediate Flask tutorial I gave at PyCon 2014

This class that I'm preparing for this year's PyCon is for intermediate and advanced Flask developers looking to learn the patterns and best practices that can help scale a Flask application, both in terms of application size and load. In terms of complexity, this class would go after the two above and will be the most advanced Flask class I have ever given. The topics are divided into two main areas:

  • Large applications: How to organize code, templates and static files in a way that allows the application to grow without becoming a mess.
  • Flask under load: Different ways to deploy a Flask application so that it can handle large numbers of clients.

Below you can see the description and abstract as published on the PyCon website, plus the tentative class outline, which was not published:

Description

Do you think that because Flask is a micro-framework, it must only be good for small, toy-like web applications? Well, not at all! In this tutorial I am going to show you a few patterns and best practices that can take your Flask application to the next level.

Abstract

Can Flask scale? For many, that is the million dollar question. Unfortunately even the Flask official documentation is ambiguous about this topic. Flask is a small, unobtrusive framework that simplifies the interface between your application and the web server. Outside of that, it mostly stays out of your way, so if you need to write an application that can scale, Flask is not going to prevent it, and in fact, it will allow you to freely choose the components of your stack and not impose choices on you like big frameworks tend to do.

In this tutorial session, I will walk you through a list of typical patterns for medium and large applications written in Flask, specifically chosen to highlight scalability patterns and best practices that you will be able to transfer to your own projects. The class will be divided in two main sections, dedicated to scalability of the code (i.e. how to write large applications with Flask) and scalability of the deployed application (i.e. how to handle large numbers of clients).

Outline

  • Introduction (10 min)
  • Large applications (1 hour)
    • How to structure a large application
    • Using Blueprints to organize an application
    • Decorators as a way to simplify application code
    • Combining a web application with a REST API
    • API versioning
  • Flask under load (1 hour)
    • Asynchronous requests
    • Using a Celery job queue
    • Using multiple processes and hosts with a load balancer
    • Using coroutine frameworks such as eventlet or gevent
    • Using WebSocket for server-push and reduced latency
  • Free-form Discussion and Q&A (50 min)

I hope this additional information helps you decide if you want to attend. And by the way, I'm only starting to prepare the material for this class, so I'm happy to accept suggestions for topics I may have not included that fit the theme of the class.

I hope to see you in Portland, either at my tutorial or around the conference!

Miguel

9 comments

  • #1 Fiit said 2016-02-29T07:17:17Z

    Any chance to see it in video / live / replay ? (We do not have the opportunity to go to Portland... sadly) Have a nice day & good conf

  • #2 Marco said 2016-02-29T10:06:18Z

    Hola Miguel! I can`t hardly wait to see this! Greetings from Germany!

  • #3 Miguel Grinberg said 2016-02-29T16:54:44Z

    @Fiit: Yes, the videos of all the tutorials and talks are later posted on youtube.

  • #4 Christophe BAL said 2016-03-01T19:35:27Z

    Thanks for your documents and videos on Flask !

  • #5 newbie said 2016-03-04T11:59:56Z

    i have to admit this blog is a goldmine of high quality and most important practical and easy to follow examples writing just to say, thanks a lot !!

  • #6 Akin said 2016-05-15T07:05:12Z

    Hi Miguel, I have purchased both of your videos on flask (An Introduction to Flask & Building Web APIs with Flask) as well as your book "Flask Web Development", all brilliant pieces of work, which have all been very helpful in my continuous stride, to achieve a strong understanding and ultimately, mastery of the art of software development. I really do wish I could attend your up coming tutorial , as this speaks to an idea for a side project i am planning to embark on. What are your thoughts on building a CMS system based on Flask? My thinking is to build such a system, in order to fulfill two things, 1.) helps me sharpen my skills and knowledge of both the language (Python), my web framework of choice (Flask) and most importantly, 2.) a non trivial project, which makes part of my portfolio, that i can eventually demonstrate to prospective employers. Your candid feedback, will be greatly appreciated.

  • #7 Miguel Grinberg said 2016-05-16T19:02:06Z

    @Akin: Absolutely. It can be a CMS, a blog, or any other kind of non-trivial application.

  • #8 David said 2016-10-14T17:33:42Z

    Hi Miguel. I was in this class on May 28. I've just begun working on a new project and was trying to understand some of the API code. I'm using Postman to test out the users API and I have hit a snag that I don't understand. I'm using v0.1 of the code and trying to create a user. I'm sending a POST to http://localhost:500/api/users, I have two headers set (Accept and Content-Type, both set to application/json). I'm using a raw JSON body containing nickname and password, but I'm getting a 400 error from the app. This same query passes in the tests (it's the third test in test_user). What am I doing wrong? BTW, I also tried using cURL with the same ill result.

  • #9 Miguel Grinberg said 2016-10-15T06:15:27Z

    @David: the only reason I can think of to get a 400 from the create user endpoint is if you haven't included the required information in the body of the request, or maybe you formatted it incorrectly. Make sure you are sending valid JSON, and also that you include nickname and password fields.

Leave a Comment