{"id":28445688,"url":"https://github.com/cheesecake87/flask-rpc","last_synced_at":"2025-07-17T16:04:44.312Z","repository":{"id":233015194,"uuid":"785739717","full_name":"CheeseCake87/flask-rpc","owner":"CheeseCake87","description":"One route to rule them all!","archived":false,"fork":false,"pushed_at":"2024-12-04T13:49:48.000Z","size":84,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-01T22:40:59.170Z","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-12T14:18:22.000Z","updated_at":"2024-12-04T13:48:05.000Z","dependencies_parsed_at":"2024-04-24T14:41:26.566Z","dependency_job_id":"ac3e2bdc-558f-4edd-b900-4400566f1e0d","html_url":"https://github.com/CheeseCake87/flask-rpc","commit_stats":null,"previous_names":["cheesecake87/flask-rpc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CheeseCake87/flask-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fflask-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fflask-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fflask-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fflask-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CheeseCake87","download_url":"https://codeload.github.com/CheeseCake87/flask-rpc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseCake87%2Fflask-rpc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265625587,"owners_count":23800625,"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:37.776Z","updated_at":"2025-07-17T16:04:44.305Z","avatar_url":"https://github.com/CheeseCake87.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask-RPC 📣\n\n[![PyPI version](https://img.shields.io/pypi/v/flask-rpc)](https://pypi.org/project/flask-rpc/)\n[![License](https://img.shields.io/github/license/CheeseCake87/flask-rpc)](https://raw.githubusercontent.com/CheeseCake87/flask-rpc/master/LICENSE.txt)\n![black](https://img.shields.io/badge/code%20style-black-000000.svg)\n\n```bash\npip install flask-rpc\n```\n\n---\n\n\u003e 🚨 Seeking contributions to bring more RPC protocols to Flask-RPC.\n\nFlask - Remote Procedure Call (RPC) is a simple\nlibrary that allows you to expose functions\nin your Flask application to be called\nremotely. It is designed to be straightforward\nto use and easy to understand.\n\nFlask-RPC currently only uses the [weeRPC](https://github.com/CheeseCake87/weeRPC)\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\nFlask-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 of weeRPC 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/flask-rpc) contains a working example of Flask-RPC.\n\n```bash\nflask --app example run\n```\n\nIt also includes an example of using the [JS library](https://github.com/CheeseCake87/weeRPCjs) that helps\nin making requests via fetch to Flask-RPC.\n\n### Simplest example\n\n```python\nfrom flask import Flask\n\nfrom flask_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 = Flask(__name__)\nrpc = RPC(app, url_prefix=\"/rpc\")  # or RPC(blueprint)\nrpc.functions(\n    add_numbers=add_numbers\n)\n```\n\nor\n\n```python\n...\nRPC(\n    app,\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 flask_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 Flask session for a key value pair, this will apply\nthis check to every function registered.\n\n```python\nfrom flask_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 Flask session for a key value pair, but only in the\nspecified functions being registered.\n\n```python\nfrom flask_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\n### Scoped Host Auth\n\nOnly requests from `127.0.0.1:5000` will be accepted on the functions specified.\n\n```python\n...\nrpc = RPC(\n    app,  # or blueprint\n    url_prefix=\"/rpc\",\n)\nrpc.functions(\n    host_auth=[\"127.0.0.1:5000\"],\n    add_numbers=add_numbers\n)\n...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesecake87%2Fflask-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheesecake87%2Fflask-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesecake87%2Fflask-rpc/lists"}