Skip to main content

SSE client for Python

Project description

Server Side Events (SSE) client for Python

A Python client for SSE event sources that seamlessly integrates with urllib3 and requests.

Installation

$ pip install sseclient-py

Usage

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sseclient-py-1.8.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

sseclient_py-1.8.0-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sseclient-py-1.8.0.tar.gz.

File metadata

  • Download URL: sseclient-py-1.8.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for sseclient-py-1.8.0.tar.gz
Algorithm Hash digest
SHA256 c547c5c1a7633230a38dc599a21a2dc638f9b5c297286b48b46b935c71fac3e8
MD5 a46b4e5ef8e05c254a6b4415bfde7ca6
BLAKE2b-256 e8ed3df5ab8bb0c12f86c28d0cadb11ed1de44a92ed35ce7ff4fd5518a809325

See more details on using hashes here.

File details

Details for the file sseclient_py-1.8.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sseclient_py-1.8.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4ecca6dc0b9f963f8384e9d7fd529bf93dd7d708144c4fb5da0e0a1a926fee83
MD5 dc4ebc32d5a27c0002059381bee4a31f
BLAKE2b-256 495897655efdfeb5b4eeab85b1fc5d3fa1023661246c2ab2a26ea8e47402d4f2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page