Paste (WSGI Toolkit)
Paste is a comprehensive set of tools for developing, deploying, and managing Web Server Gateway Interface (WSGI) applications. It includes components for serving WSGI applications, handling exceptions, parsing URLs, and more. The current version is 3.10.1, with a release cadence that has slowed down over recent years, focusing on Python 3 compatibility and maintenance.
Warnings
- breaking Python 2 compatibility was completely removed starting with Paste versions 3.7.0 and 3.8.0. If you require Python 2 support, you must use an older version of Paste (e.g., 3.6.1 or earlier).
- gotcha The `cgi.escape` function, which was deprecated and later removed in Python 3, has been replaced internally by Paste in version 3.10.0. If your application or custom Paste extensions relied on specific behaviors of `cgi.escape` through Paste, inspect `paste.util` for alternatives.
- gotcha Beginning with version 3.10.0, Paste started including `cgitb.Hook` and `cgi.FieldStorage` in `paste.util`. While this provides compatibility, direct reliance on the standard library's `cgi` module for these functions may lead to issues with future Python versions, as the `cgi` module itself is undergoing changes and potential deprecation.
Install
-
pip install paste
Imports
- serve
from paste.httpserver import serve
- loadapp
from paste.deploy import loadapp
Quickstart
from paste.httpserver import serve
def simple_app(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'text/plain; charset=utf-8')]
start_response(status, headers)
return [b'Hello, Paste!\n']
if __name__ == '__main__':
print("Serving on http://127.0.0.1:8000")
serve(simple_app, host='127.0.0.1', port=8000)