Python中ThriftPy已完全由开源社区接管,如何使用与尝鲜?
由于一些历史遗留问题,thriftpy 已经年久失修。但现在 thriftpy 已完全(通过富有 python 特色的方式)升级至 thriftpy2 并由开源社区承诺提供长期的稳定服务。就目前来说 gunicorn_thrift + thriftpy 应该依然是 Python 在生产中最佳的 thrift 实践。
目前饿了么依然有大量 Python/Go 开发职位虚位以待,如果你也对开源或者底层框架开发有兴趣,欢迎联系咨询!
Python中ThriftPy已完全由开源社区接管,如何使用与尝鲜?
4 回复
说起这个我就想起我给 apache thrift 写的几个 patch ( https://github.com/apache/thrift/commits?author=robberphex )<del>,中美合资</del>
😂请问还收简历吗?
ThriftPy现在确实由社区维护了,用起来和以前差不多。直接pip安装就行:
pip install thriftpy2
注意包名是thriftpy2,不是原来的thriftpy。写代码时导入也要用这个新名字:
import thriftpy2
from thriftpy2.rpc import make_server
# 定义Thrift IDL
pingpong_thrift = thriftpy2.load("pingpong.thrift", module_name="pingpong_thrift")
# 实现服务
class Dispatcher(object):
def ping(self):
return "pong"
# 启动服务
server = make_server(pingpong_thrift.PingService, Dispatcher(), '127.0.0.1', 6000)
server.serve()
客户端连接:
import thriftpy2
from thriftpy2.rpc import make_client
pingpong_thrift = thriftpy2.load("pingpong.thrift", module_name="pingpong_thrift")
client = make_client(pingpong_thrift.PingService, '127.0.0.1', 6000)
print(client.ping()) # 输出 pong
主要变化就是包名改了,API基本保持兼容。社区版修复了一些bug,支持Python 3.7+。如果你之前用thriftpy,改个导入语句就能迁移。
一句话建议:直接装thriftpy2用就行,API基本没变。
收,尤其是对 thrift 底层比较了解的我们非常欢迎的。


