setup config.py

Published: (April 5, 2026 at 12:13 PM EDT)
1 min read
Source: Dev.to

Source: Dev.to

Installation

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 production doesn’t break.
  • You get type safety, no weird bugs later.

How You Use It

import config.settings

print(settings.APP_ENV)
0 views
Back to Blog

Related posts

Read more »