{"id":4427,"library":"appengine-python-standard","title":"Google App Engine Standard Environment Services SDK for Python 3","description":"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.","status":"active","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/GoogleCloudPlatform/appengine-python-standard","tags":["google-cloud","app-engine","standard-environment","python3","serverless","sdk","legacy-apis"],"install":[{"cmd":"pip install appengine-python-standard","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.6 or higher, but less than Python 4.","package":"python","optional":false},{"reason":"Required for Python versions 3.13 and above to replace the removed standard 'cgi' module, particularly for applications relying on its functionality.","package":"legacy-cgi","optional":true}],"imports":[{"note":"Essential middleware for enabling App Engine API calls within your WSGI application.","symbol":"wrap_wsgi_app","correct":"from google.appengine.api import wrap_wsgi_app"},{"note":"Provides access to the App Engine Mail API for sending and receiving emails.","symbol":"mail","correct":"from google.appengine.api import mail"},{"note":"Used for fetching URLs, leveraging App Engine's URL Fetch service.","symbol":"urlfetch","correct":"from google.appengine.api import urlfetch"},{"note":"For interacting with the App Engine Memcache service.","symbol":"memcache","correct":"from google.appengine.api import memcache"},{"note":"For Python 3, the NDB client library is `google-cloud-ndb`, not `google.appengine.ext.ndb` (which is for Python 2). The `appengine-python-standard` SDK provides the necessary context for `google.cloud.ndb` to function correctly within App Engine Standard.","wrong":"from google.appengine.ext import ndb","symbol":"ndb","correct":"from google.cloud import ndb"}],"quickstart":{"code":"import os\nfrom flask import Flask, request\nfrom google.appengine.api import wrap_wsgi_app, memcache\n\napp = Flask(__name__)\napp.wsgi_app = wrap_wsgi_app(app.wsgi_app)\n\n@app.route('/')\ndef hello():\n    visits = memcache.incr('visits', initial_value=0)\n    return f'Hello, App Engine! You have visited this page {visits} times.'\n\nif __name__ == '__main__':\n    # This is used when running locally. Gunicorn is used for deployment.\n    # Ensure that `app_engine_apis: true` is set in app.yaml for deployment.\n    port = int(os.environ.get('PORT', 8080))\n    app.run(host='127.0.0.1', port=port, debug=True)","lang":"python","description":"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)."},"warnings":[{"fix":"Review comprehensive migration guides provided by Google Cloud. Replace Python 2-specific API calls with `appengine-python-standard` imports or standalone Google Cloud client libraries. Update `app.yaml` configuration to Python 3 standards.","message":"Migrating from Python 2.7 to Python 3 on App Engine Standard is a significant undertaking. The Python 3 runtime fundamentally differs, deprecating Python 2.7's bundled services model and requiring the use of standard Python libraries or specific SDKs like `appengine-python-standard`. Frameworks like `webapp2` are not supported, necessitating a switch to WSGI-compatible frameworks like Flask or Django.","severity":"breaking","affected_versions":"All versions when migrating from App Engine Python 2.7"},{"fix":"Add `app_engine_apis: true` to `app.yaml` and integrate `app.wsgi_app = wrap_wsgi_app(app.wsgi_app)` (or similar for other WSGI apps) into your main application file.","message":"To enable App Engine APIs with this SDK, your `app.yaml` must explicitly include `app_engine_apis: true`, and your WSGI application object (e.g., Flask app) must be wrapped with `google.appengine.api.wrap_wsgi_app()`. Failure to do so will result in API calls failing.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `appengine-python-standard` is at v1.1.11 or higher. For applications with direct `cgi` dependencies, explicitly add `legacy-cgi` to `requirements.txt`. Consider migrating away from direct CGI usage to a modern WSGI framework.","message":"The standard Python `cgi` module, previously used for handling CGI requests, has been removed in Python 3.13. Applications relying on this module will break. `appengine-python-standard` v1.1.11 and later address this by using `legacy-cgi` for Python versions above 3.9, but explicit dependency might still be needed for certain setups.","severity":"breaking","affected_versions":"v1.1.10 and older on Python 3.13+"},{"fix":"Use `from google.cloud import ndb`. When running locally, set `GOOGLE_APPLICATION_CREDENTIALS`. When deployed to App Engine, the context is usually handled automatically, but explicitly using `with client.context():` is good practice.","message":"When using NDB in Python 3 on App Engine Standard, you must import `ndb` from `google.cloud.ndb` and ensure an NDB client context is active for Datastore operations. The Python 2 `google.appengine.ext.ndb` import is deprecated and will not work.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Remove these deprecated attributes from your `app.yaml`. For `skip_files`, use a `.gcloudignore` file. For thread safety, Python 3 apps are assumed to be threadsafe; if not, configure `max_concurrent_requests` to 1.","message":"Several `app.yaml` attributes from Python 2.7 are deprecated or unsupported in the Python 3 runtime, including `api_version`, `threadsafe`, `libraries`, `builtins`, and `skip_files`. Using them may lead to deployment errors or unexpected behavior.","severity":"deprecated","affected_versions":"All versions"},{"fix":"For applications needing Mail API, use `from google.appengine.api import mail`. If using v2.0.0 for SMTP fallback, configure the relevant environment variables in `app.yaml` as needed.","message":"The Mail API's functionality in Python 3 has evolved. While `appengine-python-standard` re-introduces the Mail API via `google.appengine.api.mail`, earlier migration advice suggested using third-party mail providers due to its initial absence in Python 3. Version 2.0.0 adds SMTP fallback, introducing new environment variables for configuration (`APPE_MAIL_SMTP_HOST`, `APPE_MAIL_SMTP_PORT`, etc.).","severity":"gotcha","affected_versions":"All versions, especially v2.0.0+"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}