用于python的sse客户端
sseclient-p的Python项目详细描述
用于python的服务器端事件(sse)客户端
一个用于sse事件源的python客户机,它与 urllib3和requests。
安装
$ pip install sseclient-py
使用量
importjsonimportpprintimportsseclientdefwith_urllib3(url):"""Get a streaming response for the given event feed using urllib3."""importurllib3http=urllib3.PoolManager()returnhttp.request('GET',url,preload_content=False)defwith_requests(url):"""Get a streaming response for the given event feed using requests."""importrequestsreturnrequests.get(url,stream=True)url='http://domain.com/events'response=with_urllib3(url)# or with_requests(url)client=sseclient.SSEClient(response)foreventinclient.events():pprint.pprint(json.loads(event.data))