{"id":28445633,"url":"https://github.com/cheesecake87/quart-rpc","last_synced_at":"2025-06-29T22:32:09.885Z","repository":{"id":233831597,"uuid":"787903159","full_name":"CheeseCake87/quart-rpc","owner":"CheeseCake87","description":"One async route to rule them all!","archived":false,"fork":false,"pushed_at":"2024-06-19T08:16:22.000Z","size":43,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-24T00:06:04.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/CheeseCake87.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":"2024-04-17T12:02:26.000Z","updated_at":"2024-06-19T08:16:25.000Z","dependencies_parsed_at":"2024-05-30T08:27:07.378Z","dependency_job_id":null,"html_url":"https://github.com/CheeseCake87/quart-rpc","commit_stats":null,"previous_names":["cheesecake87/quart-rpc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CheeseCake87/quart-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fquart-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fquart-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fquart-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fquart-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CheeseCake87","download_url":"https://codeload.github.com/CheeseCake87/quart-rpc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fquart-rpc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262678535,"owners_count":23347382,"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":[],"created_at":"2025-06-06T10:13:30.715Z","updated_at":"2025-06-29T22:32:09.855Z","avatar_url":"https://github.com/CheeseCake87.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📢 Quart-RPC\n\n```bash\npip install quart-rpc\n```\n\n---\n\n\u003e 🚨Seeking contributions to bring more RPC protocols to Quart-RPC.\n\nThe Quart implementation of [Flask-RPC](https://github.com/CheeseCake87/flask-rpc)\n\nQuart-RPC currently only uses the [weeRPC](https://github.com/CheeseCake87/wRPC) \nas its protocol, which is a micro JSON-based protocol that allows for\neasy communication between the client and server.\n\nThis extension is designed to stay slim and provides\nmethods for generating requests and responses.\n\nIt does not enforce or validate the data passed in, or the\ndata being sent back; this is left to you to implement\nin whatever way you feel comfortable (or not at all, if there's\nno need for it)\n\nQuart-RPC does validate the version of weeRPC on an incoming request. This \nis to ensure that the request is structured in a way that the version \nof RPC you are using expects.\n\nOther than that, you are free to use whatever data validation\nyou feel comfortable with. Pydantic and Marshmallow are good choices.\n\nThe typical request/response cycle is as follows:\n\n**Request**\n\n```json\n{\n  \"weerpc\": 1.1,\n  \"function\": \"add_numbers\",\n  \"data\": [\n    1,\n    2,\n    3\n  ]\n}\n```\n\n**Response**\n\n```json\n{\n  \"weerpc\": 1.1,\n  \"ok\": true,\n  \"message\": \"Function 'add_numbers' executed successfully\",\n  \"data\": 6\n}\n```\n\n## Usage\n\n[This repo](https://github.com/CheeseCake87/quart-rpc) contains a working example of Quart-RPC.\n\nIt also includes an example of using the [JS library](https://github.com/CheeseCake87/weeRPCjs) that helps\nin making requests via fetch to Quart-RPC.\n\n### Simplest example\n\n```python\nfrom quart import Quart\n\nfrom quart_rpc.latest import RPC, RPCResponse\n\n\ndef add_numbers(data):\n    if isinstance(data, list):\n        return RPCResponse.success(\n            sum(data),\n            \"Function 'add_numbers' executed successfully\"\n        )\n\n\napp = Quart(__name__)\nrpc = RPC(app, url_prefix=\"/rpc\")  # or blueprint\nrpc.functions(\n    add_numbers=add_numbers\n)\n```\n\nor \n\n```python\n...\nRPC(\n    app,   # or blueprint\n    url_prefix=\"/rpc\", \n    functions={\n        \"add_numbers\": add_numbers\n    }\n)\n...\n```\n\n`RPC(...)`\n\nWill register a POST route with the app or blueprint that you pass in.\n\n`rpc.functions(...)`\n\nWill register the functions that you pass in to be called remotely.\nThe argument names used will be the name of the function you will call remotely, for example:\n\n```python\nrpc.functions(\n    add_numbers=add_numbers,\n    subtract=subtract_numbers\n)\n```\n\nCalling `subtract` remotely will call the `subtract_numbers` function.\n\nA request to the `/rpc` endpoint with the following JSON payload:\n\n```python\nimport requests\nfrom quart_rpc import RPCRequest\n\nresponse = requests.post(\n    \"http://localhost:5000/rpc\",\n    json=RPCRequest.build(\n        function=\"add_numbers\",\n        data=[1, 2, 3]\n    )\n)\n```\n\nor, if you're using the [JS library](https://github.com/CheeseCake87/wrpc-js):\n\n```js\nfetch(\"/rpc\", {\n    method: \"POST\",\n    headers: {\n        \"Content-Type\": \"application/json\"\n    },\n    body: wrpc(\n        function_ = \"add_numbers\",\n        data = [1, 2, 3]\n    )\n})\n```\n\nWill return:\n\n```json\n{\n  \"wrpc\": 1.0,\n  \"ok\": true,\n  \"message\": \"Function 'add_numbers' executed successfully\",\n  \"data\": 6\n}\n```\n\n## Security\n\nYou can lock down RPC routes by using sessions and, or host checking.\n\n### Global Session Auth\n\nThis will check the Quart session for a key value pair, this will apply\nthis check to every function registered.\n\n```python\nfrom quart_rpc.latest import RPCAuthSessionKey\n```\n\n```python\n...\nRPC(\n    app,  # or blueprint\n    url_prefix=\"/rpc\",\n    session_auth=RPCAuthSessionKey(\"logged_in\", [True]),\n    functions={\n        \"add_numbers\": add_numbers\n    }\n)\n...\n```\n\nor a list of RPCAuthSessionKey:\n\n```python\n...\nRPC(\n    app,  # or blueprint\n    url_prefix=\"/rpc\",\n    session_auth=[\n        RPCAuthSessionKey(\"logged_in\", [True]),\n        RPCAuthSessionKey(\"user_type\", [\"admin\"])\n    ],\n    functions={\n        \"add_numbers\": add_numbers\n    }\n)\n...\n```\n\n### Global Host Auth\n\nIn the following example, only requests from `127.0.0.1:5000` will be accepted.\n\nThis will apply this check to all functions registered.\n\n```python\n...\nRPC(\n    app,  # or blueprint\n    url_prefix=\"/rpc\",\n    host_auth=[\"127.0.0.1:5000\"],\n    functions={\n        \"add_numbers\": add_numbers\n    }\n)\n...\n```\n\n### Scoped Session Auth\n\nThis will check the Quart session for a key value pair, but only in the\nspecified functions being registered.\n\n```python\nfrom quart_rpc.latest import RPCAuthSessionKey\n```\n\n```python\n...\nrpc = RPC(\n    app,  # or blueprint\n    url_prefix=\"/rpc\",\n)\nrpc.functions(\n    session_auth__=RPCAuthSessionKey(\"logged_in\", [True]),\n    add_numbers=add_numbers\n)\n...\n```\n\nLike the example above, you can also pass a list of RPCAuthSessionKey.\n\n```python\n...\nrpc.functions(\n    session_auth__=[\n        RPCAuthSessionKey(\"logged_in\", [True]),\n        RPCAuthSessionKey(\"user_type\", [\"admin\"])\n    ],\n    add_numbers=add_numbers\n)\n...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesecake87%2Fquart-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheesecake87%2Fquart-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesecake87%2Fquart-rpc/lists"}