Share on facebook
Share on twitter
Share on linkedin
Share on email

Migrating Tag Inspector from Python 2 to Python 3

Python 2 to Python 3

Recently, our engineering team completed a migration of our proprietary tag auditing and management platform from Python 2 to Python 3. This upgrade brings with it a host of positive changes to Tag Inspector that will seek to improve performance and reduce bugs. Most notably, switching to Python 3 will future-proof our application’s security and stability.

Earlier this year, the Python Software Foundation announced that Python 2 will reach end-of-life on Jan. 1, 2020. This simply means that moving forward, Python 2 will no longer receive updates from its developers.

Porting Challenges

Porting from Python 2 to Python 3 is no easy task. This is what, historically, has kept Python 2 alive. Python is well known for its vast array of third-party libraries; these libraries must also then be ported into the new codebase. This usually presents one of two challenges.

On one hand, if the team behind the library hasn’t upgraded it to Python 3, the burden of that task falls onto the shoulders of our developers. On the other hand, teams who do port to Python 3 will often take the opportunity to update their framework in such a way as to break existing code that implements their library. Existing programs must be rewritten to fit the new library’s language. Even a single added character in a function name can—and will—grind an application to a halt. Our engineers were able to tackle and overcome both of these challenges.

Unicode Enhancements

Python 3 also brings with it code-wide Unicode enhancements. What this means is that text in Python 3 is now stored as Unicode rather than ASCII, the old default. As a web scraping application, Tag Inspector will encounter a lot of non-English Unicode characters that cannot be encoded to ASCII. Normally, trying to encode these characters into the proper character set would often throw errors since you won’t always know what character set your application is reading—a fact that is particularly true for web applications. 

This is quite possibly the best new feature for our purposes, yet it did come with its own challenges. Like I mentioned before, a change of this magnitude requires an extensive rewrite of much of the code. While Python 3 introduces text as Unicode, it also supports a different datatype (simply called bytes, or bytestring). This datatype is comprised of fully encoded text—the actual bits that make up the string. Python 2 was more-or-less the opposite: normal strings were encoded and Unicode had its own special string datatype. As you can guess, this presented an issue with the migration.

How can you easily tell which datatype any given string is in the old codebase? Luckily, Python 3 ships with a fantastic debugging tool: the -b command line option. Passing this flag when running your script lets you know exactly where you are trying to compare strings to bytes. This makes it simple to hunt down which line in your script is expecting a different datatype than it is being given. The -b flag gives developers an obvious leg up when navigating the new string datatypes.

Set Up for Success

In the end, although migrating to Python 3 is no easy task, our engineering team was able to successfully complete the project and deliver a wonderful and exciting new implementation. This is the same Tag Inspector that you are used to but faster, less buggy, and ready for anything the future may bring.

Now Hiring Software Engineers

Interested in working on our Tag Inspector proprietary software?
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on email
Email

Other Articles You Will Enjoy

Why Executive Teams are Resisting Google Analytics 4 (and What You Can Do to Change Their Minds)

Why Executive Teams are Resisting Google Analytics 4 (and What You Can Do to Change Their Minds)

Few can dispute that the future of analytics will be driven by machine learning and artificial intelligence. With Google’s launch of Google Analytics 4…

Which Analytics, TMS, and A/B Testing Platforms are Used by the Top 100 Digital News Outlets?

Which Analytics, TMS, and A/B Testing Platforms are Used by the Top 100 Digital News Outlets?

As the marketing technology landscape continues to grow beyond 8,000 martech solutions (up 13.6% YoY), the team at InfoTrust is taking a deep-dive look…

What is a Data Clean Room?

What is a Data Clean Room?

“Data clean room” is a growing buzzword in marketing, analytics, and advertising industries. Although data clean rooms aren’t an entirely new concept, they haven’t…

InfoTrust to Lead Webinar on Analytics Maturity Using Google Marketing Platform

InfoTrust to Lead Webinar on Analytics Maturity Using Google Marketing Platform

If you’re a marketer looking to sharpen your skills, or a business owner hoping to take your organization to the next level, then look…

InfoTrust Earns Looker Partner Certification

InfoTrust Earns Looker Partner Certification

CINCINNATI — The experienced digital analytics and customer data governance consulting team at InfoTrust is proud to announce that the organization achieved partner status…

Talk To Us

Talk To Us

Receive Book Updates

Fill out this form to receive email announcements about Crawl, Walk, Run: Advancing Analytics Maturity with Google Marketing Platform. This includes pre-sale dates, official publishing dates, and more.

Our website uses cookies and may collect user information to provide a good experience. Read our Privacy Policy here.

Leave Us A Review

Leave a review and let us know how we’re doing. Only actual clients, please.