Skip to main content

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:
        channel.remove_client(client)

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

spilo-0.0.12.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spilo-0.0.12-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file spilo-0.0.12.tar.gz.

File metadata

  • Download URL: spilo-0.0.12.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for spilo-0.0.12.tar.gz
Algorithm Hash digest
SHA256 8f84ba56e734a996d326512139b2a8239200a4bd13e6fad3eb04fddc871d6ffe
MD5 31fcc411897f3eccd62e9c2ae79b84a6
BLAKE2b-256 762622dbe3b84c2dd37503b645ef7a79c0f41946890e32ea5765a2d79ce20210

See more details on using hashes here.

File details

Details for the file spilo-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: spilo-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for spilo-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 ba9c1e08443ae4fe6ac22d715ebee919ef37aa244e3243cb2f87613098da7182
MD5 2d994ef6214afa292af9dfd9a50129c9
BLAKE2b-256 3195a96a28ec7abb090146f51e436043e74ce941caeb851bf0289a6f376d36b0

See more details on using hashes here.

Supported by

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