Skip to main content

A Minimalist Flet Framework

Project description

LEFT, a Minimalist Flet Framework

A very simple framework using the flet library - the bare boilerplate code I use to get some apps up and running.

I have deliberately kept things extremely simple - it doesn't attempt to hide the flet internals, very little enforced convention/configuration, and only a tiny reliance on some 'magic' in the React-influenced state management in the view layer (even this is not mandatory).

Its up to the end user to organise their implementation in a consistent and logical manner that works for them.

dev usage (requires python >= 3.10)

pip install python-left

Simplest possible app usage. See sampleapp/ for a more fully-fledged CRUD-app example.

import flet as ft
from left import LeftApp, LeftController, LeftView
from left.sharedcomponents import loading_spinner
from left.helpers import redirect


class MyView(LeftView):
    def __init__(self):
        self.state = {"message": None}

    def update_state(self, **new_state):
        self.state.update(new_state)

    @property
    def appbar(self):
        return ft.AppBar(
            actions=[
                ft.ElevatedButton("Home", on_click=lambda _: redirect("/")),
                ft.ElevatedButton("Page2", on_click=lambda _: redirect("/page/view/page2"))
            ]
        )

    @property
    def controls(self):
        if self.state["message"] is None:
            return [loading_spinner()]
        return [
            ft.Text(self.state["message"])
        ]


class MyController(LeftController):
    def index(self):
        view = MyView()
        self._mount_view(view)
        view.update_state(message="welcome to the app!")

    def load_page(self, uid):
        view = MyView()
        self._mount_view(view)
        view.update_state(message=f"Display contents for {uid} here...")


def on_route_change(page, parts):
    match parts:
        case ['']:
            MyController(page).index()
        case ['page', 'view', uid]:
            MyController(page).load_page(uid)
        case _:
            print(f"Unrecognised route: {page.route}")


LeftApp(
    router_func=on_route_change,
    default_title="A Very Simple App")

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

python-left-0.0.3.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

python_left-0.0.3-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file python-left-0.0.3.tar.gz.

File metadata

  • Download URL: python-left-0.0.3.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for python-left-0.0.3.tar.gz
Algorithm Hash digest
SHA256 61cee6d822ca11ed2a3fa91f88813001fd9a52270187e79b437801886c83b30e
MD5 e7850b67462a4c785670db789cc5abdd
BLAKE2b-256 a88d4064c2a150758f91919bcf8218c98c3ab94d63fdb7e84715e02d48161b26

See more details on using hashes here.

File details

Details for the file python_left-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: python_left-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for python_left-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6141019a69b3572d4aca559eec7fb73ab5258d3ee53381cb9b33b591bde6d573
MD5 12d06824c9940133c4be7dbd80532f23
BLAKE2b-256 3f552d1c5d8ec02c3ed56b9efd6d4d1347cda46fc1aa8977a7313d974790dbe6

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