StarLive
Universal Hypermedia System for Starlette & FastAPI
Build dynamic, real-time web applications with automatic HTMX/Turbo detection and WebSocket streaming
StarLive automatically detects HTMX/Turbo clients and provides unified streaming responses with real-time WebSocket updates.
Features
- Universal API: One codebase for both HTMX and Turbo
- Auto-detection: Framework detection via request headers
- Real-time: WebSocket streaming to all clients
- Zero config: Works out of the box
Installation
pip install starlive
Quick Start
from starlette.applications import Starlette
from starlette.responses import HTMLResponse
from starlette.routing import Route
from starlive import StarLive, StarLiveMiddleware
starlive = StarLive()
async def homepage(request):
return HTMLResponse(f"""
<html>
<head>{starlive.get_scripts()}</head>
<body>
<div id="content">
<button hx-post="/update" hx-target="#content">Update</button>
</div>
</body>
</html>
""")
async def update_content(request):
if request.state.can_stream():
content = '<div>Updated!</div>'
if request.state.hypermedia_type == "htmx":
return HTMLResponse(content)
else: # Turbo
stream = starlive.update(content, "#content",
hypermedia_type=request.state.hypermedia_type)
return starlive.stream(stream, request.state.hypermedia_type)
return HTMLResponse("Updated!")
app = Starlette(routes=[
Route("/", homepage),
Route("/update", update_content, methods=["POST"]),
])
app.add_middleware(StarLiveMiddleware, starlive=starlive)
app.router.routes.append(starlive.create_websocket_route())
FastAPI
from fastapi import FastAPI, Request
from starlive import StarLive, StarLiveMiddleware
starlive = StarLive()
app = FastAPI()
app.add_middleware(StarLiveMiddleware, starlive=starlive)
@app.websocket(starlive.ws_route)
async def websocket_endpoint(websocket):
await starlive._websocket_endpoint(websocket)
# Use same handlers as Starlette example
Stream Operations
# All work with both HTMX and Turbo
starlive.append(content, "#target")
starlive.prepend(content, "#target")
starlive.replace(content, "#target")
starlive.update(content, "#target")
starlive.remove("#target")
starlive.before(content, "#target")
starlive.after(content, "#target")
Real-time Updates
# Broadcast to all clients
await starlive.push(
starlive.append('<div>New message</div>', "#messages"),
to=None
)
# Custom user identification
@starlive.user_id
def get_user_id():
return request.session.get("user_id", "anonymous")
Request Detection
if request.state.hypermedia_type == "htmx":
return HTMLResponse("<div>HTMX response</div>")
elif request.state.hypermedia_type == "turbo":
return starlive.stream(starlive.update(content, "#target"), "turbo")
else:
return JSONResponse({"data": "value"})
Templates
from starlette.templating import Jinja2Templates
from starlive import starlive_context_processor
templates = Jinja2Templates(directory="templates")
templates.env.globals.update(starlive_context_processor(starlive)())
<head>
{{ starlive.get_scripts() }}
</head>
Examples
# Interactive demo
uv run starlive-dev
# Specific frameworks
uv run starlive-dev --framework starlette # http://localhost:8001
uv run starlive-dev --framework fastapi # http://localhost:8002
Development
git clone https://github.com/yourusername/starlive.git
cd starlive
uv sync --dev
Testing
uv run starlive-test # All tests
uv run starlive-test --framework fastapi # FastAPI only
uv run starlive-test --type e2e # End-to-end only
uv run starlive-test --coverage # With coverage
Code Quality
uv run ruff check src/ tests/ examples/
uv run ruff format src/ tests/ examples/
License
Apache 2.0 License. See LICENSE for details.
Metadata
Release files for starlive 0.2.0
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 | |
|---|---|---|---|---|
| starlive-0.2.0.tar.gz | 32.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| starlive-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 47.5 kB
Release files / starlive-0.2.0.tar.gz
| Download URL | starlive-0.2.0.tar.gz |
|---|---|
| Size | 32.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa7f973ec3b06af0a621b50d29f219454fe8d2ca61384f6cce04684e8c336496
|
|
BLAKE2b-256 checksum How to use checksums |
6d994d186ca29022190c3e0a11bfa86df4b4728ee1186d0ebd8ba949e39502f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 1, 2025.
Transparency logRelease files / starlive-0.2.0-py3-none-any.whl
| Download URL | starlive-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9b6995f2c8da3e0189b9d03ac33750b0ffb617d014bfebb6656167f08352fe70
|
|
BLAKE2b-256 checksum How to use checksums |
7b2945aba3644b2e810726bf043c473cbcc3d13ef2dc151b85dced5a83da705e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 1, 2025.
Transparency logSecurity for starlive 0.2.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for starlive-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 1, 2025.
Transparency logA 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.