Skip to main content

Python SignalR async client

Project description

SignalR-Async

Test Package version Supported Python versions

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"
    headers = {"Authorization": f"Bearer {token}"}
    async with Client(
        "https://localhost:9000",
        hub,
        connection_options={
            "http_client_options": {"headers": headers},
            "ws_client_options": {"headers": headers, "timeout": 1.0},
            "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


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-3.0.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

signalr_async-3.0.0-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file signalr-async-3.0.0.tar.gz.

File metadata

  • Download URL: signalr-async-3.0.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.12 Linux/5.15.21-1-MANJARO

File hashes

Hashes for signalr-async-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c1e746ef91968e48d0fb119e0fb5fac7af3d9833d4e593dfa8ca4dec3ac8a8d7
MD5 9fc65f2330e98366c21a4984cddd2152
BLAKE2b-256 2696b89c5725e5902a399af078b35a28e86b55d851ebb266d41f21e1ca654727

See more details on using hashes here.

File details

Details for the file signalr_async-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: signalr_async-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.12 Linux/5.15.21-1-MANJARO

File hashes

Hashes for signalr_async-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b687dd7243281257e3af0270365a5921db8570adcf759bc1a872c4e2d3e88d64
MD5 ec5b59714d9a0c72433a26ea669cc519
BLAKE2b-256 f52b7fba37b5c77c75913381cc937f79cf035d5cf9c4e1fb186f0192ab61ba74

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page