Server API
aiosignalr.server
SignalRServer
The hub server. See the server guide for usage.
SignalRServer(
hub: type[Hub],
*,
options: ServerOptions | None = None,
logger: logging.Logger | None = None,
)
Methods & attributes
| Member | Description |
|---|---|
protocol_registry | {"json": JSONProtocol, "messagepack": MessagePackProtocol} |
lifetime | HubLifetimeManager used for broadcasts/groups |
dispatcher | HubDispatcher that binds hub methods |
async serve(host, port, *, path="/hub") -> tuple[str, int] | Run standalone aiohttp server |
create_application(*, path="/hub") | Build the aiohttp app |
asgi_app(*, path="/hub") | Build an ASGI app for uvicorn/FastAPI |
async close() | Shut down the standalone server |
get_connection(connection_id) | Look up a live connection context |
ServerOptions
| Field | Default | Description |
|---|---|---|
keep_alive_interval | 15.0 | Server ping interval |
client_timeout_interval | 30.0 | Silent-client timeout |
handshake_timeout | 15.0 | Handshake deadline |
maximum_parallel_invocations | 1 | Concurrent invocations per connection |
maximum_receive_message_size | 32768 | Max inbound frame size |
stream_buffer_capacity | 10 | Upload-stream queue capacity |
long_polling_timeout | 15.0 | Long poll duration |
enable_detailed_errors | False | Send exception details to clients |
allow_stateful_reconnects | False | Enable stateful reconnect |
stateful_reconnect_buffer_size | 100_000 | Outbound buffer bytes |
stateful_reconnect_timeout | 30.0 | Seconds a dropped connection is kept |
Hub
Base class for hubs. Public methods become invocable; async generators become streaming methods.
self.clients—HubClientsproxy (see below).self.groups—GroupsManagerfor the caller's membership.self.context—HubContextwithconnection_id,headers,query,user_id.async on_connected()— per-connection hook.async on_disconnected(exception)— per-connection hook.
HubClients
| Member | Description |
|---|---|
all_ | Proxy for every client (send(method, *args)) |
others | Every client except the caller |
connection(id) | A single connection |
connections(ids) | Several connections |
group(name) | Members of a group |
groups(names) | Members of several groups |
user(id) | Connections with a user id |
users(ids) | Connections with several user ids |
caller | The calling client (invoke(...) supports client results) |
HubLifetimeManager / DefaultHubLifetimeManager
Abstract registry used for broadcasts and groups. DefaultHubLifetimeManager
is the in-memory implementation: it tracks connections, maintains groups and
serializes each broadcast once per protocol. Subclass it to plug in a
distributed backplane.
HubConnectionContext
Per-connection server state (connection id, negotiated protocol, outbound
transport, message buffer, invocation tracking). Normally you interact with it
only via self.context in hub methods or custom lifetime/dispatcher code.
has_transport— whether an outbound transport is attached.connection_id— logical connection id.use_stateful_reconnect— whether the ack protocol is active.async send(message)/send_bytes(data)/send_serialized(data)— outbound writes (the buffer-aware path).wait_closed()— resolves when the connection closes.
IncomingStream
Async-iterable bound to an upload-stream parameter (async for item in stream).
StreamTracker
Tracks client-to-server upload streams for a connection.
HubDispatcher
Discovers hub methods and routes messages. See method resolution rules.
asgi_app
asgi_app(server, *, path="/hub") — returns a plain ASGI app; also available as
server.asgi_app().