Registry / http-networking / pysignalr

pysignalr

JSON →
library1.3.2pypypi✓ verified 88d ago

pysignalr is a modern, reliable, and async-ready client for the SignalR protocol, designed to connect Python applications to SignalR hubs. It is currently at version 1.3.1 and maintains an active release cadence with regular updates and new feature additions, ensuring compatibility with the latest Python versions and SignalR protocol specifications.

pip install pysignalr
INSTALL
IMPORT
SIG · PYSIGNALR
P
pysignalr
http-networkingpythonv1.3.2
Install
4.8s avg
Import
704ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.600s · 30.1MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 4.8s · import 0.526s · 33MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SignalRClient
✓ from pysignalr.client import SignalRClient
CompletionMessage
✓ from pysignalr.messages import CompletionMessage

This quickstart demonstrates how to establish a connection to a SignalR hub, register event handlers for incoming messages, and send messages to the server. It includes examples for connection lifecycle events (open, close, error) and handling specific server events, including those requesting a client result.

import asyncio from contextlib import suppress from typing import Any, Dict, List from pysignalr.client import SignalRClient from pysignalr.messages import CompletionMessage import os async def on_open() -> None: print('Connected to the server') async def on_close() -> None: print('Disconnected from the server') async def on_message(message: List[Dict[str, Any]]) -> None: print(f'Received message: {message}') async def on_client_result(message: list[dict[str, Any]]) -> str: print(f'Received message requesting result: {message}') return 'reply_from_client' async def on_error(message: CompletionMessage) -> None: print(f'Received error: {message.error}') async def main() -> None: # Replace with your SignalR hub URL # For example, a public API like TzKT.io or your own local/remote hub signalr_url = os.environ.get('SIGNALR_HUB_URL', 'https://api.tzkt.io/v1/ws') access_token = os.environ.get('SIGNALR_ACCESS_TOKEN', '') # Optional: for authenticated hubs client_args = {'url': signalr_url} if access_token: # For authenticated hubs, provide an access token factory client_args['access_token_factory'] = lambda: access_token client = SignalRClient(**client_args) client.on_open(on_open) client.on_close(on_close) client.on_error(on_error) # Register handlers for specific events from the server client.on('operations', on_message) # Example: subscribing to 'operations' event client.on('client_result', on_client_result) # Example: handling a server request for a client result await asyncio.gather( client.run(), # Example: Sending a message to the server (e.g., to subscribe to a topic) client.send('SubscribeToOperations', [{}]), ) if __name__ == '__main__': with suppress(KeyboardInterrupt, asyncio.CancelledError): asyncio.run(main())
Debug
Known issues
breakingPython 3.9 support was officially dropped in `pysignalr` version 1.3.0. Users on Python 3.9 or older must upgrade their Python environment to at least 3.10 to use versions 1.3.0 and newer.
fix
Upgrade Python to version 3.10 or newer. If unable to upgrade, pin `pysignalr` to a version prior to 1.3.0 (e.g., `pysignalr<1.3.0`).
affects: >=1.3.0
gotchaVersion 1.3.1 introduced several fixes for SignalR Hub Protocol spec compliance in JSON and MessagePack codecs (e.g., `streamIds`, `invocationId`, `ResultKind`, headers, varint framing). Older versions might have exhibited non-compliant behavior that could lead to subtle issues or unexpected interactions with some SignalR servers.
fix
Upgrade to `pysignalr` version 1.3.1 or newer to ensure full protocol compliance and stability.
affects: <1.3.1
gotchaPrior to version 1.1.0, the reconnection logic in `pysignalr` was prone to issues. Applications relying on stable and automatic reconnections in the face of network interruptions might experience unreliability in older versions.
fix
Upgrade to `pysignalr` version 1.1.0 or newer to benefit from improved reconnection stability.
affects: <1.1.0
gotchaSignalR itself can silently fail to invoke client methods if the method name or signature sent from the server does not exactly match a registered client-side handler. The server will not receive an error.
fix
Ensure exact matching of method names and parameter types/counts between server invocations and client `on()` handlers. Enable client-side logging (`logging.DEBUG`) to diagnose unhandled messages or errors.
affects: All versions (SignalR protocol behavior)
gotchaThe `access_token_factory` argument was added in 1.1.0, allowing dynamic token generation for authentication. If you were using older, less flexible authentication methods or hardcoding tokens, you might need to refactor your authentication logic when upgrading to leverage this feature or if your token needs refreshing.
fix
Adopt the `access_token_factory` for dynamic token management, especially with expiring JWTs, to ensure continuous authentication without manual re-connection.
affects: <1.1.0
Errors
Common errors & fixes
AttributeError: 'NoneType' object has no attribute 'recv'
The `HubConnection` object's internal WebSocket client is `None` because the connection failed to establish or was closed unexpectedly, leading to `recv()` being called on a non-existent object.
fix
Ensure `await hub_connection.start()` completes successfully and implement robust error handling with reconnection logic to maintain an active connection.
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host
The pysignalr client failed to establish a basic network connection to the specified SignalR hub URL, typically due to an incorrect URL, an inaccessible host, or the server not running.
fix
Verify the SignalR hub URL (scheme, host, port) is absolutely correct and confirm that the SignalR server is running and network-accessible from the client's environment.
TypeError: 'NoneType' object is not callable
This usually occurs when `hub_connection.invoke()` returns `None`, often because the specified server method does not exist or failed to execute, and the subsequent code attempts to call this `None` result.
fix
Ensure the method name provided to `hub_connection.invoke()` precisely matches an existing, accessible method on the SignalR hub server, including correct casing, and check server logs for execution errors.
websockets.exceptions.ConnectionClosedOK
The WebSocket connection was actively closed by the SignalR server, which can happen due to inactivity, a server-side error, explicit disconnection, or adherence to the protocol.
fix
Implement automatic reconnection logic for the `hub_connection` within your application and consult server logs to understand the reason for the server-initiated connection closure.
Upgrade
Version history
1.3.2latest on PyPI · released Apr 17, 2026
Audit
Dependencies
websocketsrequiredCore dependency for WebSocket communication, frequently updated.
orjsonoptionalUsed for faster JSON deserialization, automatically detected if installed.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
pysignalr — pip install pysignalr · libregistry