A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cloud.google.com/appengine/docs/standard/python3/services/deferred below:

Deferred API for Python 3 | Google App Engine standard environment docs

Skip to main content Deferred API for Python 3

Stay organized with collections Save and categorize content based on your preferences.

This page describes how to use the Deferred API, one of the legacy bundled services, with the Python 3 runtime for the standard environment. Your app can access the bundled services through the App Engine services SDK for Python 3.

Overview

Previously, the Deferred package google.appengine.ext.deferred depended on the webapp framework in Python 2. Since the webapp framework has been removed in the App Engine services SDK for Python 3, you need to make some changes when upgrading your Python 2 app to Python 3.

Enabling the Deferred API

To enable the Deferred API for Python 3, you no longer need to set builtins.deferred to on in the app.yaml file. Instead, to enable the API, you must pass use_deferred=True in the call to wrap_wsgi_app().

Important: When using the local development server to test Python 3 apps that use the Deferred API, you must set the following environment variable in your app.yaml:
DEFERRED_USE_CROSS_COMPATIBLE_PICKLE_PROTOCOL: 'True'
Similarites and differences

By default, the Deferred API for Python 3 uses the same URL /_ah/queue/deferred and the same default queue as it did in Python 2. Note that for apps migrating to Cloud Tasks, the default queue is not created automatically and the deferred tasks library is not available.

If your app uses the default /_ah/queue/deferred endpoint, using deferred.defer() in Python 3 remains the same as Python 2. If your app uses a custom URL for execution of deferred tasks, you need to make some changes since the TaskHandler class in the deferred module for Python 2 has been removed in the Python 3 version of this API.

To set a custom URL for execution of deferred tasks, the app can override either the post or the run_from_request method in the deferred.Handler class (formerly deferred.TaskHandler in Python 2), and pass the environ parameter which represents a dictionary containing WSGI request parameters. The post method can then be called from the custom endpoint (as shown in the Python 3 samples).

The end-to-end usage of the Python 3 Deferred API, such as routing of requests and accessing the environ dictionary, depends on the web framework the app is migrating to. Compare code changes made from the Python 2 example to the Python 3 examples in the following sections.

Python 3 examples

The following example shows how to execute a deferred task using a default endpoint and a custom endpoint in a Flask app and Django app.

Flask Django Without any framework Code samples

To view the complete code samples from this guide, see GitHub.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["The Deferred API for Python 3 on Google App Engine no longer requires setting `builtins.deferred` in `app.yaml`; instead, you must use `use_deferred=True` when calling `wrap_wsgi_app()`."],["The default behavior of the Deferred API in Python 3 remains consistent with Python 2, using the `/_ah/queue/deferred` URL and the default queue, but keep in mind that Cloud Tasks will differ."],["When using the local development server for testing, you need to set `DEFERRED_USE_CROSS_COMPATIBLE_PICKLE_PROTOCOL: 'True'` in your `app.yaml` to make sure the Deferred API works."],["Custom URLs for deferred task execution in Python 3 require using the `deferred.Handler` class's `post` or `run_from_request` methods, as the `TaskHandler` from Python 2 is no longer available."],["The way a Python 3 App uses the Deferred API, including its handling of requests and accessing the `environ` dictionary, is based on the web framework that is being migrated to, as shown in the provided examples with Flask, Django and without a framework."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4