Starting on January 1, 2020, the Python community will no longer update, fix bugs, or patch security issues for Python 2.7. We recommend that you migrate apps that are still running in the Python 2 runtime of the App Engine standard environment to the Python 3 runtime as soon as possible. For more information, see Python 2 support on Google Cloud.
Key differences between the Python 2 and Python 3 runtimes
Most of the changes you need to make during the migration come from the following differences between the Python 2 and Python 3 runtimes:
- Compatibility issues between Python 2 and Python 3
- No bundled App Engine services in the Python 3 runtime
- A web framework is required to route requests for dynamic content
Compatibility issues between Python 2 and Python 3
When Python 3 was first released in 2008,
several backward incompatible changes
were introduced to the language. Some of these changes require only minor updates
to your code, such as changing the
Other changes may require significant updates to your code, such as updating
the way that you handle binary data, text, and strings.
Many popular open source libraries, including the Python standard libraries, also changed when they moved from Python 2 to Python 3.
No bundled App Engine services in the Python 3 runtime
Starting with the Python 3 runtime, the App Engine standard environment no longer includes bundled App Engine services such as Memcache and Task Queues. Instead, Google Cloud provides standalone products that are equivalent to most of the bundled services in the Python 2 runtime. For the bundled services that are not available as separate products in Google Cloud, such as image processing, search, and messaging, you can use third-party providers or other workarounds as suggested in this migration guide.
Removing the bundled App Engine services enables the Python 3 runtime to support a fully idiomatic Python development experience. In the Python 3 runtime, you write a standard Python app that is fully portable and can run in any standard Python environment, including App Engine.
Web framework required to route requests for dynamic content
In the Python 2 runtime, you can create URL handlers in the
to specify which app to run
when a specific URL or URL pattern is requested.
In the Python 3 runtime, your app needs to use a web framework such as
Flask or Django to route requests for dynamic content instead of using
URL handlers in
app.yaml. For static content, you can continue to create URL
in your app's
Overview of the migration process
We recommend the following incremental approach to the migration, in which you maintain a functioning and testable application throughout the process:
Migrate the App Engine bundled services in your Python 2 app to Google Cloud services, third-party services, or other recommended replacements. Test your app after migrating each service.
When you finish this step, your Python 2 app should no longer use any
Upgrade your app to be compatible with both Python 2 and Python 3.
For more information about this step of the migration process, see Porting Python 2 Code to Python 3 on the Python Software Foundation documentation site.
Prepare App Engine configuration files for the Python 3 runtime.
Test and deploy your upgraded app in a Python 3 environment.
You may need to spend significant time fixing compatibility issues that aren't visible until you run your upgraded app in a Python 3 environment.
After all of your tests pass, use traffic splitting to slowly migrate traffic from your app in the Python 2 runtime to the app in the Python 3 runtime.