{"id":4954,"library":"gevent-websocket","title":"gevent-websocket","description":"gevent-websocket is a WebSocket library designed for the gevent networking library, integrating with its `pywsgi` server. It provides features like integration at the socket level or through an abstract interface, and supports RPC and PubSub using WAMP (WebSocket Application Messaging Protocol). The current version is 0.10.1, last released in March 2017, suggesting it is in maintenance mode with infrequent updates.","status":"maintenance","version":"0.10.1","language":"en","source_language":"en","source_url":"https://gitlab.com/noppo/gevent-websocket","tags":["websocket","gevent","async","wsgi","server"],"install":[{"cmd":"pip install gevent-websocket","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for asynchronous I/O and WSGI server integration.","package":"gevent","optional":false},{"reason":"Optional dependency for performance acceleration, especially for UTF8 validation and frame masking/demasking.","package":"wsaccel","optional":true},{"reason":"Optional dependency for performance acceleration of JSON operations.","package":"ujson","optional":true},{"reason":"Optional dependency for performance acceleration of JSON operations (alternative to ujson).","package":"simplejson","optional":true},{"reason":"Optional dependency for deploying gevent-websocket applications with Gunicorn using a specific worker class.","package":"gunicorn","optional":true}],"imports":[{"symbol":"WebSocketServer","correct":"from geventwebsocket import WebSocketServer"},{"symbol":"WebSocketApplication","correct":"from geventwebsocket import WebSocketApplication"},{"symbol":"Resource","correct":"from geventwebsocket import Resource"},{"symbol":"WebSocketHandler","correct":"from geventwebsocket.handler import WebSocketHandler"},{"note":"Used for catching WebSocket-specific exceptions.","symbol":"WebSocketError","correct":"from geventwebsocket import WebSocketError"}],"quickstart":{"code":"from gevent import pywsgi\nfrom geventwebsocket import WebSocketServer, WebSocketApplication, Resource\nfrom collections import OrderedDict\n\nclass EchoApplication(WebSocketApplication):\n    def on_open(self):\n        print(\"Connection opened\")\n\n    def on_message(self, message):\n        # Echo the received message back to the client\n        print(f\"Received: {message}\")\n        self.ws.send(message)\n\n    def on_close(self, reason):\n        print(f\"Connection closed: {reason}\")\n\nif __name__ == '__main__':\n    print(\"Starting WebSocket echo server on ws://localhost:8000/\")\n    server = WebSocketServer(\n        ('', 8000),\n        Resource(OrderedDict([('/', EchoApplication)]))\n    )\n    try:\n        server.serve_forever()\n    except KeyboardInterrupt:\n        print(\"Server stopped.\")","lang":"python","description":"This quickstart sets up a basic WebSocket echo server using the `WebSocketApplication` and `WebSocketServer` classes. It listens on `ws://localhost:8000/` and echoes any received message back to the client. This is the higher-level API for defining WebSocket applications."},"warnings":[{"fix":"Evaluate newer alternatives for active development and support, or be aware of the limited maintenance for this library.","message":"The library's last release was in March 2017, indicating a low maintenance or potentially abandoned status. Users seeking actively developed WebSocket solutions with gevent might consider alternatives like `gevent-ws` which explicitly states itself as an MIT-licensed alternative to the 'abandoned' gevent-websocket.","severity":"deprecated","affected_versions":"<=0.10.1"},{"fix":"Always use `ws.receive()` to get messages from the WebSocket connection.","message":"The `wait()` method was renamed to `receive()` in earlier versions (pre-0.10.1). If upgrading from very old versions or referencing outdated documentation, this change can cause `AttributeError`s.","severity":"breaking","affected_versions":"<0.10.1"},{"fix":"Always check `if 'wsgi.websocket' in environ:` before attempting to access the WebSocket object and handle standard HTTP requests accordingly.","message":"When integrating with WSGI applications (especially with `WebSocketHandler`), the WebSocket object is exposed via `environ['wsgi.websocket']`. Applications must explicitly check for the presence of this key to determine if a request is a WebSocket upgrade or a standard HTTP request.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully test integration with other WebSocket-dependent libraries. If issues arise, consider removing `gevent-websocket` if `Flask-SocketIO` handles its own WebSocket transport effectively, or explore the specific `Flask-SocketIO` worker classes that might conflict.","message":"When combining `gevent-websocket` with `Flask-SocketIO`, installing `gevent-websocket` can unexpectedly break `Flask-SocketIO`'s WebSocket server functionality, leading to connections immediately closing, even though `Flask-SocketIO` itself might recommend installing it for performance.","severity":"gotcha","affected_versions":"0.10.1 (and potentially others when combined with specific `Flask-SocketIO` and `gevent` versions)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}