Metadata-Version: 2.3
Name: datastar-py
Version: 0.3.0
Summary: Helper functions and classes for the Datastar library (https://data-star.dev/)
Author-email: Felix Ingram <f.ingram@gmail.com>
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 initialise
it in your route handler:

```python
from datastar_py import ServerSentEventGenerator

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

@app.route("/updates")
async def updates():
    async def time_updates():
        sse = ServerSentEventGenerator()
        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
```

The following helpers are prov

### `ServerSentEventGenerator.send`
### `ServerSentEventGenerator.MergeFragments`
### `ServerSentEventGenerator.RemoveFragments`
### `ServerSentEventGenerator.MergeSignals`
### `ServerSentEventGenerator.RemoveSignals`
### `ServerSentEventGenerator.ExecuteScript`
