Skip to main content

A Simple Python Library for RPC

Project description

RPC 项目

这是一个基于TCP协议的RPC(远程过程调用)项目,包含客户端和服务器端的实现。该项目允许客户端通过网络调用服务器上的函数。 alt text

项目结构

  • src/

    • rpc/

      • __init__.py: 包含RPC客户端和服务器端的初始化代码。
      • client.py: 包含RPC客户端的实现。
      • server.py: 包含RPC服务器端的实现。
      • tcp.py: 包含TCP客户端和服务器端的实现。
    • tests/

      • test_rpc.py: 包含针对RPC客户端和服务器端的测试代码。

安装

1. 克隆代码库:

```sh
git clone https://github.com/King-sj/krpc.git
cd krpc
```
  1. 安装依赖项:
pip install -r requirements.txt

使用方法

启动服务器

在服务器端,创建一个RPC服务器并注册要暴露的函数:

from rpc.server import RPCServer

def test_function(*args, **kwargs):
    return f"function test called with args: {args} and kwargs: {kwargs}"

server = RPCServer()
server.register(test_function)
server.loop('127.0.0.1', 8000)

启动客户端

在客户端,创建一个RPC客户端并连接到服务器:

from rpc.client import RPCClient

client = RPCClient()
client.connect('127.0.0.1', 8000)
result = client.test_function('测试项', kw1="1")
print(result)  # 输出: function test called with args: ('测试项',) and kwargs: {'kw1': '1'}

测试

使用pytest运行测试:

pytest tests/test_rpc.py

开发

依赖项

项目依赖项在pyproject.toml文件中定义。使用以下命令安装开发依赖项:

pip install flit
flit install --deps develop

代码风格

使用flake8black检查代码风格:

flake8 src/
black src/

类型检查

使用pyright进行类型检查:

pyright src/

贡献

欢迎贡献和建议!请提交拉取请求或报告问题。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ksj_rpc-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ksj_rpc-1.0.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file ksj_rpc-1.0.0.tar.gz.

File metadata

  • Download URL: ksj_rpc-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for ksj_rpc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 75d6656d8cae5eb2b64e1961171bdc940e54c7db556ae545a92d4891507154db
MD5 999053cccffe770080e2db80c3152e5b
BLAKE2b-256 61ed3f381f8580a3556d9aa51a0c6587fcec48d5053e7658ff79d83ec78c1f43

See more details on using hashes here.

File details

Details for the file ksj_rpc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ksj_rpc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for ksj_rpc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac594d03b684c25f209226e4af7cb2ab082654c69bddfb879a5f2fcfcf9b8723
MD5 cf76e69b7be199d1d3a1d6a52e2af3b7
BLAKE2b-256 ff97e3d8953c140770f0dc7b23dada242d3d99f956778785dd7809576ca76161

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page