Python SignalR async client
Project description
SignalR-Async
SignalR-Async is a python client for ASP.NET & ASP.NET Core SignalR, ready for building bidirectional communication.
Installation
pip install signalr-async
Example
Create it
- Create a file
main.py
with:
import asyncio
from signalr_async.netcore import Hub, Client
from signalr_async.netcore.protocols import MessagePackProtocol
class MyHub(Hub):
async def on_connect(self, connection_id: str) -> None:
"""Will be awaited after connection established"""
async def on_disconnect(self) -> None:
"""Will be awaited after client disconnection"""
def on_event_one(self, x: bool, y: str) -> None:
"""Invoked by server synchronously on (event_one)"""
async def on_event_two(self, x: bool, y: str) -> None:
"""Invoked by server asynchronously on (event_two)"""
async def get_something(self) -> bool:
"""Invoke (method) on server"""
return await self.invoke("method", "arg1", 2)
hub = MyHub("my-hub")
@hub.on("event_three")
async def three(z: int) -> None:
pass
@hub.on
async def event_four(z: int) -> None:
pass
async def multi_event(z: int) -> None:
pass
for i in range(10):
hub.on(f"event_{i}", multi_event)
async def main():
token = "mytoken"
async with Client(
"https://localhost:9000",
hub,
connection_options={
"extra_headers": {"Authorization": f"Bearer {token}"},
"protocol": MessagePackProtocol(),
},
) as client:
return await hub.get_something()
asyncio.run(main())
Resources
See the SignalR Documentation at docs.microsoft.com for documentation on the latest release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
signalr-async-2.3.1.tar.gz
(15.2 kB
view hashes)
Built Distribution
Close
Hashes for signalr_async-2.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5f4018718f0750637b2cd4e2331ba7fb3f3637131f41786ef27c9eddef573b9 |
|
MD5 | 79fc12aa4f27f18b21225119db0e0c43 |
|
BLAKE2b-256 | 682680d09ccf0c0672c1d10846878d9cb9020fb48e686622a2fe6c03b11a7b91 |