anysocks

WebSocket protocol implementation for anyio


Keywords
anysocks, websockets, websocket, client, library, anyio, asyncio, clamor, curio, python, python3, trio, websocket-client, websocket-library
License
MIT
Install
pip install anysocks==0.2.2

Documentation

anysocks

This library implements the WebSocket protocol based on the Sans-IO library wsproto. I/O is handled by the anyio project which makes this library compatible to asyncio, trio and curio.

Build Status Maintainability CodeFactor Documentation Status PyPI version

Installation

This library requires Python 3.5+. You can install it directly from PyPI:

python3 -m pip install -U anysocks

If you want the cutting edge development version instead, install it directly from GitHub:

python3 -m pip install -U git+https://github.com/clamor-py/anysocks@master#egg=anysocks

Documentation

This README only provides a short overview, see the full documentation here.

Example

import anyio
from anysocks import open_connection


async def main():
    async with open_connection('wss://echo.websocket.org') as con:
        print('Connection established!')

        # First, let's send some text to the server.
        text = input('What to send? ')
        await con.send_message(text)

        # Now, we receive and verify the server's response.
        message = await con.get_message()
        assert message == text, "Received {}, expected {}".format(message, text)

    print('Connection closed with code {}', con.close_code.value)

anyio.run(main)