python的pusher-websocket客户端,基于erik kulyk的python pusher client
inscribe-Pysher的Python项目详细描述
皮希尔
pysher
是一个用于处理pusher websockets的python模块。它基于@ekulyk的PythonPusherClient
。这个叉子的意思是
项目的延续并得到积极维护。一个关键的区别是不再支持3.5之前的python版本。
安装
只需运行python setup.py install
-或通过pip pip install pysher
安装。
此模块依赖于websocket客户端模块,可从以下位置获得:http://github.com/websocket-client/websocket-client
示例
使用此pusher客户端使用websockets的示例:
importpysher# Add a logging handler so we can see the raw communication dataimportloggingroot=logging.getLogger()root.setLevel(logging.INFO)ch=logging.StreamHandler(sys.stdout)root.addHandler(ch)pusher=pysher.Pusher(appkey)defmy_func(*args,**kwargs):print("processing Args:",args)print("processing Kwargs:",kwargs)# We can't subscribe until we've connected, so we use a callback handler# to subscribe when abledefconnect_handler(data):channel=pusher.subscribe('mychannel')channel.bind('myevent',my_func)pusher.connection.bind('pusher:connection_established',connect_handler)pusher.connect()whileTrue:# Do other things in the meantime here...time.sleep(1)
只需使用pusher提供的pusher客户机即可将pusher事件发送到通道。你可以在这里得到:https://github.com/pusher/pusher-http-python
import pusher
pusher.app_id = app_id
pusher.key = appkey
p = pusher.Pusher()
p['mychannel'].trigger('myevent', 'mydata')
性能
pysher依赖于websocket客户机(在pypi上的websocket客户机,在代码中导入websocket),默认情况下,它在纯python中执行utf5验证。对于大量的消息(100个kb/s或更多)来说,这有点占用cpu。要优化此验证,请考虑从pypi安装wsaccel模块,让websocket客户机使用c编译的utf5验证方法(一旦wsaccel存在并可导入,websocket就会自动执行此操作)。
谢谢
非常感谢@ekulyk开发了PythonPusherClient库。
版权所有
MTI许可证-有关详细信息,请参阅许可证。
更改日志
版本1.0.2
固定
- #38修复websocket应用程序回调丢失的
ẁs
arg,这要感谢@squgeim
版本1.0.0
更新
- #35仅支持WebSocket客户端>;0.48并修复重新连接错误,这要感谢@agronholm
^ {STR 1 } $此更改可能会破坏现有设置并且向后不兼容!
0.5.0版
添加了
- #14增加了对集群配置的支持,这要感谢@Yvictor
固定
版本0.4.2
固定:
- #11连接记录器中的全局记录器设置不再被覆盖
0.4.0版
添加:
- #8通过http代理添加对websocket的支持,这要感谢@1tgr
0.3.0版
添加:
- #7重新连接后自动重新订阅频道,感谢@pinealan
固定:
- #4,5更新了对库名称的引用,这要感谢@deanmaniatis
0.2.0版
添加:
- #2允许auth端点生成的令牌,这要感谢@wardcraigj
- #3允许使用自定义主机实例化,这要感谢@wardcraigj