config.py 설정

발행: (2026년 4월 6일 AM 01:13 GMT+9)
1 분 소요
원문: Dev.to

Source: Dev.to

설치

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()

왜 이것이 실제로 좋은가

  • 기본값을 제공하므로 앱을 바로 실행할 수 있습니다.
  • 환경 변수 오버라이드를 지원해 프로덕션에서도 문제가 발생하지 않습니다.
  • 타입 안전성을 제공해 나중에 이상한 버그가 생기는 것을 방지합니다.

사용 방법

import config.settings

print(settings.APP_ENV)
0 조회
Back to Blog

관련 글

더 보기 »

Python에서 행렬

행렬 정의 python matrix = 1, 2, 3, 4, 5, 6, 7, 8, 9 3x3 행렬 만들기 python matrix_3x3 = 0 3 for in range3 일반적인 행렬 문제 행렬 전치…

오픈소스 릴리스 도움말

안녕하세요, 저는 로비와 게임을 실행하는 Node.js 서버 구조와 이를 통합하는 멀티플레이어 플러그인을 작업하고 있습니다. 그래서 제 질문은: is t...