py-sse
minimal python sse server for datastar — built on rsgi/granian + apsw/sqlite
sse.py → datastar event formatters (patch_elements, patch_signals, …)
app.py → rsgi app: routing, signals, cookies, static, @app.stream
db.py → sqlite helpers + Changes (update_hook → asyncio)
mserver.py → background server for notebooks (serve_background/stop_background)
ngrok.py → public tunnel + .env loader
pip install py-sse
uv add py-sse # preferred
hello
from py_sse import create_app, serve
app = create_app()
@app.get('/')
async def index(req): return '<h1>hello</h1>'
if __name__ == '__main__': serve(app)
live feed
Backend is the source of truth. Each write wakes every /feed stream; the
handler re-renders. No polling, no optimistic updates, no client state.
from py_sse import *
db = create_db('chat.db')
migrate(db, "CREATE TABLE IF NOT EXISTS msgs (id INTEGER PRIMARY KEY, txt TEXT)")
def startup(loop):
global changes
changes = Changes(db, loop)
app = create_app(on_init=startup, on_del=lambda loop: changes.close())
@app.post('/say')
async def say(req):
s = await signals(req)
write(db, lambda c: c.execute("INSERT INTO msgs(txt) VALUES(?)", (s['text'],)))
@app.stream('/feed', on=lambda: changes)
def feed(req):
rows = query(db, "SELECT txt FROM msgs ORDER BY id DESC LIMIT 50")
return ''.join(f'<p>{t}</p>' for (t,) in rows)
handler returns
str → 200 html
dict → 200 json
None → 204
(url, int) → redirect (3xx) or text body (4xx/5xx)
async gen → sse stream (use @app.stream for the common case)
api
create_app(on_init=, on_del=) → app handle: .get .post .put .patch .delete .mount .before .stream
@app.stream(path, on=) → sse route; re-renders each time `on` ticks
signals(req) → datastar signals (query on GET, json body otherwise)
body(req) / body_stream(req) → full body / chunked body
set_cookie(req, name, value) → queue a Set-Cookie
create_signer(secret) → .sign(value) / .unsign(signed) — hmac-sha256
static(app, prefix, dir) → zero-copy file serving, http range support
create_db(path) → wal sqlite connection
migrate(conn, sql) → apply schema in one txn
query(conn, sql, …, limit=) → rows as tuples
write(conn, fn, …) → run fn(conn, …) in a txn, return its result
Changes(db, loop) → fan db writes out to streams; .wait() / .close()
patch_elements(html, …) → datastar-patch-elements event
patch_signals(signals, …) → datastar-patch-signals event
remove_signals(*names) → null those signals
execute_script(js, …) → datastar-execute-script event
redirect(url) → navigate via patched script
serve(app) → foreground granian server (blocks)
serve_background(app) → background thread → ServerState
stop_background(state) → clean shutdown, 3s join
dev_alive(port) → is the port accepting connections
start_tunnel(port) → ngrok tunnel → TunnelState (needs NGROK_AUTHTOKEN)
stop_tunnel(tunnel) → close it
load_env(path='.env') → read KEY=VALUE; missing file is a noop
datastar
patch elements & signals → the verb; morph is the mechanism
fat morph → send large dom chunks, up to <html>
signals → user interaction only, used sparingly
cqrs → long-lived read stream + short-lived writes
brotli on sse → ratios up to 200:1
MIT · built from marimo notebooks with marimo-dev
Metadata
Release files for py-sse 0.12.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_sse-0.12.2.tar.gz | 13.0 kB | Without provenance | Details for py_sse-0.12.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_sse-0.12.2-py3-none-any.whl | Python 3 | none | any | Details for py_sse-0.12.2-py3-none-any.whl |
Total release size: 28.5 kB
Release files / py_sse-0.12.2.tar.gz
| Download URL | py_sse-0.12.2.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e76418326ae242c50800c55cfa1f7b854e30911165f125d0bae3c7dcf62de78a
|
|
BLAKE2b-256 checksum How to use checksums |
768401fc121d3296810486ba13710bbf273d95264f53ed113638f8932a71b504
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / py_sse-0.12.2-py3-none-any.whl
| Download URL | py_sse-0.12.2-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd4495f865b692ea96c09fa4e213370534b850e8f1aa1b22b93663ce5cbb141a
|
|
BLAKE2b-256 checksum How to use checksums |
4717eae8e79f2a1a94dfc2696f7f93b5ca873e8f286fcbf1e85f754ae0c679e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for py-sse 0.12.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.