Adam Johnson

Home | Blog | Projects | Colophon

Dropping Python 2 Support From Open Source Projects

2019-03-13

Bye bye six

I’ve recently dropped Python 2 support from most of the open source projects I maintain. Python 2 support ends 2020-01-01 (see pythonclock.org), and many major projects have signed the Python 3 Statement that declares that they will remove Python 2 support before, so this year is crunch time for migration.

Reasoning

I was originally thinking of maintaining Python 2 support until the end of the year. However, I changed my mind for a few reasons.

Firstly, Django dropped Python 2 support in version 2.0, at the start of 2018, setting a precedent.

Secondly, I have not done any professional work with Python 2 for some time. Whilst I’m using some great tools to make cross-compatibility easier, I still don’t trust myself to remember all the differences, and I especially don’t want to make a mistake and release something broken.

Thirdly, I created a Twitter poll which came out with 69% in favour of dropping today, and only 15% waiting until 2020-01-01.

Fourthly, fellow Django contributor Josh Smeaton pointed out to me that upstream packages dropping Python 2 support gives teams more ammunition to use to convince management that upgrading needs prioritization. Dropping Python 2 support can actually help such users.

Fifthly, most of the packages I’m maintaining are pretty stable. The versions that support Python 2 will remain on PyPI and in the case of a major bug or security issue, I can always make a bug fix release branched from them. It’s only new features that won’t be added with Python 2 support.

Migration Checklist

The following is the checklist I used on each project to move to Python 3 only, ordered by affected files. My packages supported Python 2 and 3 in a single codebase, using six for compatibility, and checking with modernize, isort, and tox to ensure cross-compatibility. There are other ways of achieving cross-compatibility, such as 2to3 and future, so if you’re trying to follow this list on a project, you may need to make adjustments.

Every Python File

setup.py

setup.cfg

Testing

Documentation

Example Pull Request

For an example migration, see my pull request on django-perf-rec. It shows most of the above steps in action.

Fin

I hope this can help you with removing Python 2 support from a codebase, whether in an application or a package!


If you found this useful, I'd be grateful if you subscribe to my future posts, via RSS, Twitter, or email:

Tags: python