Python Bytes is a weekly podcast hosted by Michael Kennedy and Brian Okken. The show is a short discussion on the headlines and noteworthy news in the Python, developer, and data science space.

#295 Flutter + Python GUI Apps?

August 04, 2022 00:36:16 30.6 MB Downloads: 0

Watch the live stream:

Watch on YouTube

About the show

Sponsored by Microsoft for Startups Founders Hub.

Michael #1: Faster routing for Flask & Quart

  • Flask and Quart both utilise Werkzeug's HTTP route
  • With the upcoming 2.2 release of Werkzeug this router will be significantly faster, with up to a factor of 5.
  • Better for large sets of routes
  • Micro-benchmarks are unaffected and are unlikely to show a speedup.
  • Started with tree-based radix algorithm
  • Moved to state machine algorithm because of wild cards

Brian #2: Quarto: an open-source scientific and technical publishing system built on Pandoc

  • suggested by Paul Mackenzie
  • Power of Pandoc and Jupyter
  • Build
    • documents - html, pdf, word
    • presentations - Revealjs, PowerPoint, Beemer
    • websites
    • books - html, pdf, word, epub
    • journal articles - acm, plos, elsevier, acs, jss
  • Publish
    • GitHub pages, Netlify, …
  • kinda related - Kindle to support ePub

Michael #3: Flet UI

  • via Mikael Honkala
  • New and upcoming UI framework by Feodor Fitzner: flet.
  • It has a very interesting stack - a Python client driving a Flutter front-end via a Go server.
  • That sounds complicated, but the developer experience is incredibly simple. Installation is just pip install flet.
  • Here's a quick and stupid but working sample:
    import time
    import flet
    from flet import Column, ElevatedButton, Page, Row, TextField
    
    def main(page: Page):
        text_field = TextField()
    
        def clear_field(event):
            text_field.value = "CLEARING"
            page.update()
            time.sleep(1)
            text_field.value = ""
            page.update()
    
        clear_button = ElevatedButton("Clear the field", on_click=clear_field)
        page.add(Row([Column([text_field, clear_button])], alignment="center"))
        page.update()
    
    flet.app(target=main)
    
    # If you run this, you get a native app window on Mac, Windows or Linux, looking something like this:
    

  • While the example is simple, it shows the handling of an event, updating the UI, and even doing a little sleeping between the updates, without having to worry about threads and such.
  • What's more important, if you change the last line to:

        flet.app(target=main, view=WEB_BROWSER)
    
  • You get the exact same functionality, but as a web application in a browser, with support for multiple users and deep linking to different parts of the app. All without leaving the comfortable Python world, with its access to all Python libraries, and without having to learn 3 extra, completely different languages (yes, HTML, CSS and JavaScript).

  • As this is Flutter, mobile support is in the works, after the basic UI functionality is all there.
  • Check the project front page here: flet.dev
  • Jump directly to the currently available controls: flet.dev/docs/controls
  • Check couple of tutorials here: flet.dev/docs/tutorials
  • Or read the plans for the mobile support here: flet.dev/blog/flet-mobile-strategy

Brian #4: Building an authenticated Python CLI

  • Project that uses click, rich, and OAth for using Twitter API
  • Persistent authentication
    • requests secret information from user using getpass and input
      • Client ID, Client Secret, App name
    • fetches bearer token from Twitter API
    • stores token in netrc file
  • I’m not familiar with netrc, so I don’t know if this is a good idea or not.
    • So I figured I’d ask Michael

Extras

Michael:

Joke: Light touches kingdom