Desktop Python applications with Flask

written by Eric J. Ma on 2021-05-12 | tags: python software development til

Today, I learned that it's possible to create a desktop app that uses Flask as the webserver, Python for application logic, and HTML/CSS/JS for the front-end.

The logic basically that we split the desktop app code into the front-end and back-end, and we let the front-end and back-end communicate data using JSON. The backend code does whatever complex logic is needed, while the front-end code simply does the rendering. It's basically a very familiar pattern for server-based applications.

One tool that helps with this is flaskwebgui, by GitHub user @ClimenteA. I found out about this tool by reading a dev.to article on using FastAPI to create a desktop application.

I also saw another article on using Svelte.js + Flask to create a Python app. That one also looks like a simple pattern to follow, with the advantage that Svelte.js makes reactivity very simple.

Of course, if you're looking to stay in a single language without this separation of concerns, it's feasible to stay with a single framework, like Streamlit, ipywidgets, Panel, and more. Indeed, for some projects, it may be more pragmatic to stick with a single language depending on the language skillset of those working on that project.