{"id":15009513,"url":"https://github.com/wsrpc/wsrpc-aiohttp","last_synced_at":"2025-04-09T17:24:45.587Z","repository":{"id":42520420,"uuid":"99600868","full_name":"wsrpc/wsrpc-aiohttp","owner":"wsrpc","description":"WebSocket RPC for aiohttp","archived":false,"fork":false,"pushed_at":"2023-11-28T00:38:51.000Z","size":22948,"stargazers_count":30,"open_issues_count":15,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-01T11:47:22.467Z","etag":null,"topics":["aiohttp","async","python-3-5","python3","websocket","websocket-client","websocket-server","ws"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wsrpc.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2017-08-07T17:05:12.000Z","updated_at":"2024-06-27T18:15:59.000Z","dependencies_parsed_at":"2024-06-21T13:24:20.205Z","dependency_job_id":null,"html_url":"https://github.com/wsrpc/wsrpc-aiohttp","commit_stats":{"total_commits":206,"total_committers":14,"mean_commits":"14.714285714285714","dds":0.3203883495145631,"last_synced_commit":"246be530dcb9c600815fe39cd184b4f4d1bed0ce"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsrpc%2Fwsrpc-aiohttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsrpc%2Fwsrpc-aiohttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsrpc%2Fwsrpc-aiohttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsrpc%2Fwsrpc-aiohttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wsrpc","download_url":"https://codeload.github.com/wsrpc/wsrpc-aiohttp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075669,"owners_count":21043631,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["aiohttp","async","python-3-5","python3","websocket","websocket-client","websocket-server","ws"],"created_at":"2024-09-24T19:25:57.790Z","updated_at":"2025-04-09T17:24:45.571Z","avatar_url":"https://github.com/wsrpc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WSRPC aiohttp\n\n[![Github Actions](https://github.com/wsrpc/wsrpc-aiohttp/workflows/tests/badge.svg)](https://github.com/wsrpc/wsrpc-aiohttp/actions?query=branch%3Amaster)\n\n[![Coveralls](https://coveralls.io/repos/github/wsrpc/wsrpc-aiohttp/badge.svg?branch=master)](https://coveralls.io/github/wsrpc/wsrpc-aiohttp?branch=master)\n\n[![Latest Version](https://img.shields.io/pypi/v/wsrpc-aiohttp.svg)](https://pypi.python.org/pypi/wsrpc-aiohttp/)\n\n[![python wheel](https://img.shields.io/pypi/wheel/wsrpc-aiohttp.svg)](https://pypi.python.org/pypi/wsrpc-aiohttp/)\n\n[![Python Versions](https://img.shields.io/pypi/pyversions/wsrpc-aiohttp.svg)](https://pypi.python.org/pypi/wsrpc-aiohttp/)\n\n[![license](https://img.shields.io/pypi/l/wsrpc-aiohttp.svg)](https://pypi.python.org/pypi/wsrpc-aiohttp/)\n\nEasy to use minimal WebSocket Remote Procedure Call library for aiohttp\nservers.\n\nSee [online demo](https://demo.wsrpc.info/) and\n[documentation](https://docs.wsrpc.info/) with examples.\n\n## Features\n\n-   Call server functions from the client side;\n-   Call client functions from the server (for example to notify clients\n    about events);\n-   Async connection protocol: both server or client are able to call\n    several functions and get responses as soon as each response would\n    be ready in any order.\n-   Fully async server-side functions;\n-   Transfer any exceptions from a client side to the server side and\n    vise versa;\n-   Ready-to-use frontend-library without dependencies;\n-   Thread-based websocket handler for writing fully-synchronous backend\n    code (for synchronous database drivers etc.)\n-   Protected server-side methods (cliens are not able to call methods,\n    starting with underline directly);\n-   Signals for introspection\n\n## Installation\n\nInstall via pip:\n\n    pip install wsrpc-aiohttp\n\nYou may want to install *optional*\n[ujson](https://pypi.python.org/pypi/ujson) library to speedup message\nserialization/deserialization:\n\n    pip install ujson\n\nPython module provides client js library out of the box. But for pure\njavascript applications you can install [standalone js client\nlibrary](https://www.npmjs.com/package/@wsrpc/client) using npm:\n\n    npm install @wsrpc/client\n\n## Usage\n\nBackend code:\n\n``` python\nimport logging\nfrom time import time\n\nimport aiohttp.web\nfrom wsrpc_aiohttp import Route, STATIC_DIR, WebSocketRoute, decorators\n\n\nlog = logging.getLogger(__name__)\n\n\n# This class can be called by client.\n# Connection object will have this class instance after calling route-alias.\nclass TestRoute(Route):\n    # This method will be executed when client calls route-alias\n    # for the first time.\n    def init(self, **kwargs):\n        # Python __init__ must be return \"self\".\n        # This method might return anything.\n        return kwargs\n\n    # This method named by camelCase because the client can call it.\n    @decorators.proxy\n    async def getEpoch(self):\n\n        # You can execute functions on the client side\n        await self.do_notify()\n\n        return time()\n\n    # This method calls function on the client side\n    @decorators.proxy\n    async def do_notify(self):\n        awesome = 'Somebody executed test1.getEpoch method!'\n        await self.socket.call('notify', result=awesome)\n\n\napp = aiohttp.web.Application()\napp.router.add_route(\"*\", \"/ws/\", WebSocketAsync)  # Websocket route\napp.router.add_static('/js', STATIC_DIR)  # WSRPC js library\napp.router.add_static('/', \".\")  # Your static files\n\n# Stateful request\n# This is the route alias TestRoute as \"test1\"\nWebSocketAsync.add_route('test1', TestRoute)\n\n# Stateless request\nWebSocketAsync.add_route('test2', lambda *a, **kw: True)\n\n\nif __name__ == '__main__':\n    logging.basicConfig(level=logging.DEBUG)\n    aiohttp.web.run_app(app, port=8000)\n```\n\nFrontend code:\n\n``` HTML\n\u003cscript type=\"text/javascript\" src=\"/js/wsrpc.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    var url = (window.location.protocol===\"https):\"?\"wss://\":\"ws://\") + window.location.host + '/ws/';\n    RPC = new WSRPC(url, 8000);\n\n    // Configure client API, that can be called from server\n    RPC.addRoute('notify', function (data) {\n        console.log('Server called client route \"notify\":', data);\n        return data.result;\n    });\n    RPC.connect();\n\n    // Call stateful route\n    // After you call that route, server would execute 'notify' route on the\n    // client, that is registered above.\n    RPC.call('test1.getEpoch').then(function (data) {\n        console.log('Result for calling server route \"test1.getEpoch\": ', data);\n    }, function (error) {\n        alert(error);\n    });\n\n    // Call stateless method\n    RPC.call('test2').then(function (data) {\n        console.log('Result for calling server route \"test2\"', data);\n    });\n\u003c/script\u003e\n```\n\n## Build\n\nJust run\n\n    ```bash\n    poetry run nox\n    ```\n\n## Versioning\n\nThis software follows [Semantic Versioning](http://semver.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsrpc%2Fwsrpc-aiohttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwsrpc%2Fwsrpc-aiohttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsrpc%2Fwsrpc-aiohttp/lists"}