Skip to main content

Flutter, but in Python

Project description

Flut

Flutter, but in Python

Overview

Flut is a Python project that exposes Flutter to Python's ecosystem. Flut is designed to honestly expose Flutter's API as closely as possible.

True Flutter

Flutter code maps almost 1:1 from Dart to Python.

// Flutter (Dart)
Container(
  padding: EdgeInsets.all(16),
  decoration: BoxDecoration(
    color: Colors.blue,
    borderRadius: BorderRadius.circular(8),
  ),
  child: Text('Hello'),
)
# Flut (Python)
Container(
  padding=EdgeInsets.all(16),
  decoration=BoxDecoration(
    color=Colors.blue,
    borderRadius=BorderRadius.circular(8),
  ),
  child=Text('Hello'),
)

Under the hood, the real Flutter widget system is used.

State-of-the-Art asyncio Integration

Flut provides a true async integration, bridging asyncio with the Flutter UI thread in a design that exactly matches Flutter. Thread safety and event loop conflicts are handled internally.

No Performance Surprises

The majority of projects using Flut will enjoy near identical performance to Flutter. FFI between Python and Dart does bring additional communication overhead, but the cost is fixed.

Status

This project is in Technical Preview.

  • APIs are subject to change.
  • Not ready for production use.

Installation

pip install flut

Prebuilt wheels are available for Windows (x64), macOS (x64, arm64), and Linux (x64).

Building from source is also supported and requires the Flutter SDK.

Usage

Create a file app.py:

from flut import run_app
from flut.flutter.widgets import StatelessWidget, StatefulWidget, State, Text, Center, Column, Icon, MainAxisAlignment
from flut.flutter.material import MaterialApp, Scaffold, AppBar, FloatingActionButton, Icons, ThemeData, ColorScheme, Colors, Theme


class MyApp(StatelessWidget):
    def build(self, context):
        return MaterialApp(
            title="Flut Demo",
            theme=ThemeData(
                colorScheme=ColorScheme.fromSeed(seedColor=Colors.deepPurple),
            ),
            home=MyHomePage(title="Flut Demo Home Page"),
        )


class MyHomePage(StatefulWidget):
    def __init__(self, title):
        super().__init__()
        self.title = title

    def createState(self):
        return _MyHomePageState()


class _MyHomePageState(State[MyHomePage]):
    def initState(self):
        self._counter = 0

    def _incrementCounter(self):
        def _update():
            self._counter += 1

        self.setState(_update)

    def build(self, context):
        return Scaffold(
            appBar=AppBar(
                title=Text(self.widget.title),
                backgroundColor=Theme.of(context).colorScheme.inversePrimary,
            ),
            body=Center(
                child=Column(
                    mainAxisAlignment=MainAxisAlignment.center,
                    children=[
                        Text("You have pushed the button this many times:"),
                        Text(
                            f"{self._counter}",
                            style=Theme.of(context).textTheme.headlineMedium,
                        ),
                    ],
                ),
            ),
            floatingActionButton=FloatingActionButton(
                onPressed=self._incrementCounter,
                tooltip="Increment",
                child=Icon(Icons.add),
            ),
        )


if __name__ == "__main__":
    run_app(MyApp())

Run it:

python app.py

For async support:

import asyncio
from flut import run_app_async

# ... your app code ...

if __name__ == "__main__":
    asyncio.run(run_app_async(MyApp()))

Development Setup

cd flut/.flutter
flutter build windows/macos/linux --no-tree-shake-icons

License

MIT

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

flut-0.0.0a15.tar.gz (424.2 kB view details)

Uploaded Source

Built Distributions

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

flut-0.0.0a15-py3-none-win_amd64.whl (12.9 MB view details)

Uploaded Python 3Windows x86-64

flut-0.0.0a15-py3-none-manylinux1_x86_64.whl (19.2 MB view details)

Uploaded Python 3

flut-0.0.0a15-py3-none-macosx_10_14_universal2.whl (55.0 MB view details)

Uploaded Python 3macOS 10.14+ universal2 (ARM64, x86-64)

File details

Details for the file flut-0.0.0a15.tar.gz.

File metadata

  • Download URL: flut-0.0.0a15.tar.gz
  • Upload date:
  • Size: 424.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for flut-0.0.0a15.tar.gz
Algorithm Hash digest
SHA256 420af65a4880caad1ba2426f7fb9260b5ccf8f6d19d8c14a5f5516160d8ffb68
MD5 5afef09598c5b48b3f11ed5cbd1d1db9
BLAKE2b-256 31a715d293d62e9b2ea8d4b26052086f02a9dbe24865dae045ff1b020a837bcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for flut-0.0.0a15.tar.gz:

Publisher: publish.yml on yangyuan/flut

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

File details

Details for the file flut-0.0.0a15-py3-none-win_amd64.whl.

File metadata

  • Download URL: flut-0.0.0a15-py3-none-win_amd64.whl
  • Upload date:
  • Size: 12.9 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for flut-0.0.0a15-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 cf5ab966618e5a3df5e96443c43028a5280d8b85de244f8c595049b01c3fe9f6
MD5 f36f7c7d47abb79b0074009765b7ce72
BLAKE2b-256 ed91ec141ea3d627fa35d4aca34a3cd43d80e500e76b53ca0fb30ae9e582df89

See more details on using hashes here.

Provenance

The following attestation bundles were made for flut-0.0.0a15-py3-none-win_amd64.whl:

Publisher: publish.yml on yangyuan/flut

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

File details

Details for the file flut-0.0.0a15-py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for flut-0.0.0a15-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 302f02376778a8d3ea6e9aa39abfbf308c36f63744471965034359ea4bfa81e0
MD5 66238392a02ffd01c4da237799ec4001
BLAKE2b-256 8362ec1b56f41b3431b3a3b071e9e5bb05ba7b05ab5d7aadceb5a6e400ba3091

See more details on using hashes here.

Provenance

The following attestation bundles were made for flut-0.0.0a15-py3-none-manylinux1_x86_64.whl:

Publisher: publish.yml on yangyuan/flut

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

File details

Details for the file flut-0.0.0a15-py3-none-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for flut-0.0.0a15-py3-none-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 855538782bd695cdde4ac7404675c9151dc226079d7216d09a850a72a39def5c
MD5 5b683803f5f56162af6be964f13249b6
BLAKE2b-256 0506e77f6d130c03efbf8b8013a49bb225eeadcd1e8408233f8c9442e301d814

See more details on using hashes here.

Provenance

The following attestation bundles were made for flut-0.0.0a15-py3-none-macosx_10_14_universal2.whl:

Publisher: publish.yml on yangyuan/flut

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