This could be one of the good decisions I made last year. I had been working on the document analyzer at Counselytics for a year. Utilizing Python 2.6 and using flask to provide RESTful interface for the service. I noticed that the service were slow and I needed to make it perform better. Also I had problems Dockerizing the service which I'll discuss in another post later.

I started reading about python3 and noticed that they added new exciting features that could possibly enhance my service performance.I started by checking my dependencies support to python3 and researching alternatives. I found good alternatives for RESTful like aiohttp and sanic. Both libraries utilize the new python3 APIs such as asnycio to provide way faster performance than most of python2 libraries. You can read more about it here.

The next step was estimating effort to complete the migration. There are tools such as 2to3 that could help with syntax changes. However that is the easy part, there are other factors that could make impossible to make the move. Likely for me I didn't had much problems.

Some of the tools that is new in python3 and I used it during the process were very useful. The following list include my most favorite features:

  • For creating python3 virtual environment I use venv.
  • New and way better literal string format so instead of:
print("Hi {name}!".format(name="Jake"))

you can do:

name = "Jake"
print(f"Hi {name}!")

and python will infer the variable name in the text. Check out PEP 498

  • One significant improvement is adding the type checking for variables. This will allow developers to use the traditional variable typing. Annotating variables helps avoiding ambiguity in some cases. Check out PEP 3107.
  • New module for path handling Pathlib that offers class like representations. It's very useful, especially if you have a windows users in the team.
  • If you use Spark in your python application, they remove python 2.6 support starting 2.2.0.
  • While working on machine learning application you sometimes need to use statistics functions which is provided in python3 for you in statistics module.

There are great new features has been added to python3 that worth trying out and probably migrating to. Ever since I moved to python3 I found it fairly easy to follow new modules and use them in my day to day tasks. Please feel free to reach out with your favorite features in python3. I'd love to check it out and share it with other engineers in future blog.