OAuth Authentication with Flask in 2023

Posted by
on under

A long time ago I wrote a tutorial on how to add logins with a social network to your Flask application, using the OAuth protocol. It's been almost 9 years since I wrote that article, and believe it or not, the OAuth protocol continues to be well supported by all major players including Twitter, Facebook, Google, GitHub and many more.

But of course, 9 years is a very long time in tech. Even though not much has changed in terms of how this method of authentication works, some of the packages that I've used back then have had major upgrades, while others have become unmaintained, so an update is due.


Flask + OAuth 2.0 Demo

Create a MySQL Database using Docker

Posted by
on under

MySQL is an open-source relational database owned by Oracle Corporation. The instructions I'm going to share in this article demonstrate how to install and set up a MySQL server along with the popular phpMyAdmin management application. As a bonus, I will also show you how to set up Python to access your MySQL database.

This article is an excerpt from my book SQLAlchemy 2 In Practice, where I show how to work with relational databases using Python and the SQLAlchemy library.

What's New in SQLAlchemy 2.0?

Posted by
on under

You may have heard that a major version of SQLAlchemy, version 2.0, has been released in January 2023. Or maybe you missed the announcement and this is news to you. Either way, I thought you'd be curious to know what's new in it, if it is worth upgrading and how difficult the upgrade is.

As with previous software reviews, this is going to be an opinionated overview. I have been using the SQLAlchemy ORM in web projects for a long time, so in this article I will discuss the features that affect my own work, both in positive or negative ways. If instead you are interested to see a list of every change that went into this new release, then the official change log is the place to go.

Beautiful Flask Tables, Part 2

Posted by
on under

It's been almost a year since I published my Beautiful Interactive Tables for your Flask Templates article, in which I showed a few example tables, rendered from a standard Flask and Jinja template, with some JavaScript help.

I have received a good amount of feedback on my proposed solutions. In this article I'm going to refresh my table examples to address the two most frequently requested improvements.

API Authentication with Tokens

Posted by
on under

In this article I'm going to show you a few common patterns for client authentication based on tokens, and how can they be implemented in a Python API back end. This method of authentication works well for rich clients, like JavaScript-based front end applications running in the browser, or perhaps a command-line (CLI) application.

I have written about Authentication several times on this blog, so this article is a bit different. Since I have already provided a few authentication projects in previous articles and in my open source projects, in this article I'm going to go over all the considerations you have to take into account when deciding how to best implement authentication for your own API project.

This article was voted by my supporters on Patreon. Would you like to support my work, and as a thank you be able to vote on my future articles and also have access to a chat room where I hang out? Become a Patron!

Using JavaScript-style async promises in Python

Posted by
on under

When you compare Python and JavaScript async code, you may think they are very much alike, since both use the async/await pattern. In reality, there is a significant difference between the two, which in my opinion, makes the JavaScript async model superior to Python's.

Do you want to know what the difference is, and how to make async Python work like async JavaScript? Watch or read on for the details!

Add a WebSocket Route to your Flask 2.x Application

Posted by
on under

The WebSocket protocol was standardized 10 years ago (in 2011, can you believe it?) so I'm sure for many of it you does not need an introduction. But in case you are not familiar with it, WebSocket is an extension to the HTTP protocol that provides a permanent, bi-directional communication channel between a client and the server, where both sides can send and receive data in real time, free of the constraints of the request/response cycle of HTTP.

Flask, being a minimalist web framework, does not have WebSocket support built-in. The old Flask-Sockets extension, which has not been maintained in the last few years, provided support for this protocol. My own Flask-SocketIO extension has also been a favorite, but this is Socket.IO, which is a more complex protocol that combines WebSocket and HTTP.

The good news is that if you are using Flask 2 you now have a new extension (also created by myself) called Flask-Sock, which provides modern WebSocket support for your application. In this article I'm going to show you how to work with this extension.

This article was voted by my supporters on Patreon. Would you like to support my work, and as a thank you be able to vote on my future articles and also have access to a chat room where I hang out? Become a Patron!

Accept Credit Card Payments in Flask with Stripe Checkout

Posted by
on under

In this article I'm going to show you how to implement an order page for your Flask application that you can use to sell products or services online. The solution I'm going to present to you uses Stripe Checkout, a secure and easy to use credit card charging service that integrates nicely with Flask.

This article was voted by my supporters on Patreon. Would you like to support my work, and as a thank you be able to vote on my future articles and also have access to a chat room where I hang out and answer questions? Become a Patron!

How to Write Unit Tests in Python, Part 3: Web Applications

Posted by
on under

This is the third part in my series about unit testing Python applications. In this article I'm going to show you some of the techniques I use when I work with Python web applications. For the examples in this article I will be using the Flask framework (I know, what a surprise!), but the concepts I'll show you are universal and can be applied to other frameworks as well.

While this is the first article in the series that covers web applications, I will be applying many of the ideas and solutions I shared in the first and second parts, so be sure to check those out first, even if you are only interested in web applications.

Flask Mega-Tutorial Update: Flask 2.0 and more!

Posted by
on under

I'm excited to share that I've completed a revision of the Flask Mega-Tutorial to keep it in line with new releases of Flask, Python and third-party dependencies.

Flask Mega-Tutorial

To celebrate this update, you can purchase the paid version of this course with a $10 USD discount (this offer is valid through the rest of July 2021). If you are interested in this offer, use the FLASK2 promotional code at checkout, or click here to go directly to the order page with the coupon added. Thank you!