{"id":2284,"library":"signalrcore","title":"SignalR Core Python Client","description":"signalrcore is a full-featured Python client for SignalR Core hubs, offering support for various transports (WebSockets, Server-Sent Events, Long Polling) and encodings (JSON, MessagePack). It's designed to be compatible with Azure SignalR Service and serverless functions, and includes robust automatic and manual reconnection capabilities. The library abstracts away the complexities of SignalR protocol negotiation, transport fallback, and message dispatching, allowing developers to focus on defining event callbacks. Currently at version 1.0.2, it receives active development and maintenance.","status":"active","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/mandrewcito/signalrcore","tags":["SignalR","websockets","real-time","async","client","Microsoft Azure","pub-sub"],"install":[{"cmd":"pip install signalrcore","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Minimum Python version required.","package":"python","version":">=3.9"},{"reason":"Required for MessagePack encoding support.","package":"msgpack","version":"==1.1.2"}],"imports":[{"note":"Primary builder for synchronous/blocking connections.","symbol":"HubConnectionBuilder","correct":"from signalrcore.hub_connection_builder import HubConnectionBuilder"},{"note":"Builder for asyncio-compatible connections.","symbol":"AIOHubConnectionBuilder","correct":"from signalrcore.aio.aio_hub_connection_builder import AIOHubConnectionBuilder"}],"quickstart":{"code":"import logging\nimport time\nimport os\nfrom signalrcore.hub_connection_builder import HubConnectionBuilder\n\n# Configure logging for better visibility\nhandler = logging.StreamHandler()\nhandler.setLevel(logging.DEBUG)\n\nhub_connection = HubConnectionBuilder() \\\n    .with_url(os.environ.get('SIGNALR_HUB_URL', 'http://localhost:5000/hub')) \\\n    .configure_logging(logging.DEBUG, socket_trace=True, handler_mapping={\n        \"httpx\": logging.WARNING,\n        \"websocket\": logging.WARNING,\n        \"urllib3\": logging.WARNING\n    }) \\\n    .with_automatic_reconnect({\n        \"type\": \"interval\",\n        \"keep_alive_interval\": 10,\n        \"intervals\": [1, 2, 5, 10, 15, 30] # In seconds\n    }) \\\n    .build()\n\nhub_connection.on_open(lambda: print(\"Connection opened.\"))\nhub_connection.on_close(lambda: print(\"Connection closed.\"))\nhub_connection.on_error(lambda data: print(f\"Connection error: {data.error}\"))\n\n# Define a callback for a specific method on the hub\ndef receive_message(args):\n    print(f\"Received message: {args}\")\n\nhub_connection.on(\"ReceiveMessage\", receive_message)\n\nprint(\"Starting connection...\")\nhub_connection.start()\nprint(\"Connection started.\")\n\n# Keep the connection alive for some time and send a message\ntry:\n    # Give some time for the connection to establish and possibly auto-reconnect\n    time.sleep(5)\n    if hub_connection.connected:\n        print(\"Sending message to hub...\")\n        hub_connection.send(\"SendMessage\", [\"PythonClient\", \"Hello from Python!\"])\n        print(\"Message sent. Waiting for 30 seconds to receive messages or keep alive.\")\n        time.sleep(30) # Keep connection alive and listen for messages\n    else:\n        print(\"Connection not established or reconnected. Cannot send message.\")\n\nexcept KeyboardInterrupt:\n    pass\nfinally:\n    print(\"Stopping connection...\")\n    hub_connection.stop()\n    print(\"Connection stopped.\")","lang":"python","description":"This example demonstrates how to establish a connection to a SignalR hub, set up event handlers for connection status, register a callback for a server-side method, and send messages. It includes basic logging configuration and automatic reconnection, and uses an environment variable for the hub URL for better configurability. Remember to replace `http://localhost:5000/hub` with your actual SignalR hub URL."},"warnings":[{"fix":"Ensure your environment uses Python 3.9+ and update `msgpack` to `1.1.2` or the version specified in `signalrcore`'s `install_requires`.","message":"Version 1.0.1 and newer of `signalrcore` require Python 3.9 or higher. Additionally, the `msgpack` dependency was updated to `1.1.2`. Users on older Python versions or with conflicting `msgpack` installations may encounter compatibility issues upon upgrading.","severity":"breaking","affected_versions":"1.0.1+"},{"fix":"Always check `hub_connection.connected` before sending messages. Implement appropriate delays or listen for the `on_open` event before initiating message sends. Review logs (configured to DEBUG level) for connection status and re-connection attempts.","message":"The error 'Hub is not running you cant send messages' typically occurs when attempting to send data before the SignalR connection is fully established or after it has unexpectedly closed. The connection might take a few moments to negotiate and connect, especially with automatic reconnection configured.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `signalrcore` version 1.0.2 or newer to benefit from the fix for fragmented message handling.","message":"Prior to version 1.0.2, the client could experience 'fragmented messages error' when receiving large messages over WebSocket or Server-Sent Events transports. This could lead to incomplete message processing or connection instability.","severity":"gotcha","affected_versions":"<1.0.2"},{"fix":"Ensure that the casing of method names (e.g., `hub_connection.send(\"SendMessage\", ...)` vs. server's `SendMessage` or `sendMessage`) and user/group IDs matches exactly between your Python client and the SignalR server.","message":"SignalR hub method names invoked from the client, as well as user and group identifiers used for targeting specific clients on the server, are case-sensitive. A mismatch in casing between the client invocation and the server-side method or identifier can lead to calls silently failing or messages not being delivered.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}