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.0a13.tar.gz (409.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.0a13-py3-none-win_amd64.whl (12.6 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3

flut-0.0.0a13-py3-none-macosx_10_14_universal2.whl (53.3 MB view details)

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

File details

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

File metadata

  • Download URL: flut-0.0.0a13.tar.gz
  • Upload date:
  • Size: 409.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.0a13.tar.gz
Algorithm Hash digest
SHA256 56e93c2eabe570d0b32cec54c77879f1ddfa9e4ddcfde13c93733da644a884a7
MD5 24d27d512a8770b3f8270e6ec9f8ea45
BLAKE2b-256 693715839ec79cafee311b582e3c0ec0e249b956e358e5b798e35e4860245f05

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: flut-0.0.0a13-py3-none-win_amd64.whl
  • Upload date:
  • Size: 12.6 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.0a13-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 131e81ef577be681b33eb2ac26475ab69439e43900fb430d98a7b6d398ef2ec1
MD5 5b971bc61b9c9d3e4af28f37c6f302b6
BLAKE2b-256 4c5cfa3fea5fb3f85235cc7c08484213b48946ad699e6d054f3a9e6d75910609

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flut-0.0.0a13-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4ac2dca20a65201b7803ca9f8e05153c4309c855d9add84c99f21516c4eb2463
MD5 c81964ee7b140e750542d0b739db10f7
BLAKE2b-256 d8ecb555d8ffa61d1b7006094db982d5f77bc65eea42fd92caeaa7ae79f8e8ce

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flut-0.0.0a13-py3-none-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 df2e2008527c88ae4cc53bb1123c83f265e94000075f146ab3b396f25fa7bb82
MD5 14ccc4c5f702c0c0edf389c672613bd1
BLAKE2b-256 bf0bda198d4a4054241318f42e7ef077e7095ffe3fab073d53ec27743e72e872

See more details on using hashes here.

Provenance

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