SPILO
Spilo is lightweight library for developing real time applications which helps developers managing websocket clients effectively and gives ability to scale horizontaly for handling large amount of clients.
Installation
$ pip install spilo
Here's example of the backend code for a simple websocket server:
server.py
from typing import Dict
from dataclasses import dataclass
from fastapi import FastAPI, WebSocket
from spilo.channel import Channel
from spilo.base_client import BaseClient
from spilo.redis_pubsub import RedisPubSub
from spilo.event_registry import EventRegistry
app = FastAPI()
redis_pubsub = RedisPubSub()
redis_pubsub.connect()
event_registry = EventRegistry(event_key_name="event_type")
@dataclass
class Client(BaseClient):
protocol: WebSocket
def __hash__(self):
return self.client_id.int
async def send(self, data):
await self.protocol.send_text(str(data))
async def close(self):
await self.protocol.close()
async def listen(self):
return await self.protocol.receive_text()
@app.websocket("/ws/{channel_name}")
async def websocket_endpoint(websocket: WebSocket, channel_name: str):
await websocket.accept()
client = Client(protocol=websocket)
channel = Channel.get(channel_name, redis_pubsub, event_registry)
channel.add_client(client)
await channel.listen_client(client)
@event_registry.on("test")
async def test_event_handler(data: Dict, client: BaseClient, channel: Channel):
await client.send(str(data))
await channel.publish({"event_type": "test", "data": "test_data"})
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
spilo-1.0.0.tar.gz
(6.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
spilo-1.0.0-py3-none-any.whl
(8.4 kB
view details)
File details
Details for the file spilo-1.0.0.tar.gz.
File metadata
- Download URL: spilo-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c298b9014589c2b546abf81f1b421b28cffefee04ffa408b1846a56062ee9c25
|
|
| MD5 |
0f9037eda1af8970d9c795d90c21131c
|
|
| BLAKE2b-256 |
31caa3b5766b2ef11003c3ad0aa69e52554c67b40de0ab8b055cd74e52a64df6
|
File details
Details for the file spilo-1.0.0-py3-none-any.whl.
File metadata
- Download URL: spilo-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7deb4448884abfda6aaf994e0c666f4b185779707a3bc9637f16c541a2cc116
|
|
| MD5 |
603e5b11ea1dee615775dc6b88016e77
|
|
| BLAKE2b-256 |
c15f37584fef87eb385ea3fea211a0f90b3252131f97cb98b46a79842b597714
|