PSA: Don’t use ever

Now, I know that using `` is a legitimate way to run an app in a development environment. But here's the thing I've see again and again: People using `` in production environments because they think they can run their Flask app like a node.js app while completely ignoring this message that pops up in red letters:

> WARNING: This is a development server. Do not use it in a production deployment.

Flask is not Express.js and Flask's internal dev server sucks for production. And it's a potential security risk if you leave debugging enabled. This is a statement you can find all over Flask's documentation.

- [Quickstart](
> This launches a very simple builtin server, which is good enough for testing **but probably not what you want to use in production**.

- [Command Line Interface](
> [...] The development server is provided for convenience, **but is not designed to be particularly secure, stable, or efficient**.

- [Deploy to Production](
> When running publicly rather than in development, you should not use the built-in development server (`flask run`). **The development server is provided by Werkzeug for convenience, but is not designed to be particularly efficient, stable, or secure**.

So much for the development server. **But why not use `` ever, not even while developing?** Not only is `flask run` the [recommended way]( to run an app while developing, I also think it creates a certain mindset. It eliminates the need for a dunder main construct which makes the Flask app practically not executable by passing it to `python`. That in turn makes it necessary to start a WSGI-compatible web server externally in any scenario. It want to believe that it makes people think about which environment they want to run the app in and whether to use `flask run` or `gunicorn`/`uwsgi`/`mod_wsgi`.

**tl;dr**: `` makes it look like running an app node.js-style by running the script directly is ok in production while in truth you *always* need an external WSGI-compatible web server to run Flask apps.

Thanks for coming to my TED Talk.

8 thoughts on “PSA: Don’t use ever”

  1. answering incomming questions right away:
    you can use, for example, waitress as wrapper for flask.

    get it: pip install waitress

    import it: from waitress import serve

    run it: serve(app, host=’′, port=5000)

    you don’t even have to change anything in your code.

  2. I just deployed my website to heroku, I’d really appreciate how to fix it (a tutorial?) since I think I am using

  3. This should be pinned on top of the sub. I didn’t learn proper deployment until moving on to ASGI framework where you have to had another web server to run your app.

  4. IF I’m deploying to a hosted service, specifically using Amazon Web Services Beanstalk, then as per the official documentation provided, I SHOULD use right? Because the host actually takes care of serving the app, load balancing etc? I’m a web dev noob, thank you for understanding.

  5. I’ve been advocating to use gunicorn in development and production for a long time too. It’s been like that for 5+ years in my Build a SAAS App with Flask course.

    If anyone is curious how to set that all up, it’s in the source code at:

    It handles using gunicorn, dealing with code reloading in development and also still gives you access to the in browser debugger. Files of interest would be config/, snakeeyes/ (DebuggedApplication class) and the bottom of the Dockerfile for running gunicorn (CMD).

    It also uses env variables for certain gunicorn options so that you can use the exact same config and setup in dev and prod, but then tweak certain env variables depending on where you run it. Such as using 1 gunicorn worker in development but X number of workers in prod.

    Then for production I’d throw nginx in front of that, but that’s a discussion for another time.


Leave a Comment