Skip to main content

Create desktop applications with Flask/Django/FastAPI!

Project description

Create desktop applications with Flask/FastAPI/Django!

Downloads

Install

pip install flaskwebgui

Or download source file flaskwebgui.py and place it where you need.

Usage with Flask

Let's say we have the following flask application:

#main.py

from flask import Flask  
from flask import render_template
from flaskwebgui import FlaskUI # import FlaskUI

app = Flask(__name__)
ui = FlaskUI(app, width=500, height=500) # add app and parameters


@app.route("/")
def hello():  
    return render_template('index.html')

@app.route("/home", methods=['GET'])
def home(): 
    return render_template('some_page.html')


if __name__ == "__main__":
    # app.run() for debug
    ui.run()

Alternatively, next to main.py create a file called gui.py and add the following contents:

#gui.py

from flaskwebgui import FlaskUI
from main import app

FlaskUI(app, width=600, height=500).run()

Next start the application with:

python main.py 
#or
python gui.py #in case you created gui.py 

Application will start chrome in app mode, flask will be served by waitress.

Usage with FastAPI

Pretty much the same, bellow you have the main.py file:

from fastapi import FastAPI
from flaskwebgui import FlaskUI # import FlaskUI

app = FastAPI()
ui = FlaskUI(app) # feed app and parameters

@app.get("/")
def read_root():
    return {"message": "Works with FastAPI also!"}

if __name__ == "__main__":
    ui.run()

Alternatively, next to main.py create a file called gui.py and add the following contents:

#gui.py

from flaskwebgui import FlaskUI
from main import app

FlaskUI(app, width=600, height=500).run()

Next start the application with:

python main.py 
#or
python gui.py #in case you created gui.py 

Fastapi will be served by uvicorn.

Usage with Django

Next to manage.py file create a gui.py file where you need to import application from project's wsgi.py file.

#gui.py

from flaskwebgui import FlaskUI
from project_name.wsgi import application

FlaskUI(application).run()

Next start the application with:

python gui.py  

Django will be served by waitress.

Checkout examples folder.

Configurations

Default FlaskUI class parameters:

  • app, ==> flask class instance

  • width=800 ==> default width 800

  • height=600 ==> default height 600

  • fullscreen=False ==> start app in fullscreen

  • maximized=False ==> start app in maximized window

  • app_mode=True ==> by default it will start chrome in app(desktop) mode without address bar

  • browser_path="" ==> path to browser.exe (absolute path to chrome C:/browser_folder/chrome.exe)

  • start_server="flask" ==> You can add a function which starts the desired server for your choosed framework (bottle, web2py pyramid etc)

  • port=5000 ==> specify other if needed

  • socketio=SocketIO Instance ==> Flask SocketIO instance (if specified, uses socketio.run() instead of app.run() for Flask application)

Should work on windows/linux/mac with no isssues.

Develop your app as you would normally do, add flaskwebgui at the end or for tests. flaskwebgui doesn't interfere with your way of doing a flask application it just helps converting it into a desktop app more easily with pyinstaller or pyvan.

Distribution

You can distribute it as a standalone desktop app with pyinstaller or pyvan.

Credits

It's a combination of https://github.com/Widdershin/flask-desktop and https://github.com/ChrisKnott/Eel

flaskwebgui just uses threading to start a flask server and the browser in app mode (for chrome). It has some advantages over flask-desktop because it doesn't use PyQt5, so you won't have any issues regarding licensing and over Eel because you don't need to learn any logic other than Flask/Django.

Submit any questions/issues you have! Fell free to fork it and improve it!

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

flaskwebgui-0.1.15.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

flaskwebgui-0.1.15-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file flaskwebgui-0.1.15.tar.gz.

File metadata

  • Download URL: flaskwebgui-0.1.15.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for flaskwebgui-0.1.15.tar.gz
Algorithm Hash digest
SHA256 da69f7ea4ad9a7072ffc132108ab3ed7d35a7a7d2f222d7c70f098821808072d
MD5 1b8c9c989539d3af01572b0819033cfe
BLAKE2b-256 abe278f047ff7ab9c6df3bae8d65df0fc9ddec7f859e7f2f986858d872412ec3

See more details on using hashes here.

File details

Details for the file flaskwebgui-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: flaskwebgui-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for flaskwebgui-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 45fb6fa2bcf9efd7f45677fd50728c3ef0d524b8ba0c8bddd3698d51ebcf57ed
MD5 7432df7ac403030c5ed8ad7d7620f8d1
BLAKE2b-256 b5fb020a16851e097d9bcbc21a1bd32a52f880f16e886020bf481668dabde9c7

See more details on using hashes here.

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