My Flask Web Development Book is Out!

Posted by
on under

It was a long wait, but my book is finally here! You can now buy Flask Web Development at most online bookstores, and if you are lucky you may also spot it at some brick and mortar retailers.

With the book out in the wild I thought an update is in order. In this post I will give you a summary of what I have done so far with regards to Flask training, and will conclude with the next projects that will be coming in the near future.

Free Flask Tutorials

As you probably know, I wrote the software that powers this blog in Flask, and based on that initial experience with the framework I went on to create many tutorials. In this section you can see an organized list of what's available and where.

The Flask Mega-Tutorial

The Flask Mega-Tutorial was my first tutorial, and is probably the best known. It is comprised of 18 parts, covering many different aspects of web application development with Python and Flask.

If you decide to do this tutorial you should keep in mind that it is about two years old, and it is starting to age a bit. The most important disadvantage is that these articles were written before Flask had support for Python 3, so the code examples need a few minor touches to run on the newer Python releases. The concepts are still valid and apply to Python 3, but the syntax is outdated.

Also important to note is that the organization of this tutorial is not as good as in my more recent efforts, as I started writing it without having designed the complete structure of the course. I basically wrote articles about topics that I was interested at the time. They say that the best way to learn something is to teach it to others, and that has been true for me. The early tutorials and all the questions I receive from readers allowed me to learn more and be able to present topics in a much more organized way in the material I created more recently.

Even with these minor issues people seem to like this tutorial a lot, so it is still a valid option to get a taste of what writing a real application with Flask involves.

Click here to go to the first Mega-Tutorial article

Writing REST APIs with Flask

In between mega-tutorial articles I wrote a shorter series that specifically addresses different aspects of writing RESTful APIs using Flask. This series even covers a bit of Javascript client side development, so it is definitely a great option if you are interested on rich clients and server-side APIs.

Click here to see my REST API articles

Python Web Development With Flask: an O'Reilly Webcast

To promote my book, O'Reilly asked me to do a one hour webcast presentation on a topic of my choice, and I decided to do a beginner's introduction to Flask. In this session you can see my screen as I explain and demonstrate five Flask applications. The code is available on GitHub for you to install and try on your own.

In the last 20 minutes of the presentation I answered questions from the attendees. There were some pretty interesting questions, covering topics such as the Raspberry Pi and comparisons with Node.js, Django and PHP.

Click here to view my O'Reilly webcast

Due to the success of this session I've been asked to present again later this year, on a date still to be determined. If you have any suggestions for topics you would like to hear me discuss let me know below in the comments!

PyCon Videos

I presented two sessions at PyCon 2014 in Montréal. The first is a three and a half hour long tutorial where I explain an entire application, step by step. This is a session directed at people with previous Python experience, but no Flask experience is required.

The second session is directed towards intermediate/advanced developers. In it I show some of the patterns and tricks I use to develop REST APIs with Flask. Some people dubbed this talk "Flask Decorators on Steroids". If you want to know why, you'll have to watch it.

The Book

If you are looking for the latest and greatest in my Flask training material then I hope you will consider my Flask Web Development book.

In this book you follow me through the development of a nicely featured social blogging application, from start to end. Unlike my Mega-Tutorial, the book covers the most recent version of Flask (0.10.1), which has full support for Python 3. I was careful to write the example code in a way that is compatible with Python 2 and Python 3, so indirectly you will also learn about good practices around development of Python code that works on both versions.

The book is available through most online retailers, and also directly from oreilly.com, in print or e-book formats. I have created http://flaskbook.com to provide information about the book. Click the cover below to visit this site:

I thought I'd mention that O'Reilly offers a print + e-book combo option that is great for those that want a paper book but also want to receive the free e-book updates that include corrections and improvements. Also note that unlike the big retailers (Amazon, B&N, etc.) when you buy the e-book from O'Reilly you get DRM-free files in several formats, so you can install copies of the book on your tablet, phone, computer, kindle, nook, etc. And you are also allowed to make personal backups.

OSCON

If you are coming to OSCON this year, then you'll have a chance to meet with me in person. I love this conference, not only because it is great, but also because it is located in my home town, a short 20 minute train ride away. I will be signing free copies of my book at the O'Reilly booth, and will be happy to meet with readers to answer questions or just chat.

The Future

O'Reilly is very pleased with my book, which has generated interest well above their expectations (and mine!). I'm also very happy to be part of the O'Reilly family, so it seemed natural to both that we should continue our association.

The question is what to do next.

I have found from reviews of my book that some people are very interested in learning Flask but don't have the baseline Python experience that is required to use the book. On the other side, I have also seen reviews that say that the book is too basic, that I should have included more advanced stuff.

