ksrpc


Nameksrpc JSON
Version 0.6.0 PyPI version JSON
download
home_pageNone
SummaryKeep Simple RPC
upload_time2025-09-19 06:09:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6
licenseMIT License Copyright (c) 2022 wukan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords rpc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ksrpc

Keep Simple RPC。免注册远程过程调用

!!! 注意:已经修剪成第二代。第一代请参考[fastapi](https://github.com/wukan1986/ksrpc/tree/fastapi)分支

## 第二代 vs 第一代

### 第一代

1. 功能比较多:IP黑白名单、函数黑白名单、内网反代、数据缓存、跨语言多数据格式
2. 实际考察发现,只有内网反代功能才是大家需要的,其他功能都极少有人用
3. 缺点:由于当初没有在数据包中加入请求编号或会话编号,多人都挤同房间数据会混乱
4. pip install ksrpc<0.6

### 第二代

1. 考虑到大家只关注内网反代,所以决定用更专业的反代工具,如:`frp`等
2. 删减功能,只留`API`调用+`Baisc`认证。
3. 某平台中的`FastAPI`所创建的服务只要访问,`uvicorn`就崩溃,最后决定将客服端和服务端都替换成`aiohttp`
4. `async`和`sync`的互转导致系统非常混乱,清理只留`async`。不改代码的`hack`功能作废
5. pip install ksrpc>=0.6

## 工作原理

1. 创建`Web`服务,接收请求后,调用服务器中的`Python`库,将结果二进制封装后返回
2. 客户端将API调用封装,然后向`Web`服务器请求,等待返回
3. 返回结果解包成`Python`对象
4. 反代时`frp`需要公网有服务器进行转发。当然你也可以使用其他组网工具,如`easytier`等

## 安装

```bash
pip install ksrpc -i https://mirrors.aliyun.com/pypi/simple --upgrade
# 或
pip install ksrpc -i https://pypi.org/simple --upgrade
```

## 使用

1. 服务端

```bash
python -m ksrpc.run_app
```

2. 客户端

```python
import asyncio

from ksrpc.client import RpcClient
from ksrpc.connections.http import HttpConnection

URL = 'http://127.0.0.1:8080/api/file'


async def async_main():
    async with HttpConnection(URL, username="admin", password="password123") as conn:
        demo = RpcClient('demo', conn)

        print(await demo.test())


asyncio.run(async_main())
```

更多代码参考`examples`目录

内网反代参考`examples_frp\README.md`

## 参考项目

开发到一定阶段后才发现与`rpyc`这个免注册暴露函数的功能类似,大家也可以去学习一下
https://github.com/tomerfiliba-org/rpyc

## 声明

此库仅供学习交流,请在数据提供方的授权范围内使用。请勿向第三方转发数据
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ksrpc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "rpc",
    "author": null,
    "author_email": "wukan <wu-kan@163.com>",
    "download_url": "https://files.pythonhosted.org/packages/e0/87/2a4ec8aa324941d910254b4a13f750101b8680aff9944a8523298c962a4d/ksrpc-0.6.0.tar.gz",
    "platform": null,
    "description": "# ksrpc\n\nKeep Simple RPC\u3002\u514d\u6ce8\u518c\u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528\n\n!!! \u6ce8\u610f\uff1a\u5df2\u7ecf\u4fee\u526a\u6210\u7b2c\u4e8c\u4ee3\u3002\u7b2c\u4e00\u4ee3\u8bf7\u53c2\u8003[fastapi](https://github.com/wukan1986/ksrpc/tree/fastapi)\u5206\u652f\n\n## \u7b2c\u4e8c\u4ee3 vs \u7b2c\u4e00\u4ee3\n\n### \u7b2c\u4e00\u4ee3\n\n1. \u529f\u80fd\u6bd4\u8f83\u591a\uff1aIP\u9ed1\u767d\u540d\u5355\u3001\u51fd\u6570\u9ed1\u767d\u540d\u5355\u3001\u5185\u7f51\u53cd\u4ee3\u3001\u6570\u636e\u7f13\u5b58\u3001\u8de8\u8bed\u8a00\u591a\u6570\u636e\u683c\u5f0f\n2. \u5b9e\u9645\u8003\u5bdf\u53d1\u73b0\uff0c\u53ea\u6709\u5185\u7f51\u53cd\u4ee3\u529f\u80fd\u624d\u662f\u5927\u5bb6\u9700\u8981\u7684\uff0c\u5176\u4ed6\u529f\u80fd\u90fd\u6781\u5c11\u6709\u4eba\u7528\n3. \u7f3a\u70b9\uff1a\u7531\u4e8e\u5f53\u521d\u6ca1\u6709\u5728\u6570\u636e\u5305\u4e2d\u52a0\u5165\u8bf7\u6c42\u7f16\u53f7\u6216\u4f1a\u8bdd\u7f16\u53f7\uff0c\u591a\u4eba\u90fd\u6324\u540c\u623f\u95f4\u6570\u636e\u4f1a\u6df7\u4e71\n4. pip install ksrpc<0.6\n\n### \u7b2c\u4e8c\u4ee3\n\n1. \u8003\u8651\u5230\u5927\u5bb6\u53ea\u5173\u6ce8\u5185\u7f51\u53cd\u4ee3\uff0c\u6240\u4ee5\u51b3\u5b9a\u7528\u66f4\u4e13\u4e1a\u7684\u53cd\u4ee3\u5de5\u5177\uff0c\u5982\uff1a`frp`\u7b49\n2. \u5220\u51cf\u529f\u80fd\uff0c\u53ea\u7559`API`\u8c03\u7528+`Baisc`\u8ba4\u8bc1\u3002\n3. \u67d0\u5e73\u53f0\u4e2d\u7684`FastAPI`\u6240\u521b\u5efa\u7684\u670d\u52a1\u53ea\u8981\u8bbf\u95ee\uff0c`uvicorn`\u5c31\u5d29\u6e83\uff0c\u6700\u540e\u51b3\u5b9a\u5c06\u5ba2\u670d\u7aef\u548c\u670d\u52a1\u7aef\u90fd\u66ff\u6362\u6210`aiohttp`\n4. `async`\u548c`sync`\u7684\u4e92\u8f6c\u5bfc\u81f4\u7cfb\u7edf\u975e\u5e38\u6df7\u4e71\uff0c\u6e05\u7406\u53ea\u7559`async`\u3002\u4e0d\u6539\u4ee3\u7801\u7684`hack`\u529f\u80fd\u4f5c\u5e9f\n5. pip install ksrpc>=0.6\n\n## \u5de5\u4f5c\u539f\u7406\n\n1. \u521b\u5efa`Web`\u670d\u52a1\uff0c\u63a5\u6536\u8bf7\u6c42\u540e\uff0c\u8c03\u7528\u670d\u52a1\u5668\u4e2d\u7684`Python`\u5e93\uff0c\u5c06\u7ed3\u679c\u4e8c\u8fdb\u5236\u5c01\u88c5\u540e\u8fd4\u56de\n2. \u5ba2\u6237\u7aef\u5c06API\u8c03\u7528\u5c01\u88c5\uff0c\u7136\u540e\u5411`Web`\u670d\u52a1\u5668\u8bf7\u6c42\uff0c\u7b49\u5f85\u8fd4\u56de\n3. \u8fd4\u56de\u7ed3\u679c\u89e3\u5305\u6210`Python`\u5bf9\u8c61\n4. \u53cd\u4ee3\u65f6`frp`\u9700\u8981\u516c\u7f51\u6709\u670d\u52a1\u5668\u8fdb\u884c\u8f6c\u53d1\u3002\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u7ec4\u7f51\u5de5\u5177\uff0c\u5982`easytier`\u7b49\n\n## \u5b89\u88c5\n\n```bash\npip install ksrpc -i https://mirrors.aliyun.com/pypi/simple --upgrade\n# \u6216\npip install ksrpc -i https://pypi.org/simple --upgrade\n```\n\n## \u4f7f\u7528\n\n1. \u670d\u52a1\u7aef\n\n```bash\npython -m ksrpc.run_app\n```\n\n2. \u5ba2\u6237\u7aef\n\n```python\nimport asyncio\n\nfrom ksrpc.client import RpcClient\nfrom ksrpc.connections.http import HttpConnection\n\nURL = 'http://127.0.0.1:8080/api/file'\n\n\nasync def async_main():\n    async with HttpConnection(URL, username=\"admin\", password=\"password123\") as conn:\n        demo = RpcClient('demo', conn)\n\n        print(await demo.test())\n\n\nasyncio.run(async_main())\n```\n\n\u66f4\u591a\u4ee3\u7801\u53c2\u8003`examples`\u76ee\u5f55\n\n\u5185\u7f51\u53cd\u4ee3\u53c2\u8003`examples_frp\\README.md`\n\n## \u53c2\u8003\u9879\u76ee\n\n\u5f00\u53d1\u5230\u4e00\u5b9a\u9636\u6bb5\u540e\u624d\u53d1\u73b0\u4e0e`rpyc`\u8fd9\u4e2a\u514d\u6ce8\u518c\u66b4\u9732\u51fd\u6570\u7684\u529f\u80fd\u7c7b\u4f3c\uff0c\u5927\u5bb6\u4e5f\u53ef\u4ee5\u53bb\u5b66\u4e60\u4e00\u4e0b\nhttps://github.com/tomerfiliba-org/rpyc\n\n## \u58f0\u660e\n\n\u6b64\u5e93\u4ec5\u4f9b\u5b66\u4e60\u4ea4\u6d41\uff0c\u8bf7\u5728\u6570\u636e\u63d0\u4f9b\u65b9\u7684\u6388\u6743\u8303\u56f4\u5185\u4f7f\u7528\u3002\u8bf7\u52ff\u5411\u7b2c\u4e09\u65b9\u8f6c\u53d1\u6570\u636e",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2022 wukan\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "Keep Simple RPC",
    "version": "0.6.0",
    "project_urls": null,
    "split_keywords": [
        "rpc"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "380a471afedc97bc9301a9c849626e50809658de751f4979658557c3280ee7cf",
                "md5": "9191dd82af1bbd440a3514e8696dd135",
                "sha256": "b7d753d1f4af9aef073a0792addb734bd3e3a4ffe4bdd53322b91ab89911432d"
            },
            "downloads": -1,
            "filename": "ksrpc-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9191dd82af1bbd440a3514e8696dd135",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 22651,
            "upload_time": "2025-09-19T06:09:14",
            "upload_time_iso_8601": "2025-09-19T06:09:14.165623Z",
            "url": "https://files.pythonhosted.org/packages/38/0a/471afedc97bc9301a9c849626e50809658de751f4979658557c3280ee7cf/ksrpc-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e0872a4ec8aa324941d910254b4a13f750101b8680aff9944a8523298c962a4d",
                "md5": "bd3c9b852de0ed7dd97a394e7cac9414",
                "sha256": "7d7a1176fa13df454febfdb593fe1fdd0ba41e33d458f9ecca0958675f63043a"
            },
            "downloads": -1,
            "filename": "ksrpc-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bd3c9b852de0ed7dd97a394e7cac9414",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 15268,
            "upload_time": "2025-09-19T06:09:15",
            "upload_time_iso_8601": "2025-09-19T06:09:15.381345Z",
            "url": "https://files.pythonhosted.org/packages/e0/87/2a4ec8aa324941d910254b4a13f750101b8680aff9944a8523298c962a4d/ksrpc-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-19 06:09:15",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ksrpc"
}
        
Elapsed time: 4.00417s