不带传输层的简单JSON-RPC服务
JSONRPCBase的Python项目详细描述
jsonrpcbase
简介
不带传输层的简单JSON-RPC服务
该库旨在作为辅助库,方便使用UNIX/TCP套接字实现JSON-RPC服务。 类似于没有复杂特殊要求的传输协议。你需要使用合适的交通工具 与此库的协议,以实际提供工作的JSON-RPC服务。
功能
- 使用方便,体积小,测试良好。
- 支持JSON-RPC2.0。与v1.x风格的调用兼容,但v1.0类提示除外。
- 可选参数类型验证,大大简化了jsonrpc方法数据的开发。
示例
示例用法:
import jsonrpcbase chat_service = jsonrpcbase.JSONRPCService() def login(username, password, timelimit=0): (...) return True def receive_message(**kwargs): (...) return chat_message def send_message(msg): (...) if __name__ == '__main__': # Adds the method login to the service as a 'login'. chat_service.add(login, types=[basestring, basestring, int]) # Adds the method receive_message to the service as a 'recv_msg'. chat_service.add(receive_message, name='recv_msg', types={"msg": basestring, "id": int}) # Adds the method send_message as a 'send_msg' to the service. chat_service.add(send_message, 'send_msg') (...) # Receive a JSON-RPC call. jsonmsg = my_socket.recv() # Process the JSON-RPC call. result = chat_service.call(jsonmsg) # Send back results. my_socket.send(result)
变更日志
0.2.0发布于2016年11月30日
- 添加Python3支持(3.4和3.5)
- 在Circleci和Appveyor上设置持续集成测试
- 测试覆盖率在codecov上
0.1.2 2012-03-08发布
- 使用实例方法而不使用参数时的固定参数验证逻辑
- (姆莱韦林)