Upgrading a Dockerized Flask App from Python 2.7 to Python 3.7+
Follow along in this 30 minute video where we encounter and fix a bunch of errors while upgrading Python 2.7.16 to Python 3.7.4.
Jan 1st 2020 is right around the corner and that’s when Python 2.7.x will finally be considered end of life, so now is a great time to start upgrading to Python 3.7+ if you haven’t done so already.
In the video listed below, we go over updating a real Flask application from using Python 2.7.16 to 3.7.4. It covers how to do this with Docker, but the same strategy could be applied without Docker.
Through out the video we cover:
- Picking a Python version to upgrade to
- Going over which 3rd party package versions only work with specific versions of Python
- How to perform the upgrade in a production ready (read: safe) way with Docker
- Encountering and fixing a bunch of errors you’ll run across while doing this upgrade
- How to code your app to work for both versions at once until you retire Python 2.7.x
The demo app we cover on video is the app in my Build a SAAS App with Flask course. It was originally coded to work with Python 2.7.x and early versions of Python 3.x. Over time I have updated it to keep it current and will continue to update it (yay for free updates for life).
# Updating Python from 2.7+ to 3.7+ Video
Timestamped Table of Contents
- 0:33 – Why bother updating from Python 2.7 to 3.7+?
- 0:48 – Upgrading in a production ready way
- 1:29 – What’s going to be covered in this video?
- 2:34 – Downloading a sample Flask project to upgrade
- 3:29 – Building the project with Docker so we can run it
- 4:46 – Figuring out the latest Docker image for Python 2.7
- 6:20 – Watching Docker build Python 2.7.16
- 6:49 – Downgrading the pytest library to work with Python 2.7
- 9:33 – Watching Docker build again after we fix pytest
- 10:08 – Running the example Build a SAAS App with Flask project
- 10:56 – Ensuring our test suite passes with Python 2.7
- 12:04 – Benefits of using Docker to upgrade Python versions
- 13:04 – How to upgrade the Dockerized Flask app from Python 2.7 to 3.7+
- 14:26 – Watching Docker build again after upgrading to Python 3.7.4
- 14:52 – Running into and fixing a Celery beat schedule error
- 15:43 – Running into and fixing a JSON serializable TypeError after upgrading
- 19:53 – Another benefit of using Docker is that rolling back to 2.7 is easy
- 21:33 – Looking at even more Flask related packages that work in Python 3.7
- 25:54 – Using Flask-Limiter to rate limit specific URL endpoints
- 26:55 – Scrolling through all of the packages used in the main Flask project
- 27:19 – Coding your app to work with both Python 2.7.x and Python 3.7.x
Reference Links
- https://github.com/nickjj/build-a-saas-app-with-flask
- https://buildasaasappwithflask.com
- https://nickjanetakis.com/blog
- https://hub.docker.com/_/python
- https://pypi.org/project/pytest
- https://github.com/nickjj/dotfiles
What have you had to do to upgrade Python to 3.7+? Let me know below.