{"id":6196,"library":"pysher","title":"Pysher","description":"Pysher is a Python module for handling Pusher websockets, based on Erik Kulyk's PythonPusherClient. It provides client-side functionality to connect to Pusher channels, subscribe to events, and bind callbacks to handle real-time data. The project is currently in maintenance mode, welcoming PRs for fixes, updates, and features, with releases occurring periodically for merged improvements.","status":"maintenance","version":"1.0.8","language":"en","source_language":"en","source_url":"https://github.com/deepbrook/Pysher","tags":["websocket","pusher","realtime","client"],"install":[{"cmd":"pip install pysher","lang":"bash","label":"Install Pysher"}],"dependencies":[{"reason":"Core dependency for websocket communication. Specific version constraints apply.","package":"websocket-client","optional":false},{"reason":"Used for HTTP requests, likely for authentication or initial connection setup.","package":"requests","optional":false},{"reason":"Optional dependency to improve websocket-client performance by enabling C-compiled UTF-8 validation.","package":"wsaccel","optional":true}],"imports":[{"symbol":"Pusher","correct":"import pysher\npusher = pysher.Pusher(...)"}],"quickstart":{"code":"import pysher\nimport os\nimport time\nimport logging\n\n# Configure logging to see Pysher's internal communication\nroot = logging.getLogger()\nroot.setLevel(logging.INFO)\nch = logging.StreamHandler()\nroot.addHandler(ch)\n\n# Replace with your actual Pusher App Key and Cluster\nAPP_KEY = os.environ.get('PUSHER_APP_KEY', 'your_app_key')\nCLUSTER = os.environ.get('PUSHER_CLUSTER', 'mt1') # e.g., 'mt1', 'eu', 'ap1'\n\nif APP_KEY == 'your_app_key':\n    print(\"WARNING: Please set PUSHER_APP_KEY environment variable or replace 'your_app_key' in the code.\")\n\ndef my_func(*args, **kwargs):\n    \"\"\"Callback function to process messages from a subscribed event.\"\"\"\n    print(f\"Processing Args: {args}\")\n    print(f\"Processing Kwargs: {kwargs}\")\n\ndef connect_handler(data):\n    \"\"\"Callback function when connection is established.\"\"\"\n    print(f\"Connected to Pusher! Connection data: {data}\")\n    # Subscribe to a channel after successful connection\n    channel = pusher.subscribe('my-channel')\n    # Bind a callback to a specific event on that channel\n    channel.bind('my-event', my_func)\n    print(\"Subscribed to 'my-channel' and bound 'my-event'.\")\n\n# Initialize Pusher client\npusher = pysher.Pusher(APP_KEY, cluster=CLUSTER)\n\n# Bind the connect handler to the 'pusher:connection_established' event\npusher.connection.bind('pusher:connection_established', connect_handler)\n\n# Connect to Pusher\nprint(\"Connecting to Pusher...\")\npusher.connect()\n\ntry:\n    while True:\n        # Keep the main thread alive to allow websocket client to run\n        time.sleep(1)\nexcept KeyboardInterrupt:\n    print(\"\\nDisconnecting Pysher.\")\n    pusher.disconnect()\n    print(\"Disconnected.\")\n","lang":"python","description":"This quickstart demonstrates how to connect to Pusher, subscribe to a channel, and bind a callback function to an event. It includes basic logging to observe the connection process and uses environment variables for the Pusher App Key for secure credentials handling."},"warnings":[{"fix":"Review all callback functions bound to Pusher events or connection lifecycle events (e.g., `pusher:connection_established`) and adjust their signatures to correctly handle the arguments passed by Pysher 1.0.7+.","message":"Prior to v1.0.7, callback functions bound to events or connection binds might have received an incorrect number of arguments. Version 1.0.7 fixed this to match the expected argument signature, which could break existing code that relied on the old, incorrect argument count for `my_func(*args, **kwargs)` or similar callbacks.","severity":"breaking","affected_versions":"<1.0.7"},{"fix":"Ensure your `websocket-client` version adheres to Pysher's `install_requires` specifications. If issues arise, try downgrading or upgrading `websocket-client` to a known compatible version.","message":"Pysher has specific compatibility requirements with its `websocket-client` dependency. `websocket-client==0.49` is explicitly excluded in `setup.py`, and issues have been reported with `websocket-client==0.58.0` and `Pysher 1.0.6`. Always refer to the `install_requires` in `setup.py` or the official GitHub README for the exact compatible versions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your project is running on Python 3.5 or newer.","message":"Pysher dropped support for Python versions prior to 3.5. Attempting to use Pysher on older Python 3 releases (e.g., 3.4 or 2.x) will result in compatibility errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set realistic expectations for new features and be prepared to contribute fixes or features via pull requests if needed.","message":"The Pysher library is explicitly stated to be in 'maintenance mode'. This implies that while bug fixes and contributions (PRs) are welcome and released, active development of new features or rapid updates should not be expected.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install `wsaccel` alongside Pysher: `pip install pysher wsaccel`.","message":"For optimal performance, especially when handling high volumes of messages, it is recommended to install the `wsaccel` package. This allows the underlying `websocket-client` to utilize C-compiled UTF-8 validation methods, which are significantly more CPU-efficient than the default pure Python implementation.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}