跳转到主要内容

易于创建小型本地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 查看哈希值)

上传时间 Python 3

由以下机构支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误记录StatusPageStatusPage状态页面