Skip to main content

minimal python sse server

Project description

PyPI version

[!WARNING] Under active development — May 2026

py_sse

A minimal SSE web framework for Python 3.13+. Real-time hypermedia over HTTP/1.1 with brotli-compressed Server-Sent Events.

One OS thread per connection. Topic-scoped pub/sub via hierarchical subjects. No async/await. Pure stdlib + brotli + apsw.

Install

uv add py-sse

Hello world

from py_sse import serve, html

def get_root(req):
    return html("<h1>hello, world</h1>")

serve([("GET", "/", get_root)], host="0.0.0.0", port=8000)

Real-time updates

from py_sse import serve, html, Changes, Database, stream_handler

db = Database("app.db", schema="CREATE TABLE IF NOT EXISTS msg (id INTEGER PRIMARY KEY, text TEXT)")

def post_msg(req):
    db.execute("INSERT INTO msg (text) VALUES (?)", (req["body"].decode(),))
    db.changes.notify("msg")
    return ("", [], b"")

@stream_handler(
    resource_id_fn=lambda req: "msgs",
    subscribe_to=lambda req: "msg",
)
def get_msgs(req):
    rows = db.all("SELECT id, text FROM msg ORDER BY id DESC")
    body = "<ul>" + "".join(f"<li>{t}</li>" for _, t in rows) + "</ul>"
    return html(f"<html><body>{body}</body></html>")

serve(
    [("GET", "/", get_msgs), ("POST", "/msg", post_msg)],
    changes=db.changes,
)

Design

  • Pages are database snapshots. Every render is the truth as of query time.
  • Fat morphs. SSE frames send the whole page; idiomorph patches the DOM; brotli compresses across frames.
  • Topic-scoped pub/sub. changes.notify("game.5.score") wakes only viewers waiting on matching patterns.
  • Graceful degradation. Past the live cap, viewers get one-shot HTML with data-on-interval for polling.
  • One thread per connection. The thread IS the subscription. When it dies, the subscription dies. No registry.

License

MIT

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

py_sse-0.11.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

py_sse-0.11.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file py_sse-0.11.0.tar.gz.

File metadata

  • Download URL: py_sse-0.11.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux ARM","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 py_sse-0.11.0.tar.gz
Algorithm Hash digest
SHA256 c0aee3ac1e15e1393017224d89d92385620e5fc93e10b7556cd29738aedd6dc6
MD5 0ce9657414fa71fa59c5c5666e2427b4
BLAKE2b-256 34253698cc4d3657e55b6d3e89ab98c0d5b7c5b5f484d4f2f3b3f0c272eb782b

See more details on using hashes here.

File details

Details for the file py_sse-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: py_sse-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux ARM","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 py_sse-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e1bfbbcd207cefb04595b6c4deb03fb571342e236e96273eb9a1fef1f1dff88
MD5 5b879c862abe19cf057b5e2c6448d428
BLAKE2b-256 100367a5f243f41bfb62b1b8ae5faa8a1d040a88645736b2b8419672c3b1d8f7

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