Files
test/api_config.py
2026-02-20 11:34:02 +09:00

31 lines
1.1 KiB
Python

"""API 키 관리 - .env 파일에서 읽기"""
import os
from pathlib import Path
def load_api_keys():
"""프로젝트 폴더의 .env에서 API 키 로딩"""
# python-dotenv 있으면 사용
try:
from dotenv import load_dotenv
env_path = Path(__file__).resolve().parent / '.env'
load_dotenv(env_path)
except ImportError:
# python-dotenv 없으면 수동 파싱
env_path = Path(__file__).resolve().parent / '.env'
if env_path.exists():
with open(env_path, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if line and not line.startswith('#') and '=' in line:
key, _, value = line.partition('=')
os.environ.setdefault(key.strip(), value.strip())
return {
'CLAUDE_API_KEY': os.getenv('CLAUDE_API_KEY', ''),
'GPT_API_KEY': os.getenv('GPT_API_KEY', ''),
'GEMINI_API_KEY': os.getenv('GEMINI_API_KEY', ''),
'PERPLEXITY_API_KEY': os.getenv('PERPLEXITY_API_KEY', ''),
}
API_KEYS = load_api_keys()