Skip to content

Is it possible to check for Production or Development mode? #11847

Answered by YuriiMotov
retifrav asked this question in Questions
Discussion options

You must be logged in to vote

FastAPI CLI doesn't pass this information to FastAPI app.

The only difference between these commands is that FastAPI CLI uses different defaults for parameters to run ASGI server (host address and reload).

And since it's only default parameters, they can be overridden. For example command fastapi run main.py --host 127.0.0.1 --reload is a full equivalent of fastapi dev main.py.

As I know the common way to determine whether the app is running in prod or dev environment is to use ENV variable.
Just set ENV variable with the name like RUN_MODE to DEV on your local machine and to PROD on your production server

export RUN_MODE="DEV"

Then read this variable in your app:

from fastapi import Fas…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@retifrav
Comment options

Answer selected by retifrav
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants