Skip to content

Commit a8681fc

Browse files
Sid MohanSid Mohan
authored andcommitted
config.py
1 parent 08169bd commit a8681fc

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

datafog/config.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,66 @@
1+
import os
12
from enum import Enum
3+
from typing import Optional
4+
5+
from pydantic import HttpUrl
6+
from pydantic_settings import BaseSettings
7+
8+
9+
class DataFogConfig(BaseSettings):
10+
"""Configuration settings for DataFog SDK"""
11+
12+
# API Keys and Authentication
13+
api_key: str = os.environ.get("DATAFOG_API_KEY", "")
14+
15+
# Base URLs for different services
16+
annotator_base_url: HttpUrl = (
17+
"" # for ex, "https://datafog-api-prod.azurewebsites.net"
18+
)
19+
anonymizer_base_url: HttpUrl = (
20+
"" # for ex, "https://datafog-api-anonymizer-prod.azurewebsites.net"
21+
)
22+
23+
# Default language
24+
default_language: str = "en"
25+
26+
# Timeouts
27+
request_timeout: int = 30 # seconds
28+
29+
# Retry settings
30+
max_retries: int = 3
31+
retry_backoff_factor: float = 0.3
32+
33+
# Rate limiting
34+
rate_limit_per_minute: Optional[int] = None
35+
36+
# Logging
37+
log_level: str = "INFO"
38+
39+
class Config:
40+
env_prefix = "DATAFOG_"
41+
case_sensitive = False
42+
43+
def update(self, **kwargs):
44+
"""Update configuration with new values"""
45+
for key, value in kwargs.items():
46+
if hasattr(self, key):
47+
setattr(self, key, value)
48+
else:
49+
raise ValueError(f"Invalid configuration key: {key}")
50+
51+
52+
# Create a global instance of the configuration
53+
datafog_config = DataFogConfig()
54+
55+
56+
def get_config() -> DataFogConfig:
57+
"""Get the current configuration"""
58+
return datafog_config
59+
60+
61+
def configure(**kwargs):
62+
"""Update the global configuration"""
63+
datafog_config.update(**kwargs)
264

365

466
class OperationType(str, Enum):

0 commit comments

Comments
 (0)