In discussing this with my editor we have come up with the idea of producing a couple of video tutorials to complement the book. The details are still very sketchy, but I'm thinking one of the videos will start at a pretty basic level and will be centered around a smaller and simpler application. The other video tutorial will cover advanced topics, likely in the area of API development.

The nice thing about videos is that it takes a lot less time to produce than a book. The timelines we are discussing would put these videos out around August or September of this year. (Update: the two Flask training videos are out now, see http://flaskbook.com for more information!)

As always I love to hear your comments, so feel free to let me know your ideas, suggestions or anything else you want to say.

Thanks!

Miguel

Become a Patron!

Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!

29 comments
  • #1 Brad said

    Congratulations! Very nice work. I've been reading the book since the early release version at OReilly and have gotten a lot out of it. Any chance you would do a blog post or two about using Celery? I'm particularly interested (and stumped) about how to set it up with the application factory and blueprints.

  • #2 Cody Scott said

    The code in your REST API is a lot better than in your book. Are you planning on doing another edition of the book? Maybe when Flask 1.0 is finally released?

  • #3 Miguel Grinberg said

    @Cody: The API chapter in the book is meant as an introduction, I did not have space to include complete coverage. As indicated in this article, I plan to produce a video with O'Reilly that will cover RESTful APIs in more detail.

  • #4 Brian Wisti said

    At some point - email or twitter, I forget - you mentioned that you had hoped to include a chapter on creating a Flasky admin interface. That's something I am itching to see. Could one of your videos cover that? A blog post? A link? Something? Oh man the itchiness!

    No but I'm glad and completely unsurprised that the book has been so well-received. It's my favorite Web dev book in quite some time.

  • #5 Miguel Grinberg said

    @Brian: Yeah, you pay attention to what I say, it seems! Turns out at the early stages in the writing of the book I had planned to include a chapter on creating admin interfaces, I even tweeted pictures. But later I decided to remove that chapter from the book, as it did not really include any new server-side topics (it did have a couple interesting things in the handling of forms client-side, though). The good news is that I have that material (and code), so that will be coming in a blog post when I find the time to review it. I'm thinking I can even make it be an extension to Flasky instead of a separate application.

  • #6 Weihong Guan said

    I am reading it. Very good job. much more detail than the mega tutorial.

    There is an error on Chapter 6 Email. In Table 6-1, It should be MAIL_SERVER, not MAIL_HOSTNAME

  • #7 Daniel Ducharme said

    I just bought your book after passing some time in the last couple of weeks on your site with your tutorials and I really like what you do. I am a software architect and developer (especially on iOS) and I'm eager to read it and get started on Flask! Just started Python a year or so ago and I love it!

    Congrats!
    Daniel Ducharme
    LinkedIn: http://www.linkedin.com/pub/daniel-ducharme/8/467/43a

  • #8 Weihong Guan said

    I can not believe that the word ajax is not in the book.

  • #9 Miguel Grinberg said

    @Weihong: :)
    There is a chapter on RESTful APIs, though. The server-side is covered, for the Ajax side you need to look at my tutorials here, or a Javascript/AngularJS/etc. book.

  • #10 Frode Egeland said

    Looks like O'Reilley have removed your webcast..
    I'm getting:
    "Python Web Development with Flask
    This presentation is no longer available."

    Is it available anywhere else? Would like to see it, as I've followed your megatutorial most of the way through..
    Will be getting your book soon! :)

  • #11 Miguel Grinberg said

    @Frode: I still see the webcast, maybe it was a temporary error?

  • #12 Bjorn said

    Hi Miguel,
    The tutorials are really well written, but I hit a wall of problems after being forced to use py3k. What are the odds for an update?
    May I also propose that you write an introduction on how to host multiple sites on a flask server. For example fossil-scm's scgi server and your existing microblog. That would be a great combination.

  • #13 Miguel Grinberg said

    @Bjorn: Yes, as I mention above the mega-tutorial was written at a time Flask did not support Python 3. I may revise the code to make it Py3 compatible at some point, the changes are minimal though.
    The easiest way to host multiple sites is by running each application on a different port, so for example, you can have your Flask app running on 5000 and the other app running on 8000. You can then install nginx on the default port 80 and configure it to be a reverse proxy for these two apps. To differentiate URLs for the two apps you can use different subdomains, or you can add a component to the URL.

  • #14 Oliver said

    Thanks for your book, the linked videos and your very helpful blog.

    I'm, like Brad, very interested in using Celery with Flask. But the example on the Flask Website isn't very helpful. Did you work with Flask and Celery? Could you post an example (or send my an email) how to use Flask with an existing Celery setup (tasks are defined, worker is up and running; like in the Celery First/Second Step tutorial).

    That would be very, very nice.

    Thanks in advance,
    Oliver

  • #15 Miguel Grinberg said

    @Oliver: I don't have any public examples to share. Not sure if this is exactly what you want, but have a look at https://github.com/iwootten/celery-socketio. This is a Flask application that monitors Celery tasks using my Flask-SocketIO extension.

  • #16 Marcus M. Darden said

    I loved the Mega Tutorial, and the book was a great leap past that!

    I incorporated the new "build targets" method from your config.py in the book. My project has some information that needs to be pre-populated into my database(s), and I was looking for some help with making a manager command that will populate all 3 targets' databases.

    Where's the best place to post a question?

  • #17 Miguel Grinberg said

    @Marcus: the flasky application featured in my book has a manage.py custom command that sets up the application, including adding a set of predetermined user roles to the database. See https://github.com/miguelgrinberg/flasky/blob/master/manage.py#L65.

  • #18 Akin said

    Hi Miguel,

    I'm a Python enthusiast, picked up the language mid last year. In the interest of brushing up my development skills i was advised to learn using the Flask framework in the development of web applications, due to its minimalist approach.

    I went ahead and bought your "Flask Web Development" book and most recently your "An Introduction to Flask" videos. I guess for me, I got a bit lost by the time I got to the chapters that dealt with building a blog application, there seem to be a disconnect, in which i'm kept thinking i had to revisit previous chapters in order to grasp concepts that were being discussed.
    It would have been nice if the blog project was actually started from scratch. In light of this, i decided to purchase your videos, which i am looking forward to jump into this weekend :)

    Can you kindly give me your personal thoughts on the following approach. I'm looking to brush up my Python + Flask skills by setting out on a side project. I'm thinking of creating a Flask CMS system, do you think this might be a Herculean task/project to tackle per a beginner/newbie ?

  • #19 Miguel Grinberg said

    @Akin: the blog is started from scratch, you can see the progression in the commit list in Github. That said, the book is targeted at intermediate Python experience, so I'm sorry if it wasn't what you expected. The introduction video will help you with the basic Flask concepts.

    Doing a Flask CMS is a good project, but you can make it an easy or a hard project depending on what your goals are. My recommendation is that you aim for something simple for your version 1, maybe a simple admin panel where you can add/remove/edit pages plus the rendered pages themselves. Then you can add more sophisticated functions in version 2 and on. Good luck!

  • #20 Tim Johnson said

    The shell results differ for example 5-7.
    python hello.py

    app
    <Flask 'hello'>
    db

    <h2>Correct path and URI to sqlite file</h2>

    User
    <class 'hello.User'>
    From the book

    <hr />

    python hello.py

    app
    <Flask 'app'>
    db

    <h2>Correct path and URI to sqlite file</h2>

    User
    <class 'app.User'>
    On my machine

    <hr />

    python hello.py shell

    app
    <Flask 'hello'>
    db

    <h2>Correct path and URI to sqlite file</h2>

    User
    <class '__main__.User'>

    <hr />

    1)Why the differences?
    2)Is the session from my machine the correct one?
    Thanks

  • #21 Miguel Grinberg said

    @Tim: The output that you get is correct. I inadvertently left this example in an outdated state in the book.

  • #22 Rodolfo Lugo said

    Hi Miguel.

    Some months ago I found your blog for my first Movil-app with Ionic+Flask.

    I follow your authentication token guide. (its very good!). In that project I have problems with the MysqlConnections, because the server return the error "2006 server has gone away".

    At this day, I can't fix that problem in that project....I think have a bad mysql configuration or bad mysql connection/petitions from my python code...

    Now I have a new project and I want to make it with flask but I don't want repeat this problem in my new project, Do you have any suggestion for database configuration? what is the correct form who you recommend for make request a the db?. What database recommends? in your book have examples about it?

    Thanks for yours tutorials, are awesome!

  • #23 Miguel Grinberg said

    @Rodolfo: In the book I use SQLAlchemy to access the database, and this gives me some freedom to choose any of the databases that SQLAlchemy supports. As far as the "server has gone away" message, not sure where that comes from, you should inspect the MySQL log to see if there are any clues there.

  • #24 Yunus Ansari Howarth said

    I have been following your book and could not figure out to change my database to mysql

    The line I tried to change was from Chapter 5: Databases (page 53)

    base dir = os.path.abspath(os.path.dirname(file))

    app=Flask(name)
    app.config[SQLALCHEMY_DATABASE_URI'] =\
    'sql:///' + os.path.join(based, 'data.sqlite')

    I would like it to go to 'mysql//root:root@localhost/test

    I believe I'm just not understanding properly at the moment. Can you assist?

  • #25 Miguel Grinberg said

    @Yunus: you can check the sqlalchemy documentation to find out how to construct database URLs for other databases. Later in the book you will see how to connect to a Postgres database, for example. Here is the documentation for MySQL: http://docs.sqlalchemy.org/en/latest/dialects/mysql.html

Leave a Comment