Skip to main content

An event-driven WebSocket library for Python.

Project description

wsaio

An event-driven WebSocket library for Python built on top of asyncio's protocols.

import asyncio
import itertools

import wsaio

URL = 'wss://echo.websocket.org'


class HelloClient(wsaio.WebSocketClient):
    async def ws_connected(self):
        for i in itertools.count():
            print(f'[HelloClient] Sending data - COUNT: {i}')
            await self.send_str('Hello World')
            await asyncio.sleep(5)

    def ws_text_received(self, data):
        print(f'[HelloClient] Received frame - DATA: {data}')

    def closing_connection(self, exc):
        print(f'[HelloClient] Closed while {self.strstate()}', str(exc))


client = HelloClient()
client.loop.create_task(client.connect(URL))
client.loop.run_forever()

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

wsaio-0.0.6.tar.gz (7.7 kB view hashes)

Uploaded Source

Supported by

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