PIP-Talk - Week 38

Every week going forward I plan to write a little about interesting modules/libraries available for Python.

The topic for this week is: Flet

Flet is the fastest way to build Flutter apps in Python.

Flutter is an open source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase. Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required. It comes with a included webserver and all “batteries included” to build apps for any (or almost any) platform.


Key features - Flet

1. From idea to app in minutes

An internal tool or a dashboard for your team, weekend project, data entry form, kiosk app or high-fidelity prototype - Flet is an ideal framework to quickly hack a great-looking interactive apps to serve a group of users.

2. Simple architecture

No more complex architecture with JavaScript frontend, REST API backend, database, cache, etc. With Flet you just write a monolith stateful app in Python only and get multi-user, realtime Single-Page Application (SPA).

3. Batteries included To start developing with Flet, you just need your favorite IDE or text editor. No SDKs, no thousands of dependencies, no complex tooling - Flet has built-in web server with assets hosting and desktop clients.

4. Powered by Flutter

Flet UI is built with Flutter, so your app looks professional and could be delivered to any platform. Flet simplifies Flutter model by combining smaller “widgets” to ready-to-use “controls” with imperative programming model.

5. Speaks your language

Flet is language-agnostic, so anyone on your team could develop Flet apps in their favorite language. Python is already supported, Go, C# and others are coming next.

6. Deliver to any device

Deploy Flet app as a web app and view it in a browser. Package it as a standalone desktop app for Windows, macOS and Linux. Install it on mobile as PWA or view via Flet app for iOS and Android.


Whats the use case, what problem does it solve ?

Flet enables you to easily build realtime web, mobile and desktop apps in your favorite language and securely share them with your team. No frontend experience required.


Example code

Here is a simple example code that will start up a application as a standalone and platform independent application.

import flet
from flet import ElevatedButton, Text, TextField


def main(page):
    def btn_click(e):
        if not txt_name.value:
            txt_name.error_text = "Please enter your name"
            page.update()
        else:
            name = txt_name.value
            page.clean()
            page.add(Text(f"Hello, {name}!"))

    txt_name = TextField(label="Your name")

    page.add(txt_name, ElevatedButton("Say hello!", on_click=btn_click))


flet.app(target=main)

If you prefer the application as a web application, you simple change the target to:

flet.app(target=main, view=flet.WEB_BROWSER)


Sources


Install

pip install flet"