Beautiful Interactive Tables for your Flask Templates

Posted by
on under

Rendering a table with data in a Flask template is a relatively simple task when the table is short, but can be incredibly hard for larger tables that require features such as sorting, pagination and searching. In this article I'm going to show you how to integrate the dataTables.js library in your templates, which will allow you to create fully featured tables with ease!

How to Get the Code

How to Dockerize a React + Flask Project

Posted by
on under

This is the fourth article in my series about working with a combined Flask and React project. In this part I'm going to cover how to deploy the application in Docker containers.

Dynamically Update Your Flask Web Pages Using Turbo-Flask

Posted by
on under

How can you update a part of a web page dynamically, without the user having to hit the refresh button on the browser?

This is a question that is frequently asked on the Internet. If you have some knowledge of JavaScript this is relatively easy to do, more so if you use a front end web framework such as React or Vue. But what if you have a standard web application written in Flask and Jinja templates?

In this article I'm going to introduce you to my Turbo-Flask extension, which will allow your Flask application to easily push asynchronous page updates to the browser, without having to write any JavaScript code. In the screenshot below, note how the CPU load numbers update without the user doing anything.

Turbo-Flask Demo Application

How to Write Unit Tests in Python, Part 2: Game of Life

Posted by
on under

This is the second part of my series on unit testing Python applications. In this article I will introduce you to Conway's Game of Life, an interesting simulation that plays animated patterns on a grid.

Game of Life

My implementation of this game has an engine part, where the data structures and algorithm of the simulation are implemented, and a graphical user interface (GUI) part. In this article I will focus on testing the engine (testing GUIs will be covered in a future article).

Testing this code will present us with a few new challenges. In this article you will learn about the following topics:

  • Test parametrization
  • Building test matrices
  • Basic mocking
  • Testing Python exceptions

How to Write Unit Tests in Python, Part 1: Fizz Buzz

Posted by
on under

Today I'm starting a new series of articles about a topic that does not get a lot of coverage: how to write Python unit tests. Unlike other testing tutorials, I'm going to focus on testing techniques more than on the testing tools themselves. The idea is that in each part of this series I will look at a particular piece of code and discuss the challenges it presents from a testing point of view and how to address them.

In this first part I'm going to introduce the testing set up that I use in my projects, which is based on pytest. Then I will show you how to write unit tests for an implementation of the popular fizz buzz game that is frequently the subject of coding interview exercises.

Learn Socket.IO with Python and JavaScript in 90 Minutes!

Posted by
on under

The video below contains a complete 90 minute Socket.IO course using Python and JavaScript.

This is the list of chapters, each with a link to the code for each part of the tutorial:

Learn React in 90 Minutes!

Posted by
on under

Below you can watch my complete "Quick React Tutorial" video series. The entire seven-part series runs for about 93 minutes and will give you a fairly complete overview of the core features of the React framework.

Below you can see the list of parts in the series, each with a link to the code for that part of the tutorial:

Why do we pass __name__ to the Flask class?

Posted by
on under

When you learn Flask, you are told to create your Flask application instances by passing __name__ as the first argument to the Flask class. Most developers do this without thinking, and without knowing what it achieves.

In this article we are going to look at Flask(__name__) in depth. By the end you will not only have a full understanding of this pattern, but you will also know when to deviate from it and pass other values.

How to Kill a Python Thread

Posted by
on under

I'm often asked how to kill a background thread, and the answer to this question makes a lot of people unhappy: threads cannot be killed. In this article I'm going to show you two options we have in Python to terminate threads.

Ignore All Web Performance Benchmarks, Including This One

Posted by
on under

A couple of months ago there was an article titled Async Python is Not Faster making the rounds on social media. In it, the author Cal Paterson made the point that contrary to popular belief, asynchronous web frameworks are not only "not faster" than their traditional synchronous counterparts, but they are also slower. He supports this by showing the results of a fairly complete benchmark that he implemented.

I wish things were as simple as this author puts them in his blog post, but the fact is that measuring web application performance is incredibly complex and he's got a few things wrong, both in the implementation of the benchmark and in his interpretation of the results.

In this article you can see the results of my effort in understanding and fixing this benchmark, re-running it, and finally arriving at a shocking revelation.