We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eg:
from functools import lru_cache from typing import Optional
from pydantic_settings import BaseSettings, SettingsConfigDict
class BaseConfig(BaseSettings): ENV_STATE: Optional[str] = None
model_config = SettingsConfigDict( env_file=".env", extra="ignore", env_file_encoding="utf-8" )
class GlobalConfig(BaseConfig): DATABASE_URL: Optional[str] = None DB_FORCE_ROLL_BACK: bool = False LOG_FILE: Optional[str] = None LOGTAIL_API_KEY: Optional[str] = None JWT_ALGORITHM: Optional[str] = None JWT_SECRET_KEY: Optional[str] = None MAILGUN_API_KEY: Optional[str] = None MAILGUN_DOMAIN: Optional[str] = None B2_API_KEY_ID: Optional[str] = None B2_BUCKET_NAME: Optional[str] = None B2_API_KEY: Optional[str] = None OPENAI_API_KEY: Optional[str] = None OPENAI_IMAGE_SIZE: Optional[str] = None SENTRY_DSN: Optional[str] = None
class DevConfig(GlobalConfig): model_config = SettingsConfigDict(env_prefix="DEV_")
class ProdConfig(GlobalConfig): model_config = SettingsConfigDict(env_prefix="PROD_")
class TestConfig(GlobalConfig): DATABASE_URL: str = "sqlite:///test.db" DB_FORCE_ROLL_BACK: bool = True JWT_SECRET_KEY: str = ( "4598398cca0a7ecb7c7466fb30e43d4525bb3f5c59974183c8f46724e63ccee7" ) JWT_ALGORITHM: str = "HS256"
model_config = SettingsConfigDict(env_prefix="TEST_")
@lru_cache() def get_config(env_state: str): configs = {"dev": DevConfig, "prod": ProdConfig, "test": TestConfig} return configsenv_state
config = get_config(BaseConfig().ENV_STATE)
The text was updated successfully, but these errors were encountered:
Implemented. It seemed more maintainable to have a single config for all future .env variables. Pre-existing in infrastructure untouched. Issue #115
Sorry, something went wrong.
davidjnevin
No branches or pull requests
eg:
from functools import lru_cache
from typing import Optional
from pydantic_settings import BaseSettings, SettingsConfigDict
class BaseConfig(BaseSettings):
ENV_STATE: Optional[str] = None
class GlobalConfig(BaseConfig):
DATABASE_URL: Optional[str] = None
DB_FORCE_ROLL_BACK: bool = False
LOG_FILE: Optional[str] = None
LOGTAIL_API_KEY: Optional[str] = None
JWT_ALGORITHM: Optional[str] = None
JWT_SECRET_KEY: Optional[str] = None
MAILGUN_API_KEY: Optional[str] = None
MAILGUN_DOMAIN: Optional[str] = None
B2_API_KEY_ID: Optional[str] = None
B2_BUCKET_NAME: Optional[str] = None
B2_API_KEY: Optional[str] = None
OPENAI_API_KEY: Optional[str] = None
OPENAI_IMAGE_SIZE: Optional[str] = None
SENTRY_DSN: Optional[str] = None
class DevConfig(GlobalConfig):
model_config = SettingsConfigDict(env_prefix="DEV_")
class ProdConfig(GlobalConfig):
model_config = SettingsConfigDict(env_prefix="PROD_")
class TestConfig(GlobalConfig):
DATABASE_URL: str = "sqlite:///test.db"
DB_FORCE_ROLL_BACK: bool = True
JWT_SECRET_KEY: str = (
"4598398cca0a7ecb7c7466fb30e43d4525bb3f5c59974183c8f46724e63ccee7"
)
JWT_ALGORITHM: str = "HS256"
@lru_cache()
def get_config(env_state: str):
configs = {"dev": DevConfig, "prod": ProdConfig, "test": TestConfig}
return configsenv_state
config = get_config(BaseConfig().ENV_STATE)
The text was updated successfully, but these errors were encountered: