Lightweight library for developing real time applications
Project description
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 dataclasses import dataclass
import uuid
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from spilo.channel import Channel
from spilo.base_client import BaseClient
from spilo.redis_pubsub import RedisPubSub
app = FastAPI()
redis_pubsub = RedisPubSub()
redis_pubsub.connect()
@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()
@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)
channel.add_client(client)
try:
while True:
data = await websocket.receive_text()
await channel.publish(data)
except WebSocketDisconnect:
await channel.remove_client(client)
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
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
File details
Details for the file spilo-0.0.15.tar.gz.
File metadata
- Download URL: spilo-0.0.15.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e09a57d7c5eb80a2fe6d12f6b2f1c2d0afa80c6e76b5ad285b2b98387d3aa27
|
|
| MD5 |
80fe6abcc86e9f173b1f76cef0e4f16e
|
|
| BLAKE2b-256 |
7c0482847e922855593e48af6b578f7ef995736cd14a91079a46e636b313d978
|
File details
Details for the file spilo-0.0.15-py3-none-any.whl.
File metadata
- Download URL: spilo-0.0.15-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9750bb85f795e646dc4e65a4c3b3821d8c336884676ef244128493c6c021e78a
|
|
| MD5 |
093103373b5c4a2301b1c03b8f084349
|
|
| BLAKE2b-256 |
48f1cc25b5f506f5f787d62377cb8231cff8a533ddfcd75525bca777502a21ef
|