Module-Level Configuration

Defined at the top-level of a Python module (file), typically as global variables or constants. For example:

1
2
3
4
# settings.py
API_KEY = 'your-key-here'
DEBUG = True
TIMEOUT = 30

Usage:

1
from settings import API_KEY, DEBUG, TIMEOUT

Pydantic-Based Configuration

Pydantic is a data validation and parsing library.

define config (or any data model) as a class with type annotations, validation, and parsing built-in.

1
2
3
4
5
6
7
8
9
10
11
from pydantic import BaseSettings

class Settings(BaseSettings):
api_key: str
debug: bool = False
timeout: int = 30

class Config:
env_file = ".env"

settings = Settings()