{"id":2889,"library":"cheroot","title":"Cheroot HTTP Server","description":"Cheroot is a high-performance, pure-Python HTTP server used by the CherryPy web framework, but it can also be used as a standalone WSGI server. It provides a robust and efficient way to serve web applications. The library is actively maintained, with the current version being 11.1.2, and aims for high stability and performance.","status":"active","version":"11.1.2","language":"en","source_language":"en","source_url":"https://github.com/cherrypy/cheroot","tags":["http","server","wsgi","cherrypy"],"install":[{"cmd":"pip install cheroot","lang":"bash","label":"Install stable version"},{"cmd":"pip install cheroot[zope]","lang":"bash","label":"Install with optional zope.interface dependency"}],"dependencies":[{"reason":"Required for the optional 'zope' extra, which might be used for specific interface implementations or compatibility.","package":"zope.interface","optional":true}],"imports":[{"note":"The core WSGI Server class is located within the `cheroot.wsgi` module.","symbol":"Server","correct":"from cheroot.wsgi import Server"},{"note":"Used for routing multiple WSGI applications based on URL path.","symbol":"PathInfoDispatcher","correct":"from cheroot.wsgi import PathInfoDispatcher"}],"quickstart":{"code":"import os\nimport time\nfrom cheroot.wsgi import Server, PathInfoDispatcher\n\n\ndef simple_app(environ, start_response):\n    \"\"\"A simple WSGI application.\"\"\"\n    status = '200 OK'\n    headers = [('Content-type', 'text/plain')]\n    start_response(status, headers)\n    return [b'Hello, Cheroot!\\n']\n\ndef delayed_app(environ, start_response):\n    \"\"\"An application with a delay to demonstrate concurrency.\"\"\"\n    time.sleep(2) # Simulate work\n    status = '200 OK'\n    headers = [('Content-type', 'text/plain')]\n    start_response(status, headers)\n    return [b'Hello after 2 seconds!\\n']\n\n# Map paths to WSGI applications\npath_map = {\n    '/': simple_app,\n    '/delay': delayed_app,\n}\ndispatcher = PathInfoDispatcher(path_map)\n\n# Configure the server\n# Default host is 0.0.0.0, default port is 8080 if not specified\n# Using 127.0.0.1 and a common testing port here\nhost = os.environ.get('CHERoot_HOST', '127.0.0.1')\nport = int(os.environ.get('CHERoot_PORT', 8070))\n\nserver = Server((host, port), dispatcher)\n\nprint(f\"Cheroot server starting on http://{host}:{port}/\")\nprint(\"Access http://localhost:8070/ and http://localhost:8070/delay\")\nprint(\"Press Ctrl+C to stop...\")\n\ntry:\n    server.start()\nexcept KeyboardInterrupt:\n    server.stop()\n    print(\"Cheroot server stopped.\")\n","lang":"python","description":"This quickstart demonstrates how to set up a basic Cheroot WSGI server with two different applications dispatched by `PathInfoDispatcher`. It listens on a configurable host and port (defaulting to `127.0.0.1:8070`), and handles incoming requests with a simple 'Hello, Cheroot!' response or a delayed response."},"warnings":[{"fix":"Ensure WSGI application returns `str` for status and headers with only Latin-1 compatible characters, and `bytes` for the body.","message":"When serving WSGI applications, ensure that response status and headers adhere to PEP 3333. For Python 3, these must be `str` type but restricted to Latin-1 code points, not arbitrary Unicode.","severity":"gotcha","affected_versions":"All versions on Python 3"},{"fix":"Follow the WSGI specification (PEP 3333) for `start_response` implementation in your application.","message":"The `start_response` callable in a WSGI application must not transmit headers immediately. It should store them, and the server (Cheroot) will transmit them only after the first non-empty iterable yielded by the application or explicit `write()` call.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always pass a `bind_addr` tuple like `('127.0.0.1', 8080)` or `('0.0.0.0', 80)` to the `Server` constructor, or use environment variables for flexible deployment.","message":"By default, if the host specification is omitted during server instantiation, Cheroot will listen on all IPv4 interfaces (`0.0.0.0`). The default port, if not specified, is `8080`. Always explicitly configure the bind address for production environments.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}