# 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
```bash
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
```python
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)
# You can optionally mirror the same chunks to your HTTP response here.
asyncio.run(main())
```
### Pipe an async iterator directly
```python
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
```python
from streamstraight_server import fetch_client_token
token = await fetch_client_token({"api_key": "YOUR_STREAMSTRAIGHT_API_KEY"})
```
Raw data
{
"_id": null,
"home_page": null,
"name": "streamstraight-server",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "streaming, socket.io, websockets, sdk, llm, streamstraight",
"author": null,
"author_email": "Streamstraight <support@streamstraight.com>",
"download_url": "https://files.pythonhosted.org/packages/3c/6b/630fc98a1fcd5ae34a62c33087acb72153dc48e79fe215ac958b1354cd33/streamstraight_server-0.2.0.tar.gz",
"platform": null,
"description": "# Streamstraight Python SDK\n\n`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.\n\n## Quickstart\n\n```bash\nuv add streamstraight-server\n```\n\n## Usage\n\nStreamstraight 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\u2011serializable 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.\n\n### Push chunks with the writer context manager\n\n```python\nimport asyncio\nfrom collections.abc import AsyncIterator\n\nfrom streamstraight_server import streamstraight_server\n\n\nasync def generate() -> AsyncIterator[str]:\n yield \"first\"\n yield \"second\"\n\n\nasync def main() -> None:\n server = await streamstraight_server(\n {\"api_key\": \"YOUR_STREAMSTRAIGHT_API_KEY\"},\n {\"stream_id\": \"your-stream-id\"},\n ) # connects and configures the stream\n\n async with server.stream_writer() as writer:\n async for chunk in generate():\n await writer.send(chunk)\n # You can optionally mirror the same chunks to your HTTP response here.\n\nasyncio.run(main())\n```\n\n### Pipe an async iterator directly\n\n```python\nimport asyncio\nfrom streamstraight_server import streamstraight_server\n\n\nasync def generate():\n # Replace with your LLM or other async generator\n yield {\"content\": \"first chunk\"}\n yield {\"content\": \"second chunk\"}\n\n\nasync def main() -> None:\n server = await streamstraight_server(\n {\"api_key\": \"YOUR_STREAMSTRAIGHT_API_KEY\"},\n {\"stream_id\": \"your-stream-id\"},\n )\n\n await server.stream(generate())\n\nasyncio.run(main())\n```\n\n### Mint a client JWT for your browser client\n\n```python\nfrom streamstraight_server import fetch_client_token\n\ntoken = await fetch_client_token({\"api_key\": \"YOUR_STREAMSTRAIGHT_API_KEY\"})\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python server SDK for streaming data into Streamstraight.",
"version": "0.2.0",
"project_urls": {
"Documentation": "https://docs.streamstraight.com",
"Homepage": "https://www.streamstraight.com",
"Issues": "https://github.com/streamstraight/streamstraight/issues",
"Repository": "https://github.com/streamstraight/streamstraight"
},
"split_keywords": [
"streaming",
" socket.io",
" websockets",
" sdk",
" llm",
" streamstraight"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "e952d054ae075198a0c554c641986ede3be26e9cb2cd59ce9a17b03cb6e126c7",
"md5": "d88f778a7031a0290c815452bbfd1918",
"sha256": "bd684cb93663201c961d2b149e8aa6fa608be7b456d9dd8f15bdac80207db865"
},
"downloads": -1,
"filename": "streamstraight_server-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d88f778a7031a0290c815452bbfd1918",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 10698,
"upload_time": "2025-10-20T22:02:09",
"upload_time_iso_8601": "2025-10-20T22:02:09.685490Z",
"url": "https://files.pythonhosted.org/packages/e9/52/d054ae075198a0c554c641986ede3be26e9cb2cd59ce9a17b03cb6e126c7/streamstraight_server-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "3c6b630fc98a1fcd5ae34a62c33087acb72153dc48e79fe215ac958b1354cd33",
"md5": "f28a20d279b6636d391b3cfebc47f964",
"sha256": "1525e18880a02a74c897ff276115350f50545787abf9e7496ccd6982f412c6f8"
},
"downloads": -1,
"filename": "streamstraight_server-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "f28a20d279b6636d391b3cfebc47f964",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 12019,
"upload_time": "2025-10-20T22:02:10",
"upload_time_iso_8601": "2025-10-20T22:02:10.587848Z",
"url": "https://files.pythonhosted.org/packages/3c/6b/630fc98a1fcd5ae34a62c33087acb72153dc48e79fe215ac958b1354cd33/streamstraight_server-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-20 22:02:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "streamstraight",
"github_project": "streamstraight",
"github_not_found": true,
"lcname": "streamstraight-server"
}