Skip to content

feat: add datastar_py.url helper - #58

Open
kdheepak wants to merge 5 commits into
starfederation:developfrom
kdheepak:kd/datastar_url
Open

kdheepak wants to merge 5 commits into
starfederation:developfrom
kdheepak:kd/datastar_url

Conversation

@kdheepak

@kdheepak kdheepak commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds a helper function to return a jsdelivr string pointing to a versioned or latest datastar bundle.

This is useful when constructing the script tag for an app from the server side, for example:

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "datastar-py>=1.0.3",
#     "htpy>=26.5.1",
# ]
#
# [tool.uv.sources]
# datastar-py = { path = ".", editable = true }
# ///

import datastar_py
import htpy as h

head = h.head[
   h.script(
       type="module", src=datastar_py.url("1.0.4"), # pinned version
   ),
   h.script(
       type="module", src=datastar_py.url("v1"), # stable
   ),
   h.script(
       type="module", src=datastar_py.url(), # latest
   ),
]
print(str(head))

results in

<head>
 <script 
   type="module"
   src="https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.4/bundles/datastar.js"></script>
 <script
   type="module"
   src="https://cdn.jsdelivr.net/gh/starfederation/datastar@v1/bundles/datastar.js"></script>
 <script
   type="module"
   src="https://cdn.jsdelivr.net/gh/starfederation/datastar/bundles/datastar.js"></script>
</head>

@kdheepak kdheepak changed the title feat: add datastar_url helper feat: add datastar_py.url helper Sep 27, 2026
Comment thread README.md
Comment thread src/datastar_py/__init__.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant