mwx23 / lona

Write responsive web apps in full python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lona logo

license MIT python 3 latest version ci status code coverage

Lona is a web application framework, designed to write responsive web apps in full Python.

Demos: lona-web.org/demos

FAQ: lona-web.org/faq

Documentation: lona-web.org

Changelog: lona-web.org/changelog

Reddit: reddit.com/r/lona_web_org/

Web is a solved problem in Python since ages, but traditionally Python handles only the server side. If you want to have client side interaction like click events or you want update content live, you have to write an additional Javascript application.

Lona handles the server side and the client side, and provides a simple, pythonic API to write self contained views.

# pip install lona
from lona.html import HTML, Button, Div, H1
from lona import LonaApp, LonaView

app = LonaApp(__file__)

@app.route('/')
class MyView(LonaView):
    def handle_request(self, request):
        message = Div('Button not clicked')
        button = Button('Click me!')

        html = HTML(
            H1('Click the button!'),
            message,
            button,
        )

        self.show(html)

        # this call blocks until the button was clicked
        input_event = self.await_click(button)

        if input_event.node == button:
            message.set_text('Button clicked')

        return html


app.run(port=8080)

More information: Getting Started

How does it work?

Lona comes with a Javascript based browser library that speaks a specialized protocol with the backend. This protocol specifies messages like "hey frontend, please show $HTML" and "hey backend, someone clicked on node XY".

More information: Basic Concept

About

Write responsive web apps in full python

License:MIT License


Languages

Language:Python 83.1%Language:JavaScript 14.4%Language:HTML 1.6%Language:Makefile 0.8%Language:CSS 0.1%