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.1.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.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_sse_client-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 8c4eb01ae6469fe5164352af9d574cb6b804660fef7103c675d52789a5571239
MD5 bc7cafde18af2aac153e126fe5f33af3
BLAKE2b-256 538d345ee7ff9816b797d265f3f1b7c2c4a12c5f69e05ea4cde933d7134aaf7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_sse_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97eb89ea221f76be6a2dd173465fc86ba5b1a8e6718a06cabe065d9c65ab9af3
MD5 30f43eff966ba06b440c96c5f7640bc4
BLAKE2b-256 fe497c63ccac3be67469ba3e8a3bfbcdb9fad568c4ea29ae750cab165cbeb508

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