Welcome to Webshocket!

PyPI Version Supported Python Versions

Webshocket is a lightweight Python framework for WebSocket-based applications. It gives you a high-level API for remote procedure calls, per-client session state, pub/sub channels, and efficient message broadcasting — all built on top of asyncio and picows.

Note

This documentation is for version 0.5.2.

Key Features

  • RPC Framework — Call server-side functions from the client with send_rpc(). Supports streaming, rate limiting, and access control.

  • Streaming RPC — Server methods can yield values as async generators. The client iterates over chunks in real-time.

  • Session State — Attach data directly to connection objects (connection.username = "alice"). No external state store needed.

  • Pub/Sub Channels — Built-in channels with wildcard pattern matching (news.*, alerts.region.?).

  • Rate Limiting — Decorator-based rate limiting with human-readable periods ("5/1m").

  • Access Control — Protect RPC methods with composable predicates (Is, Has, IsEqual, Any, All).

  • Auto-Retry — Client reconnects automatically with exponential backoff.

  • Cross-Language — Framework clients use fast msgpack. Any WebSocket client (JS, Java, C#) can connect with plain JSON.

  • Secure by Default — Full SSL/TLS support via standard Python SSLContext.

User Guide

Indices and tables