Skip to main content

Framework for easy small local web apps or programs

Project description

Starbear

Documentation

Tutorial

Starbear allow creating interactive local web applications in Python very easily.

  • The entire app is a single async function.
  • Call Python functions from JS, call JS functions from Python.
  • No subroutes: starbear automatically creates the endpoints you need.

Be careful about using this in production: Starbear is a beta, experimental framework. It is not highly efficient and may not scale very well, therefore you should use this for small apps that you want to run locally or that don't need high uptime and reliability.

Install

pip install starbear

Example

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))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starbear-0.2.4.tar.gz (10.3 MB view details)

Uploaded Source

Built Distribution

starbear-0.2.4-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

Details for the file starbear-0.2.4.tar.gz.

File metadata

  • Download URL: starbear-0.2.4.tar.gz
  • Upload date:
  • Size: 10.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.3

File hashes

Hashes for starbear-0.2.4.tar.gz
Algorithm Hash digest
SHA256 7e8e19caf0de0306101867b22791af17a7207660c26ed77b62e9066aa0b52c06
MD5 cec9b61a170fd65245e517424b4971e8
BLAKE2b-256 63aad69743262f19759c9d464f8c32660fe2d1f068d33ec5f97f15cde2772e13

See more details on using hashes here.

File details

Details for the file starbear-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for starbear-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 13da9611e991f5707d545ed56086344dcade76d71cec96be0326427567e18c7e
MD5 c73a378975fe61b4ba95df8c31e5bab2
BLAKE2b-256 27aebab74827c011533e74ef162a5ec45d0cbbdbe2721009f000d3465d370578

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page