websockets

16.0 · active · verified Sat Mar 28

An implementation of the WebSocket Protocol (RFC 6455 & 7692) for Python, currently at version 16.0, with a release cadence of approximately every 6 months.

Warnings

Install

Imports

Quickstart

A simple WebSocket server that echoes messages received from clients.

import asyncio
from websockets import serve

async def handler(websocket, path):
    async for message in websocket:
        await websocket.send(f'Hello, {message}!')

async def main():
    async with serve(handler, 'localhost', 8765):
        await asyncio.Future()  # Run forever

if __name__ == '__main__':
    asyncio.run(main())

view raw JSON →