Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run production Flask app locally, without a complex web server

Tags:

python

flask

I built a small web app for a friend. That friend's computer will not be connected to the Internet when using the app, so deploying it on Heroku is not an option.

Is there a way to deploy it locally without having to install a complex web server? Something small that can be packaged with the application? Using the built-in Flask server seems to be discouraged when you go to "production", but for a local app is it ok?

like image 203
Kinwolf Avatar asked Jan 09 '23 11:01

Kinwolf


2 Answers

If it's just going to be used offline by one person, then yes, the internal development server might be sufficient.

If you're looking for a simple way to send that app to her, then see pyinstaller:

pip install pyinstaller
pyinstaller your_app.py

Zip up the folder inside the new dist directory and pass that along.

If pyinstaller isn't for you, there are plenty of options.

like image 112
Celeo Avatar answered Jan 13 '23 19:01

Celeo


If you're just running the app locally, it should be fine. The main issues with the dev server are security and performance, but for an app that's not exposed to the outside and that has a single user, it should work fine. Even though you're using the dev server, it's still a good idea to turn off debug mode and enable multiprocess mode.

from multiprocessing import cpu_count
app.run(debug=False, processes=cpu_count())

If you want a little more performance, consider using uwsgi or gunicorn. Both are good WSGI app servers that can be installed with pip along with your application.

gunicorn -w $(nproc) --threads 2 --max-requests 10 myproject:app
like image 42
davidism Avatar answered Jan 13 '23 19:01

davidism