From the course: Build REST APIs with FastAPI
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Configuration - Python Tutorial
From the course: Build REST APIs with FastAPI
Configuration
An important aspect of making your server production-ready is handling configuration. This way the code stays the same, but you can change things like which port to listen on, what is the logging level, where is the authentication server. And configuration usually comes in several layers. The bottom one is the defaults and these are the ones that you set in the code. Once the server is starting without any changes, this is how it behaves. Second one is a configuration file and it overrides the default. Then we have environment variables and these are overriding the configuration file. And finally, the command line arguments that are going to override the environment ones. And you don't have to handle all of them, but this is usually how things are going on. There are many libraries for handling configuration in Python. I'm using mostly Dynaconf, which is a really nice library with support for environment variables, configuration files, and also secrets. These things that you don't put…