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.10.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.10-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spilo-0.0.10.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.10.tar.gz
Algorithm Hash digest
SHA256 e7b3ef3f41c494c17e3fc66997d9dd87655c9e0742439914d67f7cc2c15efe6e
MD5 bc7e2d90e2c388db56408d8ba759edb1
BLAKE2b-256 369f7d24587b655129daeca05172a69ffdf901c8921f71ad84dfd8f7482a3cf7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spilo-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ea1b48c9a599a8186a62e91b3f4b4f253edcd1352a0fe361f0f44bb00b37e7f2
MD5 fe4c4c374654a621657dbc5bff3341a2
BLAKE2b-256 73a6a1345205c6e48404c6332ebb522b7d791306e5d01e08d74a73b6b77eaca5

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