Back to articles
setup config.py

setup config.py

via Dev.toNihal

Every project starts the same way… You hardcode a few values, sprinkle some os.getenv() calls, and tell yourself “I’ll clean this up later.” Later never comes. Instead, just do this 👇 Install package: pip install pydantic-settings config.py from pydantic_settings import BaseSettings class Settings ( BaseSettings ): APP_ENV : str = " development " APP_TITLE : str = " App Title " APP_VERSION : str = " 1.0.0 " FRONTEND_URL : str = " http://localhost:5173 " SECRET_KEY : str CORS_ORIGINS : list [ str ] = [] class Config : env_file = " .env " env_file_encoding = " utf-8 " case_sensitive = True extra = " ignore " settings = Settings () Why This Is Actually Nice You get defaults , so your app runs instantly You get env overrides , so prod doesn’t break You get type safety , no weird bugs later How You Use It import config.settings print ( settings . APP_ENV ) Boom. Done.

Continue reading on Dev.to

Opens in a new tab

Read Full Article
3 views

Related Articles