- Building Google Cloud Platform Solutions
- Ted Hunter Steven Porter Legorie Rajan PS
- 194字
- 2025-04-04 14:47:41
WSGI and CGI
The App Engine standard Python runtime supports both WSGI and CGI. These are standard gateway interfaces that specify how a web server should interact with Python services. Web Server Gateway Interface (WSGI) implementations, interact with Python at the application level by associating requests with a Python module function. Common Gateway Interface (CGI) implementations invoke Python scripts on a per-request basis, generally spawning an individual process for each request that executes the associated script.
App Engine handler scripts must either conform to WSGI or CGI standards. To associate an WSGI application to an App Engine handler, specify the application in Python module notation. For CGI compliant scripts, specify the *.py script directly. For example:
handlers:
- url: /my-app/*
script: myapp.application # specifies a WSGI module myapp and module variable application
- url: /my-script/*
script: myscript # specifies a CGI script ./myscript.py
By supporting both WSGI and CGI, developers can choose to build endpoint-specific handler functions or entire Python web applications. There are many popular WSGI-compliant Python web frameworks, including Django and Flask. Additionally, App Engine supports webapp2, a simple WSGI-compliant web framework whose origins and design are very closely related to App Engine.