Streamstraight Python SDK
streamstraight-server mirrors the @streamstraight/server Node SDK for producers who prefer Python. It connects to Streamstraight over Socket.IO, manages chunk acknowledgements, and exposes helpers for minting client JWTs.
Quickstart
uv add streamstraight-server
Usage
Streamstraight needs a unique stream_id for every stream you produce. Once connected, you can either push chunks manually with the writer API or hand us an async iterator/object that yields JSON‑serializable chunks. The writer reuses the most recent stream configuration, so call await server.connect({...}) again if you need to swap streams or override the encoder.
Push chunks with the writer context manager
import asyncio
from collections.abc import AsyncIterator
from streamstraight_server import streamstraight_server
async def generate() -> AsyncIterator[str]:
yield "first"
yield "second"
async def main() -> None:
server = await streamstraight_server(
{"api_key": "YOUR_STREAMSTRAIGHT_API_KEY"},
{"stream_id": "your-stream-id"},
) # connects and configures the stream
async with server.stream_writer() as writer:
async for chunk in generate():
await writer.send(chunk) # returns an asyncio.Future you can await later if needed
# You can optionally mirror the same chunks to your HTTP response here.
asyncio.run(main())
Pipe an async iterator directly
import asyncio
from streamstraight_server import streamstraight_server
async def generate():
# Replace with your LLM or other async generator
yield {"content": "first chunk"}
yield {"content": "second chunk"}
async def main() -> None:
server = await streamstraight_server(
{"api_key": "YOUR_STREAMSTRAIGHT_API_KEY"},
{"stream_id": "your-stream-id"},
)
await server.stream(generate())
asyncio.run(main())
Mint a client JWT for your browser client
from streamstraight_server import fetch_client_token
token = await fetch_client_token({"api_key": "YOUR_STREAMSTRAIGHT_API_KEY"})
Logging
The SDK defaults to logging only errors. To see more detailed logs (useful for debugging connection issues), you can adjust the log level:
import logging
# Set to INFO to see connection attempts and stream lifecycle
logging.getLogger("streamstraight_server").setLevel(logging.INFO)
# Set to DEBUG to see all internal operations
logging.getLogger("streamstraight_server").setLevel(logging.DEBUG)
# Disable SDK logging entirely
logging.getLogger("streamstraight_server").setLevel(logging.CRITICAL)
Release files for streamstraight-server 0.2.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| streamstraight_server-0.2.10.tar.gz | 16.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamstraight_server-0.2.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.0 kB
Release files / streamstraight_server-0.2.10.tar.gz
| Download URL | streamstraight_server-0.2.10.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bc4880b29e2793c912ec8dd4ec9b120e9f6be2ceda8d12fd16dae637fb8ef6b
|
|
BLAKE2b-256 checksum How to use checksums |
77fde7a608972a4de5a0be1b813ce4462c38f180234c4d0e154ee5b21853c453
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.3
|
Release files / streamstraight_server-0.2.10-py3-none-any.whl
| Download URL | streamstraight_server-0.2.10-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f7bd423702e7c5d4a3eed587e52757b095ce13fac4567d7e1abcb00ea19cef8
|
|
BLAKE2b-256 checksum How to use checksums |
bf9fbbd503d5f44d68e29a3cda78d9a9e6e0d9d0c49485c8d6923a076b2e0df2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.3
|