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.0a14.tar.gz (412.4 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.0a14-py3-none-win_amd64.whl (12.7 MB view details)

Uploaded Python 3Windows x86-64

flut-0.0.0a14-py3-none-manylinux1_x86_64.whl (18.9 MB view details)

Uploaded Python 3

flut-0.0.0a14-py3-none-macosx_10_14_universal2.whl (53.4 MB view details)

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

File details

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

File metadata

  • Download URL: flut-0.0.0a14.tar.gz
  • Upload date:
  • Size: 412.4 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.0a14.tar.gz
Algorithm Hash digest
SHA256 6fa2059ddc3baeed97779fde4eef543d75cc868cea907580fef79152a365c4df
MD5 0cb27e53ebe11eaaad8c72049035f29b
BLAKE2b-256 3598f338e55706c7401e23afe465de014043265a0643814f9a5614586bc8323a

See more details on using hashes here.

Provenance

The following attestation bundles were made for flut-0.0.0a14.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.0a14-py3-none-win_amd64.whl.

File metadata

  • Download URL: flut-0.0.0a14-py3-none-win_amd64.whl
  • Upload date:
  • Size: 12.7 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.0a14-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 eab09fffb03edf29ec6a89515a97937d5c545455c5747411b5268de9704dd727
MD5 53d4c3b1d62fc475d8a38f9e8dad366d
BLAKE2b-256 506a6d93e783dfd6b9938185f1d28a5d7980d100861034b1b56218d38efcd1b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for flut-0.0.0a14-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.0a14-py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for flut-0.0.0a14-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e2d92d27cf677c1becdea7591433c0fcb2a2adcf89d1ae1cbf54f2325d452910
MD5 301ac0e03bc6eac967046bf005daa521
BLAKE2b-256 f9953d36c2b939e803dcc4484a2904a2c6200cfd1d668ef9f821c15134157fda

See more details on using hashes here.

Provenance

The following attestation bundles were made for flut-0.0.0a14-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.0a14-py3-none-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for flut-0.0.0a14-py3-none-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 cd1bd11057de545a9264c3f9140ac64d3bd0eda168a559c24f49b1576c3312a8
MD5 6b89f209902412588f2f04bd7dcf7d09
BLAKE2b-256 30b03abac15561852bb7feddd0a5a975636636ac9e0ff0863b854750585d0a22

See more details on using hashes here.

Provenance

The following attestation bundles were made for flut-0.0.0a14-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