Category: programming

2017-12-05T17:15:48Z

The Flask Mega-Tutorial Part I: Hello, World!

Welcome! You are about to start on a journey to learn how to create web applications with Python and the Flask framework. In this first chapter, you are going to learn how to set up a Flask project. By the end of this chapter you are going to have a simple Flask web application running on your computer!

11 comments

2017-10-10T15:22:43Z

Implementing User Comments with SQLAlchemy

One of the most basic ways to keep the users of your web application engaged is to give them a space to write comments. These days, there are third-party services pretty much for everything, and comments is not an exception. Disqus and Facebook are popular services that allow you to embed comments into your site.

But what if you don't want to use an external service? In this article, I'm going to show you how I implement comments in Python, using the SQLAlchemy ORM and any of the database engines it supports. I'm going to start with an extremely simple approach, and then will go on to discuss a few advanced implementations with support for multiple levels of replies.

10 comments

2017-09-12T18:24:44Z

Using a Chromebook for Web Development

Google Chromebook

Have you seen anybody using a Chromebook yet? These are slim, lightweight laptops that run ChromeOS, an operating system made by Google that is designed around the Chrome web browser. If you want a laptop that you can use for doing your email, watching Netflix and other tasks you can easily do in a web browser, then a Chromebook is a very good choice, and also cheap, since most models are in the $150-$300 price range.

They also make great travel laptops if you are going on vacation or to a conference. The problem for me is that when I travel, I spend a fair amount of time coding (this is an addiction I do not want to get rid of!). So I decided to buy one and try to configure it in a way that is suitable for web development on the move. In this article I'm going to go over three different approaches to do that.

24 comments

2017-08-23T17:32:00Z

Serverless Deployments of Python APIs

If you are like me, you were starting to get comfortable with the idea of deploying your applications to cloud instances such as EC2s on AWS or droplets on DigitalOcean, when people started to shift away from cloud instances and embrace containers. Maybe now you are getting into containers and Docker, and as is to be expected, the tech world is making a move once again, this time to severless computing. Impossible to ever catch up, right?

In this article I'm going to tell you what a serverless architecture can offer you that the more traditional approaches cannot (and more specifically how it is possible to run your Python web applications without a server!). At the time I'm writing this, AWS has by far the most mature serverless platform, with the Lambda, API Gateway and DynamoDB triad of services at the forefront, so this is the platform I'm going to concentrate on.

AWS Serverless

9 comments

2017-08-07T06:38:45Z

Flask Video Streaming Revisited

Flask Video Streaming Server

Almost three years ago I wrote an article on this blog titled Video Streaming with Flask, in which I presented a very modest streaming server that used a Flask generator view function to stream a Motion-JPEG stream to web browsers. My intention with that article was to show a simple, yet practical use of streaming responses, a not very well known feature in Flask.

That article is extremely popular, but not because it teaches how to implement streaming responses, but because a lot of people want to implement streaming video servers. Unfortunately, my focus when I wrote the article was not on creating a robust video server, so I frequently get questions and requests for advice from those who want to use the video server for a real application and quickly find its limitations. So today I'm going to revisit my streaming video server and describe a few improvements I've made to it.

36 comments

2017-08-01T17:41:59Z

Using Headless Chrome with Selenium

While working on the second edition of my flask book, I was reviewing my Selenium tests, which allow me to automate a web browser and do end-to-end testing. In the current version of the book I recommend running these tests against Firefox. I thought this was a great opportunity to see how Headless Chrome works, as that eliminates the annoying browser window that pops out every time you run the tests.

The results are encouraging. This super short article describes what you need to do to set up Selenium to use the Headless Chrome browser.

15 comments

2017-07-18T20:16:19Z

Cookie Security for Flask Applications

Cookies are the most common attack vector for applications that run on web browsers, yet the topic of how to make cookies secure is frequently overlooked. I touched upon this topic in a few past articles, but today I want to specifically go over all the options Flask and extensions such as Flask-Login and Flask-WTF give you in terms of securing your application against web browser attacks.

Cookie Security

15 comments

2017-07-09T21:15:55Z

The Flask Mega-Tutorial Kickstarter

Chances are, you were introduced to my blog through the Flask Mega-Tutorial, which is by far, the most popular topic on this blog. If you are doing the tutorial now, I'm sure you noticed that a number of things aren't quite as easy anymore. This is unfortunate, but several of the areas the tutorial touches on have seen significant changes since I published the articles.

The tutorial is now five years old, and embarking on a rewrite to bring it to Python 3.6 and current versions of all other technologies is going to require a considerable amount of time and effort. So I have decided to try a little experiment with a Kckstarter. If you haven't seen this yet, have a look at this video:

25 comments

2017-07-03T15:45:28Z

Flask-SocketIO and the User Session

The way user sessions are handled in my Flask-SocketIO extension has always been a pain point for me. I tried to make sessions work almost the same as they work on regular Flask routes, but the "almost" part is what makes it confusing for most people.

In this short article and its companion video, I will try to explain why this is not trivial, and also will go over some improvements I just released that I hope will improve the use cases on which users seem to always trip.

2 comments

2017-06-21T22:15:18Z

Handling Authentication Secrets in the Browser

I gave a talk titled Handling Authentication Secrets in the Browser at Fluent 2017 in San Jose (you can see the slides above). As a complement to the talk, I thought it would be a good idea to write down the main concepts here on the blog as well, for those that weren't at my talk or those that were, but want to study the topic with more time than the 40 minutes I had for my presentation.

2 comments