Skip to main content

A lightweight SSE client that uses the httpx package based on httpx-sse.

Project description

Simple SSE Client

[!WARNING] This python package is currently in beta and will likely change. It is not yet ready for production use.

A lightweight SSE client that uses the httpx package based on httpx-sse.

Installation

pip install simple-sse-client

Usage

Synchronous

from simple_sse_client import stream

for event in stream("https://example.com/sse"):
    print(event)

Asynchronous

from simple_sse_client import async_stream

async for event in async_stream("https://example.com/sse"):
    print(event)

Interface

The stream and async_stream functions follow the httpx.request() interface.

stream(method, url, *, params=None, content=None, data=None, files=None, json=None, headers=None, cookies=None, auth=None, proxy=None, timeout=Timeout(timeout=5.0), follow_redirects=False, verify=True, trust_env=True)
async_stream(method, url, *, params=None, content=None, data=None, files=None, json=None, headers=None, cookies=None, auth=None, proxy=None, timeout=Timeout(timeout=5.0), follow_redirects=False, verify=True, trust_env=True)

Both functions connect to an SSE endpoint and yield ServerSentEvent objects.

Parameters:

  • method - HTTP method (GET, OPTIONS, HEAD, POST, PUT, PATCH, or DELETE).
  • url - URL.
  • params - (Optional) Query parameters to include in the URL, as a string, dictionary, or sequence of two-tuples.
  • content - (Optional) Binary content to include in the body of the request, as bytes or a byte iterator.
  • data - (Optional) Form data to include in the body of the request, as a dictionary.
  • files - (Optional) A dictionary of upload files to include in the body of the request.
  • json - (Optional) A JSON serializable object to include in the body of the request.
  • headers - (Optional) Dictionary of HTTP headers to include in the request.
  • cookies - (Optional) Dictionary of Cookie items to include in the request.
  • auth - (Optional) An authentication class to use when sending the request.
  • proxy - (Optional) A proxy URL where all the traffic should be routed.
  • timeout - (Optional) The timeout configuration to use when sending the request.
  • follow_redirects - (Optional) Enables or disables HTTP redirects.
  • verify - (Optional) Either True to use an SSL context with the default CA bundle, False to disable verification, or an instance of ssl.SSLContext to use a custom context.
  • trust_env - (Optional) Enables or disables usage of environment variables for configuration.

stream returns an Iterator[ServerSentEvent] and async_stream returns an AsyncIterator[ServerSentEvent].

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

simple_sse_client-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

simple_sse_client-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_sse_client-0.1.0.tar.gz.

File metadata

  • Download URL: simple_sse_client-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for simple_sse_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aff94f84e09b0436ac9f9ca7bfc91531600d2d12c71afcc2872026bb8e24571a
MD5 48aa69a9f3c41741e27aace5277d95f4
BLAKE2b-256 d0915c096bbda35284a8e364e7ca82318b200688c35624aae270125081292a08

See more details on using hashes here.

File details

Details for the file simple_sse_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_sse_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 235fecaa09d008b316b1d31a2ce903480d081bbf40d780f39144ff10e15a0d3d
MD5 8aa562152353f0eb6ea3c375edeff5c2
BLAKE2b-256 bcc89417e0f9e3fb4c7715eb4063ba64b3706d88856ce0c3a8dc5ca3caecb6bb

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