Modified files
storeapi/config.py
---
+++
@@ -1,5 +1,6 @@
# Most of this taken from Redowan Delowar's post on configurations with Pydantic
# https://rednafi.github.io/digressions/python/2020/06/03/python-configs.html
+from functools import lru_cache
from typing import Optional
from pydantic_settings import BaseSettings, SettingsConfigDict
@@ -31,3 +32,13 @@
DB_FORCE_ROLL_BACK: bool = True
model_config = SettingsConfigDict(env_prefix="TEST_")
+
+
+@lru_cache()
+def get_config(env_state):
+ """Instantiate config based on the environment."""
+ configs = {"dev": DevConfig, "prod": ProdConfig, "test": TestConfig}
+ return configs[env_state]()
+
+
+config = get_config(BaseConfig().ENV_STATE)