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 sseclient
def 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/
Raw data
{
"_id": null,
"home_page": "https://github.com/mpetazzoni/sseclient",
"name": "sseclient-py",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Maxime Petazzoni",
"author_email": "maxime.petazzoni@bulix.org",
"download_url": "https://files.pythonhosted.org/packages/e8/ed/3df5ab8bb0c12f86c28d0cadb11ed1de44a92ed35ce7ff4fd5518a809325/sseclient-py-1.8.0.tar.gz",
"platform": null,
"description": "Server Side Events (SSE) client for Python\n==========================================\n\nA Python client for SSE event sources that seamlessly integrates with\n``urllib3`` and ``requests``.\n\nInstallation\n------------\n\n.. code::\n\n $ pip install sseclient-py\n\nUsage\n-----\n\n.. code:: python\n\n import json\n import pprint\n import sseclient\n\n def with_urllib3(url, headers):\n \"\"\"Get a streaming response for the given event feed using urllib3.\"\"\"\n import urllib3\n http = urllib3.PoolManager()\n return http.request('GET', url, preload_content=False, headers=headers)\n\n def with_requests(url, headers):\n \"\"\"Get a streaming response for the given event feed using requests.\"\"\"\n import requests\n return requests.get(url, stream=True, headers=headers)\n\n def with_httpx(url, headers):\n \"\"\"Get a streaming response for the given event feed using httpx.\"\"\"\n import httpx\n with httpx.stream('GET', url, headers=headers) as s:\n # Note: 'yield from' is Python >= 3.3. Use for/yield instead if you\n # are using an earlier version.\n yield from s.iter_bytes()\n\n\n url = 'http://domain.com/events'\n headers = {'Accept': 'text/event-stream'}\n response = with_urllib3(url, headers) # or with_requests(url, headers)\n client = sseclient.SSEClient(response)\n for event in client.events():\n pprint.pprint(json.loads(event.data))\n\nResources\n=========\n\n- http://www.w3.org/TR/2009/WD-eventsource-20091029/\n- https://pypi.python.org/pypi/sseclient-py/\n",
"bugtrack_url": null,
"license": "Apache Software License v2",
"summary": "SSE client for Python",
"version": "1.8.0",
"project_urls": {
"Homepage": "https://github.com/mpetazzoni/sseclient"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "495897655efdfeb5b4eeab85b1fc5d3fa1023661246c2ab2a26ea8e47402d4f2",
"md5": "dc4ebc32d5a27c0002059381bee4a31f",
"sha256": "4ecca6dc0b9f963f8384e9d7fd529bf93dd7d708144c4fb5da0e0a1a926fee83"
},
"downloads": -1,
"filename": "sseclient_py-1.8.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "dc4ebc32d5a27c0002059381bee4a31f",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 8828,
"upload_time": "2023-09-01T19:39:17",
"upload_time_iso_8601": "2023-09-01T19:39:17.627952Z",
"url": "https://files.pythonhosted.org/packages/49/58/97655efdfeb5b4eeab85b1fc5d3fa1023661246c2ab2a26ea8e47402d4f2/sseclient_py-1.8.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e8ed3df5ab8bb0c12f86c28d0cadb11ed1de44a92ed35ce7ff4fd5518a809325",
"md5": "a46b4e5ef8e05c254a6b4415bfde7ca6",
"sha256": "c547c5c1a7633230a38dc599a21a2dc638f9b5c297286b48b46b935c71fac3e8"
},
"downloads": -1,
"filename": "sseclient-py-1.8.0.tar.gz",
"has_sig": false,
"md5_digest": "a46b4e5ef8e05c254a6b4415bfde7ca6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7791,
"upload_time": "2023-09-01T19:39:20",
"upload_time_iso_8601": "2023-09-01T19:39:20.450732Z",
"url": "https://files.pythonhosted.org/packages/e8/ed/3df5ab8bb0c12f86c28d0cadb11ed1de44a92ed35ce7ff4fd5518a809325/sseclient-py-1.8.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-01 19:39:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mpetazzoni",
"github_project": "sseclient",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "sseclient-py"
}