Metadata-Version: 2.4
Name: datastar-py
Version: 0.4.4
Summary: Helper functions and classes for the Datastar library (https://data-star.dev/)
Project-URL: Documentation, https://github.com/starfederation/datastar/blob/develop/sdk/python/README.md
Project-URL: GitHub, https://github.com/starfederation/datastar
Author-email: Felix Ingram <f.ingram@gmail.com>, Lucian Knock <git@lucianknock.com>
License: MIT
Keywords: datastar,django,fastapi,fasthtml,flask,html,litestar,quart,sanic,starlette
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# datastar-py

The `datastar-py` package provides backend helpers for the [Datastar](https://data-star.dev) JS library.

Datastar requires all backend responses to use SSE. This allows the backend to
send any number of responses, from zero to inifinity.

`datastar-py` helps with the formatting of these responses, while also
providing helper functions for the different supported responses.

To use `datastar-py`, import the SSE generator in your app and then use
it in your route handler:

```python
from datastar_py import ServerSentEventGenerator as SSE

# ... various app setup. The example below is for the Quart framework

@app.route("/updates")
async def updates():
    async def time_updates():
        while True:
            yield SSE.merge_fragments(
                [f"""<span id="currentTime">{datetime.now().isoformat()}"""]
            )
            await asyncio.sleep(1)
            yield SSE.merge_signals({"currentTime": f"{datetime.now().isoformat()}"})
            await asyncio.sleep(1)

    response = await make_response(time_updates(), SSE_HEADERS)
    response.timeout = None
    return response
```

There are also a number of custom responses/helpers for various frameworks. Currently the following frameworks are supported:

* [Django](https://www.djangoproject.com/)
* [FastAPI](https://fastapi.tiangolo.com/)
* [FastHTML](https://fastht.ml/)
* [Litestar](https://litestar.dev/)
* [Quart](https://quart.palletsprojects.com/en/stable/)
* [Sanic](https://sanic.dev/en/)
* [Starlette](https://www.starlette.io/)
