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.14.tar.gz (5.1 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.14-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spilo-0.0.14.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

Hashes for spilo-0.0.14.tar.gz
Algorithm Hash digest
SHA256 0113ed3f14e18e1fd677d9148f43a77f83e979ecd230e32c3a6374f70f17b402
MD5 3b8bedcd57a3da660c1c67e3b0351af1
BLAKE2b-256 b8d66af338ac5c457295e7f1d0f8e4a9f884f677e60a84ef0ea0736629004a36

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spilo-0.0.14-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

Hashes for spilo-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 5403cbe8ba7b2f5b3aab340e18a7a0e8a0ebbb707c6c893c9d6464f13864b5fc
MD5 51bf2ccec659833e7b205257835e3c2f
BLAKE2b-256 a1292daa7171b4fbf43e75378a40be255a4f8b770de509109987b974d1d1d755

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