DEV Community

Discussion on: Structure Flask project with convention over configuration

Collapse
 
imankulov profile image
Roman Imankulov

Environment variables are the way to go 🚀!

Having a config.py doesn't mean that I don't use environment variables or initialize configuration from secrets. Instead, config provides an abstraction layer that hides the configuration source.

My current preferred setup consists of three files at the top of the project.

  • config.py: acts mainly as a proxy to environment variables.
  • services.py: a service registry that other parts of the code use heavily.
  • app.py: the module with a function initializing the project.

In the app.py, I wrap initialization with a function to avoid accidental initialization on import.

Here's my boilerplate.

GitHub logo imankulov / flask-boilerplate

Flask project boilerplate