Configs¶
Overview¶
The configs module provides tools for standardized configuration management and injection, supporting consistent setup across services like databases, Redis, and email.
Quick Start¶
from archipy.configs.base_config import BaseConfig
class AppConfig(BaseConfig):
APP_NAME: str = "MyService"
DEBUG: bool = False
DB_HOST: str = "localhost"
DB_PORT: int = 5432
API Stability¶
Component | Status | Notes |
---|---|---|
BaseConfig | 🟢 Stable | Production-ready |
Config Templates | 🟢 Stable | Production-ready |
Environment Types | 🟢 Stable | Production-ready |
Core Classes¶
BaseConfig¶
The main configuration class that provides environment variable support, type validation, and global configuration access.
Key Features: - Environment variable support - Type validation - Global configuration access - Nested configuration support
SQLAlchemyConfig¶
Database configuration template with connection settings, pool configuration, and debug options.
Key Features: - Database connection settings - Pool configuration - Migration settings - Debug options
Examples¶
For practical examples, see the Configuration Management Guide.
Source Code¶
📁 Location: archipy/configs/
🔗 Browse Source
- ENABLE_FROM_LINTING
: Whether to enable SQL linting
- HIDE_PARAMETERS
: Whether to hide SQL parameters in logs
- HOST
: Database host
- ISOLATION_LEVEL
: Transaction isolation level
- PASSWORD
: Database password
- POOL_MAX_OVERFLOW
: Maximum number of connections in pool overflow
- POOL_PRE_PING
: Whether to ping connections before use
- POOL_RECYCLE_SECONDS
: Seconds between connection recycling
- POOL_RESET_ON_RETURN
: Action when returning connections to pool
- POOL_SIZE
: Number of connections to keep open
- POOL_TIMEOUT
: Seconds to wait for a connection
- POOL_USE_LIFO
: Whether to use LIFO for connection pool
- PORT
: Database port
- QUERY_CACHE_SIZE
: Size of the query cache
- USERNAME
: Database username
SQLiteSQLAlchemyConfig¶
Class: archipy.configs.config_template.SQLiteSQLAlchemyConfig
Configures:
- SQLite-specific database settings
- In-memory database options
- SQLite isolation levels
Attributes:
DRIVER_NAME
: SQLite driver nameDATABASE
: SQLite database pathISOLATION_LEVEL
: SQLite isolation levelPORT
: Not used for SQLite
PostgresSQLAlchemyConfig¶
Class: archipy.configs.config_template.PostgresSQLAlchemyConfig
Configures:
- PostgreSQL-specific database settings
- Connection URL building
- DSN configuration
Attributes:
POSTGRES_DSN
: PostgreSQL connection URL
StarrocksSQLAlchemyConfig¶
Class: archipy.configs.config_template.StarrocksSQLAlchemyConfig
Configures:
- Starrocks-specific database settings
- Catalog configuration
Attributes:
CATALOG
: Starrocks catalog name
RedisConfig¶
Class: archipy.configs.config_template.RedisConfig
Configures:
- Connection settings
- Pool configuration
- SSL options
- Sentinel support
Attributes:
MASTER_HOST
: Redis master hostSLAVE_HOST
: Redis slave hostPORT
: Redis server portDATABASE
: Redis database numberPASSWORD
: Redis passwordDECODE_RESPONSES
: Whether to decode responsesVERSION
: Redis protocol versionHEALTH_CHECK_INTERVAL
: Health check interval in seconds
EmailConfig¶
Class: archipy.configs.config_template.EmailConfig
Configures:
- SMTP settings
- Authentication
- TLS options
- Default headers
Attributes:
SMTP_SERVER
: SMTP server hostSMTP_PORT
: SMTP server portUSERNAME
: SMTP usernamePASSWORD
: SMTP passwordPOOL_SIZE
: Connection pool sizeCONNECTION_TIMEOUT
: Connection timeout in secondsMAX_RETRIES
: Maximum retry attemptsATTACHMENT_MAX_SIZE
: Maximum attachment size in bytes
FastAPIConfig¶
Class: archipy.configs.config_template.FastAPIConfig
Configures:
- API versioning
- CORS configuration
- Rate limiting
- Documentation
Attributes:
PROJECT_NAME
: Name of the FastAPI projectAPI_PREFIX
: URL prefix for API endpointsACCESS_LOG
: Whether to enable access loggingBACKLOG
: Maximum number of queued connectionsDATE_HEADER
: Whether to include date header in responsesFORWARDED_ALLOW_IPS
: List of allowed forwarded IPsLIMIT_CONCURRENCY
: Maximum concurrent requestsLIMIT_MAX_REQUESTS
: Maximum number of requestsCORS_MIDDLEWARE_ALLOW_CREDENTIALS
: Whether to allow credentials in CORSCORS_MIDDLEWARE_ALLOW_HEADERS
: Allowed CORS headersCORS_MIDDLEWARE_ALLOW_METHODS
: Allowed CORS methodsCORS_MIDDLEWARE_ALLOW_ORIGINS
: Allowed CORS originsPROXY_HEADERS
: Whether to trust proxy headersRELOAD
: Whether to enable auto-reloadSERVER_HEADER
: Whether to include server headerSERVE_HOST
: Host to serve the application onSERVE_PORT
: Port to serve the application onTIMEOUT_GRACEFUL_SHUTDOWN
: Graceful shutdown timeoutTIMEOUT_KEEP_ALIVE
: Keep-alive timeoutWORKERS_COUNT
: Number of worker processesWS_MAX_SIZE
: Maximum WebSocket message sizeWS_PER_MESSAGE_DEFLATE
: Whether to enable WebSocket compressionWS_PING_INTERVAL
: WebSocket ping intervalWS_PING_TIMEOUT
: WebSocket ping timeoutOPENAPI_URL
: URL for OpenAPI schemaDOCS_URL
: URL for API documentationRE_DOCS_URL
: URL for ReDoc documentationSWAGGER_UI_PARAMS
: Swagger UI parameters
GrpcConfig¶
Class: archipy.configs.config_template.GrpcConfig
Configures:
- Server settings
- Client configuration
- Interceptors
- SSL/TLS options
Attributes:
SERVE_PORT
: Port to serve gRPC onSERVE_HOST
: Host to serve gRPC onTHREAD_WORKER_COUNT
: Number of worker threadsTHREAD_PER_CPU_CORE
: Threads per CPU coreSERVER_OPTIONS_CONFIG_LIST
: Server configuration optionsSTUB_OPTIONS_CONFIG_LIST
: Client stub configuration options
SentryConfig¶
Class: archipy.configs.config_template.SentryConfig
Configures:
- DSN configuration
- Environment settings
- Sample rates
- Performance monitoring
Attributes:
IS_ENABLED
: Whether Sentry is enabledDSN
: Sentry DSN for error reportingDEBUG
: Whether to enable debug modeRELEASE
: Application release versionSAMPLE_RATE
: Error sampling rate (0.0 to 1.0)TRACES_SAMPLE_RATE
: Performance monitoring sampling rate (0.0 to 1.0)
ElasticsearchConfig¶
Class: archipy.configs.config_template.ElasticsearchConfig
Configures:
- Cluster configuration
- Authentication
- Index settings
- Retry policies
Attributes:
SEARCH_HOSTS
: List of Elasticsearch server hostsSEARCH_HTTP_USER_NAME
: Username for HTTP authenticationSEARCH_HTTP_PASSWORD
: Password for HTTP authenticationSEARCH_HTTPS_VERIFY_CERTS
: Whether to verify SSL certificatesSEARCH_KWARG
: Additional keyword arguments for Elasticsearch clientSEARCH_BATCH_INTERVAL_THRESHOLD_IN_SECONDS
: Time threshold for batch operationsSEARCH_BATCH_DOC_COUNT_THRESHOLD
: Document count threshold for batch operations
ElasticsearchAPMConfig¶
Class: archipy.configs.config_template.ElasticsearchAPMConfig
Configures:
- APM server settings
- Service name
- Transaction sampling
- Instrumentation
Attributes:
API_REQUEST_SIZE
: Maximum size of API requestsAPI_REQUEST_TIME
: Maximum time for API requestsAUTO_LOG_STACKS
: Whether to automatically log stack tracesCAPTURE_BODY
: Level of request body captureCAPTURE_HEADERS
: Whether to capture HTTP headersCOLLECT_LOCAL_VARIABLES
: Level of local variable collectionIS_ENABLED
: Whether APM is enabledENVIRONMENT
: APM environment nameLOG_FILE
: Path to APM log fileLOG_FILE_SIZE
: Maximum size of APM log fileRECORDING
: Whether to record transactionsSECRET_TOKEN
: APM secret tokenSERVER_TIMEOUT
: Server timeout durationSERVER_URL
: APM server URLSERVICE_NAME
: Name of the service being monitoredSERVICE_VERSION
: Version of the serviceTRANSACTION_SAMPLE_RATE
: Rate at which to sample transactionsAPI_KEY
: API key for authentication
KafkaConfig¶
Class: archipy.configs.config_template.KafkaConfig
Configures:
- Broker configuration
- Consumer groups
- Producer settings
- Security options
Attributes:
ACKNOWLEDGE_COUNT
: Number of acknowledgments requiredAUTO_OFFSET_RESET
: Action to take when there is no initial offsetBROKERS_LIST
: List of Kafka broker addressesCERT_PEM
: Path to SSL certificateENABLE_AUTO_COMMIT
: Whether to enable auto-commitMAX_BUFFER_MS
: Maximum time to buffer messagesMAX_BUFFER_SIZE
: Maximum number of messages to bufferPASSWORD
: Password for authenticationSASL_MECHANISMS
: SASL mechanism for authenticationSECURITY_PROTOCOL
: Security protocol to useSESSION_TIMEOUT_MS
: Session timeout in millisecondsREQUEST_ACK_TIMEOUT_MS
: Request acknowledgment timeoutDELIVERY_MESSAGE_TIMEOUT_MS
: Message delivery timeoutUSER_NAME
: Username for authenticationLIST_TOPICS_TIMEOUT
: Timeout for listing topics
KeycloakConfig¶
Class: archipy.configs.config_template.KeycloakConfig
Configures:
- Server connection
- Authentication settings
- SSL verification
- Timeout configuration
Attributes:
SERVER_URL
: URL of the Keycloak serverCLIENT_ID
: Client ID for authenticationREALM_NAME
: Name of the Keycloak realmCLIENT_SECRET_KEY
: Client secret keyVERIFY_SSL
: Whether to verify SSL certificatesTIMEOUT
: Request timeout in seconds
MinioConfig¶
Class: archipy.configs.config_template.MinioConfig
Configures:
- Server connection
- Authentication
- Security settings
- Region configuration
Attributes:
ENDPOINT
: MinIO server endpointACCESS_KEY
: Access key for authenticationSECRET_KEY
: Secret key for authenticationSECURE
: Whether to use secure (HTTPS) connectionSESSION_TOKEN
: Session token for temporary credentialsREGION
: AWS region for S3 compatibility
PrometheusConfig¶
Class: archipy.configs.config_template.PrometheusConfig
Configures:
- Metrics collection
- Server settings
- Endpoint configuration
Attributes:
IS_ENABLED
: Whether Prometheus metrics are enabledSERVER_PORT
: Port for the Prometheus metrics endpoint
KavenegarConfig¶
Class: archipy.configs.config_template.KavenegarConfig
Configures:
- API connection
- Authentication
- Default sender settings
Attributes:
SERVER_URL
: Kavenegar API server URLAPI_KEY
: Kavenegar API keyPHONE_NUMBER
: Default sender phone number
AuthConfig¶
Class: archipy.configs.config_template.AuthConfig
Configures:
- JWT settings
- TOTP configuration
- Rate limiting
- Password policies
- Token security
Attributes:
SECRET_KEY
: JWT signing keyACCESS_TOKEN_EXPIRES_IN
: Access token expiration in secondsREFRESH_TOKEN_EXPIRES_IN
: Refresh token expiration in secondsHASH_ALGORITHM
: JWT signing algorithmJWT_ISSUER
: JWT issuer claimJWT_AUDIENCE
: JWT audience claimTOKEN_VERSION
: JWT token versionTOTP_SECRET_KEY
: TOTP master keyTOTP_HASH_ALGORITHM
: TOTP hash algorithmTOTP_LENGTH
: TOTP code lengthTOTP_EXPIRES_IN
: TOTP expiration in secondsTOTP_TIME_STEP
: TOTP time step in secondsTOTP_VERIFICATION_WINDOW
: TOTP verification window sizeTOTP_MAX_ATTEMPTS
: Maximum TOTP verification attemptsTOTP_LOCKOUT_TIME
: TOTP lockout duration in secondsLOGIN_RATE_LIMIT
: Login attempts per minuteTOTP_RATE_LIMIT
: TOTP requests per minutePASSWORD_RESET_RATE_LIMIT
: Password reset requests per hourHASH_ITERATIONS
: Password hash iterationsMIN_LENGTH
: Minimum password lengthREQUIRE_DIGIT
: Whether password requires digitsREQUIRE_LOWERCASE
: Whether password requires lowercaseREQUIRE_SPECIAL
: Whether password requires special charsREQUIRE_UPPERCASE
: Whether password requires uppercaseSALT_LENGTH
: Password salt lengthSPECIAL_CHARACTERS
: Allowed special charactersPASSWORD_HISTORY_SIZE
: Number of previous passwords to rememberENABLE_JTI_CLAIM
: Whether to enable JWT ID claimENABLE_TOKEN_ROTATION
: Whether to enable refresh token rotationREFRESH_TOKEN_REUSE_INTERVAL
: Refresh token reuse grace period
FileConfig¶
Class: archipy.configs.config_template.FileConfig
Configures:
- File link security
- Expiration policies
- File type restrictions
Attributes:
SECRET_KEY
: Secret key for generating secure file linksDEFAULT_EXPIRY_MINUTES
: Default link expiration time in minutesALLOWED_EXTENSIONS
: List of allowed file extensions
DatetimeConfig¶
Class: archipy.configs.config_template.DatetimeConfig
Configures:
- API connections
- Time service settings
- Caching behavior
Attributes:
TIME_IR_API_KEY
: API key for time.ir serviceTIME_IR_API_ENDPOINT
: Endpoint for time.ir serviceREQUEST_TIMEOUT
: Request timeout in secondsMAX_RETRIES
: Maximum retry attemptsCACHE_TTL
: Cache time-to-live in secondsHISTORICAL_CACHE_TTL
: Cache time-to-live for historical dates in seconds
EnvironmentType¶
Class: archipy.configs.environment_type.EnvironmentType
Configures:
- Environment types (DEV, STAGING, PROD)
- Environment-specific behaviors
- Configuration validation rules
Includes all members, undocumented members, and shows inheritance.