{"id":29785490,"url":"https://github.com/floydous/webshocket","last_synced_at":"2026-02-11T06:12:02.443Z","repository":{"id":301522621,"uuid":"1009099367","full_name":"floydous/webshocket","owner":"floydous","description":"An enhanced module to provide a robust, socket-like abstraction for WebSockets","archived":false,"fork":false,"pushed_at":"2026-01-31T14:13:01.000Z","size":245,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-01T01:56:54.820Z","etag":null,"topics":["asynchronous","contributions-welcome","good-first-issue","good-first-pr","help-wanted","networking","python","python3","rpc","rpc-client","rpc-server","webshocket","websocket","websockets"],"latest_commit_sha":null,"homepage":"https://github.com/floydous/webshocket","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/floydous.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-26T15:16:46.000Z","updated_at":"2026-01-31T14:13:04.000Z","dependencies_parsed_at":"2026-01-31T16:02:25.943Z","dependency_job_id":null,"html_url":"https://github.com/floydous/webshocket","commit_stats":null,"previous_names":["floydous/webshocket"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/floydous/webshocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floydous%2Fwebshocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floydous%2Fwebshocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floydous%2Fwebshocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floydous%2Fwebshocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/floydous","download_url":"https://codeload.github.com/floydous/webshocket/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/floydous%2Fwebshocket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29328018,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T03:52:29.695Z","status":"ssl_error","status_checked_at":"2026-02-11T03:52:23.094Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous","contributions-welcome","good-first-issue","good-first-pr","help-wanted","networking","python","python3","rpc","rpc-client","rpc-server","webshocket","websocket","websockets"],"created_at":"2025-07-27T17:11:51.088Z","updated_at":"2026-02-11T06:12:02.437Z","avatar_url":"https://github.com/floydous.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![docs](https://readthedocs.org/projects/web-shocket/badge/?style=flat)](https://web-shocket.readthedocs.io/)\n[![Build Status](https://github.com/floydous/webshocket/actions/workflows/tests.yml/badge.svg)](https://github.com/floydous/webshocket/actions/workflows/tests.yml)\n[![PyPI Downloads](https://pepy.tech/badge/webshocket)](https://pepy.tech/project/webshocket)\n[![PyPI version](https://img.shields.io/pypi/v/webshocket)](https://pypi.org/project/webshocket/)\n[![License](https://img.shields.io/badge/License-MIT-blue)](https://opensource.org/license/mit)\n[![Code style: ruff](https://img.shields.io/badge/code_style-ruff-dafd5e)](https://github.com/astral-sh/ruff)\n\n\u003e [!WARNING]\n\u003e Webshocket is still unfinished and is not ready for proper-project use. It is advised to not expect any stability from this project until it reaches a stable release\n\n# Webshocket\n\nWebshocket is a lightweight Python framework designed to handle the complexity of WebSocket-based RPC applications. It provides a high-level API for remote procedure calls, per-client session management, and efficient message broadcasting.\n\n# Why Webshocket?\n\nExposing local TCP projects to the internet effectively often requires expensive paid tunnels or unstable free alternatives. Webshocket solves this by running over standard WebSockets, making it natively compatible with robust, free HTTP tunnel services like Cloudflare Argo and LocalTunnel.\n\nIt combines the simplicity of raw sockets with a rich feature set for easier development:\n\n- **Free Tunneling:** Works out-of-the-box with any HTTP/WebSocket tunnel.\n- **Developer Experience:** Includes a complete RPC system, session state management, rate limiting, and pub/sub channels—no complex middleware or global state required.\n\n## Comparison with Other WebSocket Libraries\n\n| Feature          | Webshocket                 | websockets      | socket.io           | FastAPI WS      |\n| ---------------- | -------------------------- | --------------- | ------------------- | --------------- |\n| RPC Layer        | ✅ Built-in                | ❌ Manual       | ⚠ Client-driven     | ❌ Manual       |\n| Session State    | ✅ Connection attrs        | ❌ Manual       | ✅ Rooms            | ❌ Manual       |\n| Predicates/Auth  | ✅ Built-in                | ❌ Manual       | ⚠ Library-dependent | ❌ Manual       |\n| Pub/Sub Channels | ✅ Built-in                | ❌ Manual       | ✅ Rooms            | ❌ Manual       |\n| Rate Limiting    | ✅ Decorator-based         | ❌ Manual       | ❌ Manual           | ⚠ Middleware    |\n| Auto-Retry       | ✅ Built-in (exp. backoff) | ❌ Manual       | ✅ Built-in         | ❌ Manual       |\n| HTTP Tunnels     | ✅ Designed for            | ✅ Compatible   | ⚠ HTTP fallback     | ✅ Compatible   |\n| Cross-Language   | ✅ Binary + JSON           | ⚠ Protocol only | ✅ Client libs      | ⚠ Protocol only |\n| Performance Core | picows (Cython)            | Pure Python     | JS-heavy            | ASGI stack      |\n\n# Unique Features at a Glance\n\nWebshocket simplifies complex networking logic into simple, object-oriented patterns.\n\n### 1. Powerful RPC with Access Control\n\nDefine server methods effortlessly and protect them with custom rules (predicates).\n\n```python\nclass MyHandler(webshocket.WebSocketHandler):\n    @webshocket.rpc_method(alias_name=\"add\")\n    async def add(self, _: webshocket.ClientConnection, a: int, b: int):\n        return a + b\n\n    # Unique: Use built-in predicates for clean access control\n    @webshocket.rpc_method(requires=webshocket.Is(\"is_admin\"))\n    async def secret_function(self, conn: webshocket.ClientConnection):\n        return \"Sensitive Data\"\n```\n\n### 2. Effortless Session State\n\nNo more look-up tables. Assign data directly to the client connection; Webshocket handles the persistence for you.\n\n```python\n    @webshocket.rpc_method()\n    async def login(self, connection: webshocket.ClientConnection, user_id: str):\n        # Direct attribute assignment persists for the session\n        connection.user_id = user_id\n        connection.is_admin = True\n\n        # Subscribe to updates immediately\n        connection.subscribe(\"broadcast-channel\")\n```\n\n### 3. Decorator-Based Rate Limiting\n\nProtect your RPC methods from abuse with a simple decorator. Supports human-readable periods and optional auto-disconnect.\n\n```python\nclass MyHandler(webshocket.WebSocketHandler):\n    @webshocket.rate_limit(limit=5, period=\"1m\")  # 5 calls per minute\n    @webshocket.rpc_method()\n    async def expensive_operation(self, connection: webshocket.ClientConnection, query: str):\n        return await run_ai_model(query)\n\n    @webshocket.rate_limit(limit=100, period=\"10s\", disconnect_on_limit_exceeded=True)\n    @webshocket.rpc_method()\n    async def chat_message(self, connection: webshocket.ClientConnection, msg: str):\n        return await process_message(msg)\n```\n\n### 4. Pub/Sub Channels with Smart Filtering\n\nSubscribe clients to channels, then publish messages with optional predicates to filter recipients.\n\n```python\nclass GameHandler(webshocket.WebSocketHandler):\n    @webshocket.rpc_method()\n    async def join_game(self, connection: webshocket.ClientConnection, room: str):\n        connection.subscribe(room)\n        connection.team = \"red\"\n\n    @webshocket.rpc_method()\n    async def send_team_update(self, connection: webshocket.ClientConnection, room: str, data):\n        # Only publish to players on the \"red\" team in this room\n        self.publish(room, data, predicate=webshocket.IsEqual(\"team\", \"red\"))\n\n        # Or broadcast to ALL connected clients who are admins\n        self.broadcast(\"Server announcement\", predicate=webshocket.Is(\"is_admin\"))\n```\n\n### 5. Auto-Retry with Exponential Backoff\n\nThe client handles reconnection automatically — no manual retry loops needed.\n\n```python\nasync def main():\n    client = webshocket.WebSocketClient(\"ws://your-tunnel.url\")\n    await client.connect(retry=True, max_retry_attempt=5, retry_interval=2)\n\n    result = await client.send_rpc(\"add\", 10, 20)\n    print(result.data)  # 30\n```\n\n### 6. Integrated Tunnelling \u0026 Deployment\n\nDesigned to run perfectly behind free HTTP tunnels, making it the easiest way to expose a local AI or IoT project to the world.\n\n```python\nasync def main():\n    server = webshocket.WebSocketServer(\"0.0.0.0\", 5000, clientHandler=MyHandler)\n    async with server:\n        await server.serve_forever()\n```\n\n### 7. Cross-Language Compatibility\n\nWebshocket is designed to be language-agnostic. While the Python client is optimized with MessagePack, the server natively understands **standard JSON packets**. This means you can build a client in **JavaScript**, Java, or C# using nothing but the standard library.\n\n```javascript\n// Example: Standard Browser JavaScript Client\nconst socket = new WebSocket(\"ws://your-tunnel.url\");\n\nsocket.onopen = () =\u003e {\n\tconst rpcRequest = {\n\t\trpc: {\n\t\t\ttype: \"request\",\n\t\t\tmethod: \"add\",\n\t\t\targs: [10, 20],\n\t\t\tkwargs: {},\n\t\t},\n\t\tsource: 5,\n\t};\n\n\tsocket.send(JSON.stringify(rpcRequest));\n};\n\nsocket.onmessage = async (event) =\u003e {\n\tconst packet = JSON.parse(await event.data.text());\n\tconsole.log(\"Result:\", packet.rpc.response); // 30\n};\n```\n\n# Contributing\n\nContributions are welcome! Please feel free to open an issue or submit a pull request on our GitHub repository.\n\n# License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloydous%2Fwebshocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffloydous%2Fwebshocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffloydous%2Fwebshocket/lists"}