🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

datastar-py

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datastar-py

Helper functions and classes for the Datastar library (https://data-star.dev/)

0.4.4
PyPI
Maintainers
1

datastar-py

The datastar-py package provides backend helpers for the Datastar 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:

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:

Keywords

datastar

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts