If you have Python in your tech stack, the date January 1, 2020 is probably long marked on your calendar; if not, then it should be—that’s when Python 2 finally loses support. A while ago, we published a comprehensive guide on migrating from Python 2 to Python 3. The focus of the guide was to explain how to go about upgrading to Python 3. Now, we’d like to take a step back and answer an even more fundamental question you might be asking yourself: why is the migration so important in the first place? Read on to learn just that, in 5 simple reasons.
The (long) journey to Python 3 migration
Python has been around since 1990. The language had thrived for a long time before Python 3 was first released around a decade ago, so it’s no surprise that a great number of Python projects still use version 2 to this day.
Ever since the introduction of Python 3, Python users and enthusiasts alike began asking themselves one simple question: when will the time be right to migrate?
The initial end-of-life date for Python 2 was supposed to be 2015, later pushed back to the beginning of 2020. With the date finally set, the question of migration started popping up much more often.
How bad will it get for Python 2 projects past their end-of-life?
Now that the moment is nearly upon us and the answer to the original question couldn’t be more clear—the time to migrate is right now—other concerns are quick to follow.
The costs of going through with the upgrade, which is a necessary investment, rank pretty high on that list, but even more so, another burning question appears: what if you don’t make it in time? What are the potential risks, including financial ones, of getting stuck with Python 2?
The good news is that it won’t be all fire and brimstone should you miss the set deadline. The world won’t end for your Python 2 projects on January 1, 2020, that much is certain.
The bad news is that maintaining those projects past that date is going to get a lot harder, and it’ll keep getting worse the longer you hold off on migrating. As time goes by, active development of such projects in particular will suffer the most.
5 reasons why you should migrate from Python 2 to Python 3
Since we’ve already established that it would be preferable if you did manage to migrate to Python 3 before January 1, 2020, let’s take a look at our 5 reasons why we believe it’s a good idea, exactly.
1. Third-party libraries
One of the greatest advantages of Python is the vast collection of easy-to-use third-party packages it offers. At first glance, it’s hard to imagine a scenario where this isn’t considered a definitively positive aspect of Python.
However, ironically enough, the ready availability and sheer number of Python libraries and frameworks have precisely been the top reasons behind the slow adoption of Python 3. To add insult to injury, they’re now also becoming the bane of Python 2.
Python packages have a tendency to drop interpreters past their end-of-life. This is done to reduce the work required from developers, who are often forced to support those projects in their own free time.
Dropping support for major versions of Python is never a decision taken lightly. That being said, plenty of libraries have done it already, or have declared their intention to do so before or on January 1, 2020.
All in all, as far as the libraries you’re using in your Python 2 projects go, don’t expect too many updates in 2019—especially updates that would include new features for you to benefit from.
2. Software security
If your project is in maintenance-only mode, security should be your top concern when considering the end of support for Python 2.
Securing a Python interpreter will be relatively simple. Upon discovering a security hole in Python 2.7 beyond its end-of-life, you’ll have to apply unofficial security patches. Those may originate from Linux distributions with a support period of up to 10 years. However, if you’re not currently using such long-supported distribution, applying them manually will be necessary.
Maintenance of third-party dependencies is going to get much more problematic, since they’re bound to lose Python 2 support, if they haven’t lost it already. In the (highly likely) event of you coming across a vulnerability in any of them, you’ll be on your own. That’s why this is quite possibly the gravest threat to the security of Python 2 applications.
Ensuring software security is a legal requirement, especially when you’re dealing with personal information in the realm of GDPR. Keeping your software up to date understandably ranks very high among security best practices, and an outdated Python interpreter would be all but guaranteed to show up as a red flag during a security audit.
3. Developer support
Software companies have one of the highest employee turnover rates on the market. It comes as no surprise, then, that attracting new developers and keeping your current ones for as long as possible are a definite priority.
Developers thrive on fixing things. They’re always out for a new challenge, always looking for the next best thing. If you fail to provide those for them, you risk losing their interest and subsequently them in the process.
Meanwhile, Python 2 is slowly but surely becoming a relict of the past, or a niche at best. It’s a high-speed train headed for future obsolescence before we know it. Solving problems for unsupported and outdated technologies doesn’t sound like a good use of all that mental firepower developers boast.
Python 2 is no longer fun or exciting. Instead, it has become a death sentence for the creativity of your developers and a nuisance for both your project stakeholders and the people implementing it.
In short, not migrating to Python 3 doesn’t bode well for the future of your Python projects, if only because you might soon start struggling to even find developers to work on them.
4. Missed opportunities
We’ve already mentioned third-party libraries, haven’t we? Well, aside from those, Python 3 brings a lot to the table with its standard library alone.
For starters, type safety was improved considerably. This covers arguably the best-known change: strings that are unicode by default and of an explicitly different type than bytes. In our first-hand experience, this saves countless hours you’d normally spend hunting down UnicodeDecodeErrors.
But that’s not nearly the end of it. Python 3 also gives you:
- type annotations you can leverage to improve static code analysis and overall usability;
- native asynchronous programming;
- chained exceptions, which are especially useful when debugging;
- other helpful features that make coding in Python much more efficient.
The list goes on, and it is sure to grow with each new Python 3 release.
5. Tangible benefits
Python 3 comes with more tangible benefits, as well. For instance, Instagram—one of the most popular software products that use Python—reported a 12% CPU performance boost and a 30% improvement in using memory resources after their Python 3 migration combined with a Django update.
Speaking of which, it’s also worth mentioning that while Django had supported Python 2 for a long period of time, it became Python 3-only when Django 2.0 was released. With other libraries following suit, it’s quite self-evident that the kind of change Instagram experienced may not be possible without an interpreter upgrade for Python 2 projects.
The performance improvements of Python are continuously benchmarked. However, it should be noted that such toy benchmarks rarely showcase just how beneficial upgrading to Python 3 can be for mission-critical applications.
What are your options for continued Python 2 support?
There is no indication that the end-of-life date for Python 2 will be postponed once again. The last time Python’s creator Guido van Rossum was publicly asked about it, he only reaffirmed his position on ending support for Python 2 with January 1, 2020. Even at the time of the previous extension in 2014, the former Benevolent Dictator for Life of the Python language was quite clear: there will be no Python 2.8.
As we’ve said before, some Linux distributions are likely to continue supporting Python 3 for the next couple of years, but that support will only involve security fixes, and only for the core interpreter and most popular libraries.
When it comes to new features, the only way to get them in Python 2 for the past decade or so has been through using some hacky backports or forks. The most prominent fork of Python 2.7 is Tauthon, which attempts to bring certain Python 3 features over to Python 2. However, the development speed of Tauthon has significantly decreased in recent years.
All of this paints a relatively straightforward picture: the smartest play for you is to simply migrate to Python 3, instead of clinging to the old version for no good reason.
Final thoughts on moving forward with Python 3 migration
Using Python 2 right now should be treated the same way you would any code debt: it won’t necessarily kill your project, but it does affect your product negatively, and will continue to do so the longer you put the migration off. If you care about the long-term well-being of your software, the choice to upgrade your current version of Python should be a no-brainer.
January 1, 2020 is virtually around the corner, but there’s no reason to panic just yet; you still have enough time to migrate to Python 3 and do it the right way. This isn’t a rats-and-a-sinking-ship-type situation.
Python 3 migration isn’t a process that should be rushed, but the moment to start thinking about it is already here. One of the safest ways to go about the upgrade is to gradually introduce Python 3 support during your everyday development. It’s the perfect solution for active and mission-critical projects.
This approach is described at length in our Python 2.7 to 3 migration guide. We highly recommend you check it out.
And if you need support with your Python 3 migration or Python development as a whole—don’t hesitate to let us know how we can help. We’re here for you!