CherryPy
CherryPy is a pythonic, object-oriented HTTP framework that enables developers to build web applications in much the same way they would build any other object-oriented Python program. It includes a robust, HTTP/1.1-compliant, WSGI thread-pooled webserver. The library, currently at version 18.10.0, has a proven track record of stability and is actively maintained with several minor releases per year.
Warnings
- breaking CherryPy 18.0.0 dropped support for Python 2.7 and Python 3.4. Users on these Python versions must use an older CherryPy version (e.g., CherryPy 17 LTS).
- breaking The `basic_auth` and `digest_auth` tools, along with the `httpauth` module, were officially deprecated in v14.0.0 and subsequently removed in v16.0.0.
- gotcha By default, CherryPy's built-in HTTP server binds to `127.0.0.1` (localhost). This means your application is only accessible from the machine it's running on.
- gotcha Methods intended to be exposed as web endpoints (accessible via URL) must be decorated with `@cherrypy.expose`. Forgetting this decorator will result in a 404 Not Found error for that URL path.
- breaking Cheroot, CherryPy's underlying HTTP server, dropped support for Python 3.6 and 3.7, now requiring Python 3.8 or later as of its recent releases. While CherryPy itself states support up to 3.11, newer Cheroot versions might introduce a conflict for older Python environments.
Install
-
pip install cherrypy
Imports
- cherrypy
import cherrypy
Quickstart
import cherrypy
class HelloWorld(object):
@cherrypy.expose
def index(self):
return "Hello World!"
if __name__ == '__main__':
# By default, CherryPy binds to 127.0.0.1:8080 (localhost)
# To make it accessible from other machines, set 'server.socket_host' to '0.0.0.0'
# cherrypy.config.update({'server.socket_host': '0.0.0.0'})
cherrypy.quickstart(HelloWorld())