Factus API uses pydantic-settings for type-safe configuration management. All settings are defined in a central configuration class and loaded from environment variables.
Configuration values are never hardcoded. All sensitive data and environment-specific settings are loaded from .env files or environment variables.
Type Safety: Pydantic validates all settings at startup. If required variables are missing or have invalid types, the application will fail to start with a clear error message.
Create a .env file in the project root with your configuration:
.env
# Factus API ConfigurationFACTUS_BASE_URL=https://api.factus.com.coFACTUS_CLIENT_ID=your_client_id_hereFACTUS_CLIENT_SECRET=your_client_secret_here# JWT ConfigurationSECRET_KEY=your_secret_key_here_generate_with_python_secretsALGORITHM=HS256ACCESS_TOKEN_EXPIRE_MINUTES=60# Application Configuration (Optional)PROJECT_NAME=Factus APIVERSION=1.0.0API_V1_STR=/api/v1
Security: Never commit .env files to version control. Add .env to your .gitignore file.
Pydantic automatically validates settings at startup:
class Settings(BaseSettings): # Must be a valid URL FACTUS_BASE_URL: str # Must be an integer ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 # Must be one of the specified values ALGORITHM: str = "HS256"
If validation fails, you’ll get a clear error:
ValidationError: 1 validation error for SettingsFACTUS_BASE_URL field required (type=value_error.missing)
FACTUS_BASE_URL=https://sandbox.factus.com.coFACTUS_CLIENT_ID=dev_client_idFACTUS_CLIENT_SECRET=dev_secretSECRET_KEY=dev_secret_keyACCESS_TOKEN_EXPIRE_MINUTES=480 # Longer for development
FACTUS_BASE_URL=https://api.factus.com.coFACTUS_CLIENT_ID=${FACTUS_CLIENT_ID} # From secrets managerFACTUS_CLIENT_SECRET=${FACTUS_CLIENT_SECRET}SECRET_KEY=${SECRET_KEY}ACCESS_TOKEN_EXPIRE_MINUTES=60
In production, use a secrets manager (AWS Secrets Manager, HashiCorp Vault, etc.) instead of .env files.