Metadata-Version: 2.1
Name: signalr-async
Version: 2.1.0
Summary: Python SignalR async client
Home-page: https://github.com/sam-mosleh/signalr-async
License: MIT
Keywords: SignalR,SignalR client,Real-time messaging
Author: Sam Mosleh
Author-email: sam.mosleh@ut.ac.ir
Requires-Python: >=3.8,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: aiohttp (>=3.6.0,<4.0.0)
Requires-Dist: msgpack (>=1.0.2,<2.0.0)
Description-Content-Type: text/markdown

# SignalR-Async

<p align="center">
<a href="https://app.travis-ci.com/sam-mosleh/signalr-async" target="_blank">
    <img src="https://app.travis-ci.com/sam-mosleh/signalr-async.svg?branch=master" alt="Test">
</a>

<a href="https://codecov.io/gh/sam-mosleh/signalr-async">
  <img src="https://codecov.io/gh/sam-mosleh/signalr-async/branch/master/graph/badge.svg?token=JYBKXSFAX6"/>
</a>

<a href="https://pypi.org/project/signalr-async/" target="_blank">
    <img src="https://img.shields.io/pypi/v/signalr-async" alt="Package version">
</a>
<a href="https://pypi.org/project/signalr-async/" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/signalr-async.svg" alt="Supported Python versions">
</a>
</p>

SignalR-Async is a python client for ASP.NET & ASP.NET Core SignalR, ready for building bidirectional communication.

## Installation

```bash
pip install signalr-async
```

## Example

### Create it

* Create a file `main.py` with:

```Python
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](https://docs.microsoft.com/aspnet/core/signalr) at docs.microsoft.com for documentation on the latest release.

