易于创建小型本地Web应用程序或程序的框架
项目描述
Starbear
Starbear允许您非常容易地用Python创建交互式本地Web应用程序。
- 整个应用程序是一个单独的异步函数。
- 从JS调用Python函数,从Python调用JS函数。
- 无子路由:Starbear自动创建您需要的端点。
注意在生产中使用此框架: Starbear是一个beta,实验性框架。它效率不高,可能扩展性不佳,因此您应该将其用于您希望在本地上运行的小型应用程序或不需要高可用性和可靠性的应用程序。
安装
pip install starbear
示例
from hrepr import H
from pathlib import Path
from starbear import bear, Queue
@bear
async def app(page):
# Events coming from the webpage will be added to this Queue
q = Queue()
# You can print to any part of the page using a CSS selector, for
# example we can add stuff to the <head> element:
page["head"].print(
# Use H.xyz to create a <xyz> node
H.title("Clicking game!"),
# If you give a Path object, Starbear will serve the corresponding
# file for you.
H.link(rel="stylesheet", href=Path("path/to/style.css"))
)
# page.print prints to <body> by default
page.print(
# If you give a Queue as an onclick handler, the events will be
# accumulated in that queue. You can also give a Python function
# as a handler.
H.button("Click me!", onclick=q),
H.div(
# This is the span we want to update, so we put it in a variable
target := H.span("0", id=True),
" clicks"
)
)
i = 0
# And now we can simply loop over the event queue. Be careful to use *async* for,
# which will yield to the event loop between each iteration.
async for event in q:
i += 1
# We can index the page using any node we created and set its contents
# to whatever we desire.
page[target].set(str(i))
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
starbear-0.2.3.tar.gz (1.9 MB 查看哈希值)
构建分发版
starbear-0.2.3-py3-none-any.whl (47.6 kB 查看哈希值)
关闭
starbear-0.2.3.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c815993d280cc88498a02e126845f1902622f8d3087c8d45f580a3d19e015dad |
|
MD5 | ec5db3350238ffc35044f31a2691ed96 |
|
BLAKE2b-256 | 67e5952336e291cbb9eed778c881959a83270f05bebda2d338a834a32807ee5c |
关闭
starbear-0.2.3-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a56efbcc5a0a449a09240a14fca18d0aa1c97ba195c9a0f20ca484543ccd9773 |
|
MD5 | 2d3fe5f2806cbaf73062565b33c29e81 |
|
BLAKE2b-256 | d4b6dc46afcded812419ba47af6fd62551c1590618daedf346478172b180f62b |