Skip to main content

PuePy — PyScript Frontend Framework

➡️ https://puepy.dev

PuePy is an attempt to create a frontend framework using PyScript. PuePy is partially inspired by Vue. It runs entirely in your browser, though server-side rendering is likely feasible. PuePy aims to support two runtime environments: PyScript Pyodide or PyScript Micropython. The Micropython option foregoes some features found in the CPython, but offers a far, far smaller runtime, making it a better option for websites. Line-of-business or scientific webapp developers may prefer the CPython version, which is heavier but more functional.

😎 To see an example of a demo built with PuePy, see ExpenseLemur.com and the Expense Lemur Github Rep.

Here's an example:

from puepy import Page, Application, t

app = Application()


@app.page()
class Hello(Page):
    def initial(self):
        return dict(name="")

    def populate(self):
        with t.div(classes=["container", "mx-auto", "p-4"]):
            t.h1("Welcome to PyScript", classes=["text-xl", "pb-4"])
            if self.state["name"]:
                t.p(f"Why hello there, {self.state['name']}")
            else:
                t.p("Why don't you tell me your name?")
            t.input(placeholder="Enter your name", bind="name")
            t.button("Continue", classes="btn btn-lg", on_click=self.on_button_click)

    def on_button_click(self, event):
        print("Button clicked")  # This logs to console


app.mount("#app")

A few things to note:

  • The .state dictionary, which is populated by initial(), is reactive. As it changes, populate is called as necessary and the page is redrawn.
  • Events are simply and Python, but use JavaScript events under the hood (including custom events)
  • You layout your page with context managers.

Components, Props, Slots

You can define reusable components with PuePy, which also use slots (similar to Vue, Web Components, etc). Here's a simple Card component:

from puepy import Component, Prop, t

# This registers the component
@t.component()
class Card(Component):
    default_role = "card"
    props = ["help_text", Prop("show_buttons", "whether to show buttons", bool, False)]

    def populate(self):
        with t.div(classes="card-header"):
            self.insert_slot("card-header")
        with t.div(classes="card-body"):
            self.insert_slot()
            if self.show_buttons:
                with t.div(classes="card-footer"):
                    t.button("Button 1")
                    t.button("Button 2")

Using the component is simple:

@app.page("/my-page")
class MyPage(Page):
    def populate(self):
        with t.card(show_buttons=True) as card:
            with card.slot("card-header"):
                t("Show header here")
            with card.slot():
                t("This is the card body")

Where to go from here...

A few things to note:

  • PuePy is not fully documented yet
  • I haven't figured out exactly what is permanent and what isn't
  • You can examine, in git, the /examples directory and view them with python3 ./serve_examples.py

Download files

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

Source Distribution

puepy-0.3.3.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

puepy-0.3.3-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file puepy-0.3.3.tar.gz.

File metadata

  • Download URL: puepy-0.3.3.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for puepy-0.3.3.tar.gz
Algorithm Hash digest
SHA256 ffd0f6b903e89f4ffd9bb68150b34bbf673f44bf3072ce02d5e40be94d4f5be6
MD5 007b9bc1519172996cd04f6ac3b15af8
BLAKE2b-256 bda99ac15dc7f09076b70b7a1d937d4d9e99b8461564b66fc16c12278b3fc2ff

See more details on using hashes here.

File details

Details for the file puepy-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: puepy-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for puepy-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f39f7cf20fa063cb50a196bcb30c8bc00a2ec8bdabbf890a36d89a32f133381e
MD5 66f1da24c3b9b1d87f96cacf23c68d34
BLAKE2b-256 8bc0cda61d314f1bab881d9e5f0c15133ec1c5da37f8f93e4d78aeeb71687da2

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.5

2 files

0.6.2

2 files

0.5.0

2 files

0.4.6

2 files

0.4.5

2 files

0.4.1

2 files

0.4.0

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

This release

0.3.3 This release

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page