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.8.tar.gz (111.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

starbear-0.2.8-py3-none-any.whl (48.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: starbear-0.2.8.tar.gz
  • Upload date:
  • Size: 111.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for starbear-0.2.8.tar.gz
Algorithm Hash digest
SHA256 0c96dbfbd418fff7816f78b3c394d0040cfda48dc6fb14320379d584df59657f
MD5 466b7e201def5fafb36cd0a26b5a5fba
BLAKE2b-256 549edd4ae9599f6d2b8b8e3d4f9cc9b7b14b6cb04bba25d3d488169f890e08a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for starbear-0.2.8.tar.gz:

Publisher: publish.yml on breuleux/starbear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: starbear-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 48.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for starbear-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 24977f531cae48209859d73659b79f3c80f534b2b4c421f51698cfa0bd996ba4
MD5 17999cddf7e05d1f1b48dbc510f993bb
BLAKE2b-256 5978ba41a05e8bf8aaec1d728807c1270d5fed9651b1c50e7d8364dce972369c

See more details on using hashes here.

Provenance

The following attestation bundles were made for starbear-0.2.8-py3-none-any.whl:

Publisher: publish.yml on breuleux/starbear

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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