I have a Python API that uses Flask as the framework. I have a server where I have the code. I can run the API from Poetry or Gunicorn

When to Start the server using Gunicorn

In case you need concurrency and high performance, use this command. This method is used for production environment

go to API_BDG folder and execute:

export $(grep -v '^#' ../.env | xargs) && gunicorn -w <WORKERS_QTY> -b <SERVER_IP>:<SERVER_PORT> app:app

This command is composed of 2 parts connected with && which means that the second command is executed if the first is successful.

The first part of the command is:

export $(grep -v '^#' ../.env | xargs)

Where:

The Second part of the command is:

gunircorn -w <WORKERS_QTY> -b <SERVER_IP>:<SERVER_PORT> app:app

Where:

Start the server using Poetry

In case concurrency and high performance are not necessary, use this commands. It runs API DBG using Flask (single thread)

go to API_BDG folder and execute:

poetry shell
poetry run python3 src/app.py

It looks simpler and it easier to remember. So I not have to take care of concurrency and high performance I use this.

What are your thoughts of this? when do you prefer Gunicorn or Poetry? Do you have other preferred ways to run the APIs?

Lets share opinions and keep going forward!