Coverage for app / core / config.py: 97%

37 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-04 06:09 -0500

1import os 

2from functools import lru_cache 

3from pydantic_settings import BaseSettings 

4 

5 

6class Settings(BaseSettings): 

7 # Environment 

8 env: str = "development" 

9 

10 # Database 

11 database_url_dev: str = "sqlite+aiosqlite:///./data/dev.db" 

12 database_url_prod: str = "sqlite+aiosqlite:///./data/prod.db" 

13 

14 # Ensure data directory exists 

15 def __init__(self, **kwargs): 

16 super().__init__(**kwargs) 

17 from pathlib import Path 

18 Path("./data").mkdir(exist_ok=True) 

19 

20 # Security 

21 secret_key: str = "change-me-in-production-use-a-real-secret-key" 

22 api_key_salt: str = "change-me-salt" 

23 algorithm: str = "HS256" 

24 access_token_expire_minutes: int = 60 * 24 * 7 # 7 days 

25 

26 # Magic Link 

27 magic_link_expire_minutes: int = 15 

28 

29 # CORS 

30 frontend_url: str = "http://localhost:5173" 

31 

32 # Email (optional for MVP) 

33 smtp_host: str = "" 

34 smtp_port: int = 587 

35 smtp_user: str = "" 

36 smtp_password: str = "" 

37 from_email: str = "noreply@moltfund.me" 

38 

39 # Blockchain APIs 

40 blockcypher_api_token: str = "" # Optional, increases rate limits 

41 helius_api_key: str = "" 

42 balance_poll_interval_seconds: int = 120 

43 

44 @property 

45 def database_url(self) -> str: 

46 if self.env == "production": 

47 return self.database_url_prod 

48 return self.database_url_dev 

49 

50 class Config: 

51 env_file = ".env" 

52 env_file_encoding = "utf-8" 

53 

54 

55@lru_cache 

56def get_settings() -> Settings: 

57 return Settings() 

58 

59 

60settings = get_settings()