Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mpetazzoni/sseclient
Pure-Python Server Side Events (SSE) client
https://github.com/mpetazzoni/sseclient
library python server-sent-events sse sseclient
Last synced: 5 days ago
JSON representation
Pure-Python Server Side Events (SSE) client
- Host: GitHub
- URL: https://github.com/mpetazzoni/sseclient
- Owner: mpetazzoni
- License: apache-2.0
- Created: 2016-03-11T22:15:14.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-03-01T17:29:29.000Z (10 months ago)
- Last Synced: 2024-12-14T21:00:46.290Z (12 days ago)
- Topics: library, python, server-sent-events, sse, sseclient
- Language: Python
- Size: 43 KB
- Stars: 198
- Watchers: 6
- Forks: 33
- Open Issues: 9
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Server Side Events (SSE) client for Python
==========================================A Python client for SSE event sources that seamlessly integrates with
``urllib3`` and ``requests``.Installation
------------.. code::
$ pip install sseclient-py
Usage
-----.. code:: python
import json
import pprint
import sseclientdef with_urllib3(url, headers):
"""Get a streaming response for the given event feed using urllib3."""
import urllib3
http = urllib3.PoolManager()
return http.request('GET', url, preload_content=False, headers=headers)def with_requests(url, headers):
"""Get a streaming response for the given event feed using requests."""
import requests
return requests.get(url, stream=True, headers=headers)def with_httpx(url, headers):
"""Get a streaming response for the given event feed using httpx."""
import httpx
with httpx.stream('GET', url, headers=headers) as s:
# Note: 'yield from' is Python >= 3.3. Use for/yield instead if you
# are using an earlier version.
yield from s.iter_bytes()url = 'http://domain.com/events'
headers = {'Accept': 'text/event-stream'}
response = with_urllib3(url, headers) # or with_requests(url, headers)
client = sseclient.SSEClient(response)
for event in client.events():
pprint.pprint(json.loads(event.data))Resources
=========- http://www.w3.org/TR/2009/WD-eventsource-20091029/
- https://pypi.python.org/pypi/sseclient-py/