Google App Engine Standard Environment Services SDK for Python 3

2.0.0 · active · verified Sun Apr 12

The `appengine-python-standard` library is the Google App Engine services SDK for Python 3. It provides Python 3 applications running in the App Engine standard environment access to various legacy bundled services and API endpoints that were previously only available on the Python 2.7 runtime, such as Mail, Memcache, NDB, and URL Fetch. The library is actively maintained, with minor, patch, and occasional major releases addressing new features and compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Flask application using `appengine-python-standard` to access the App Engine Memcache service. It includes the required `wrap_wsgi_app` middleware call. For deployment, ensure your `app.yaml` includes `app_engine_apis: true` and specifies a Python 3 runtime and an entrypoint (e.g., Gunicorn).

import os
from flask import Flask, request
from google.appengine.api import wrap_wsgi_app, memcache

app = Flask(__name__)
app.wsgi_app = wrap_wsgi_app(app.wsgi_app)

@app.route('/')
def hello():
    visits = memcache.incr('visits', initial_value=0)
    return f'Hello, App Engine! You have visited this page {visits} times.'

if __name__ == '__main__':
    # This is used when running locally. Gunicorn is used for deployment.
    # Ensure that `app_engine_apis: true` is set in app.yaml for deployment.
    port = int(os.environ.get('PORT', 8080))
    app.run(host='127.0.0.1', port=port, debug=True)

view raw JSON →