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 sseclient

def with_urllib3(url):
    """Get a streaming response for the given event feed using urllib3."""
    import urllib3
    http = urllib3.PoolManager()
    res = http.request('GET', url, preload_content=False)
    yield from sseclient.SSEClient(res).events()

def with_requests(url):
    """Get a streaming response for the given event feed using requests."""
    import requests
    res = requests.get(url, stream=True)
    yield from sseclient.SSEClient(res).events()

def with_httpx(url):
    """Get a streaming response for the given event feed using httpx."""
    import httpx
    with httpx.stream('GET', url) as s:
        # Note: 'yield from' is Python >= 3.3. Use for/yield instead if you
        # are using an earlier version.
        yield from sseclient.SSEClient(s.iter_bytes()).events()


url = 'http://domain.com/events'
for event in with_urllib3(url):
    ...
for event in with_requests(url):
    ...
for event in with_httpx(url):
    ...

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sseclient_py-1.9.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file sseclient_py-1.9.0-py3-none-any.whl.

File metadata

  • Download URL: sseclient_py-1.9.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sseclient_py-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 340062b1587fc2880892811e2ab5b176d98ef3eee98b3672ff3a3ba1e8ed0f6f
MD5 a35309f98246065ae2a1712bbf285d2f
BLAKE2b-256 4d2e59920f7d66b7f9932a3d83dd0ec53fab001be1e058bf582606fe414a5198

See more details on using hashes here.

Supported by

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