config
konigle.config
¶
Configuration management for the Konigle SDK.
This module provides configuration classes and utilities for managing SDK settings, environment variables, and client configuration options.
ClientConfig
¶
Bases: BaseModel
Client configuration schema with validation and defaults.
This class defines all configuration options available for the Konigle SDK clients, with sensible defaults and environment variable support.
| PARAMETER | DESCRIPTION |
|---|---|
api_key
|
Konigle API key for authentication
|
base_url
|
Base URL for the Konigle API
|
timeout
|
Request timeout in seconds
|
retry_count
|
Number of retries for failed requests
|
retry_backoff
|
Base backoff time for exponential retry
|
max_connections
|
Maximum number of HTTP connections in pool
|
keepalive_connections
|
Number of connections to keep alive
|
user_agent
|
Custom user agent string
|
log_level
|
Logging level (DEBUG, INFO, WARNING, ERROR)
|
log_requests
|
Whether to log HTTP requests
|
log_responses
|
Whether to log HTTP responses
|
enable_retry
|
Whether to enable automatic retries
|
api_key = Field(...)
class-attribute
instance-attribute
¶
Konigle API key for authentication.
auth_prefix = Field(default='Token')
class-attribute
instance-attribute
¶
Authentication header prefix (e.g., 'Token' or 'Bearer').
base_url = Field(default=BASE_URL)
class-attribute
instance-attribute
¶
Base URL for the Konigle API.
enable_retry = Field(default=True)
class-attribute
instance-attribute
¶
Whether to enable automatic retries.
keepalive_connections = Field(default=20, gt=0, le=100)
class-attribute
instance-attribute
¶
Number of connections to keep alive.
log_level = Field(default='WARNING')
class-attribute
instance-attribute
¶
Logging level (DEBUG, INFO, WARNING, ERROR).
log_requests = Field(default=False)
class-attribute
instance-attribute
¶
Whether to log HTTP requests.
log_responses = Field(default=False)
class-attribute
instance-attribute
¶
Whether to log HTTP responses.
max_connections = Field(default=100, gt=0, le=1000)
class-attribute
instance-attribute
¶
Maximum number of HTTP connections in pool.
retry_backoff = Field(default=0.5, ge=0)
class-attribute
instance-attribute
¶
Base backoff time for exponential retry.
retry_count = Field(default=3, ge=0, le=10)
class-attribute
instance-attribute
¶
Number of retries for failed requests.
timeout = Field(default=30.0, gt=0)
class-attribute
instance-attribute
¶
Request timeout in seconds.
user_agent = Field(default=None)
class-attribute
instance-attribute
¶
Custom user agent string.
from_dict(config_dict)
classmethod
¶
Create configuration from a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
config_dict
|
Dictionary containing configuration values
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ClientConfig
|
ClientConfig instance |
from_env()
classmethod
¶
Create configuration from environment variables.
Environment variables should be prefixed with KONIQ_ and follow the field names. For example: KONIQ_API_KEY, KONIQ_BASE_URL, etc.
| RETURNS | DESCRIPTION |
|---|---|
ClientConfig
|
ClientConfig instance populated from environment variables |
| RAISES | DESCRIPTION |
|---|---|
ValidationError
|
If required fields are missing or invalid |
get_http_limits()
¶
Get HTTPX limits configuration.
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
Dictionary with HTTPX limits configuration |
get_user_agent()
¶
Get the user agent string for HTTP requests.
| RETURNS | DESCRIPTION |
|---|---|
str
|
User agent string, either custom or default |
should_retry_status_code(status_code)
¶
Determine if a status code should trigger a retry.
| PARAMETER | DESCRIPTION |
|---|---|
status_code
|
HTTP status code
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the status code indicates a retriable error |
to_dict()
¶
Export configuration as a dictionary.
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
Dictionary representation of the configuration |
validate_base_url(v)
classmethod
¶
Normalize base URL by removing trailing slash.
validate_keepalive_connections()
¶
Ensure keepalive connections doesn't exceed max connections.
validate_log_level(v)
classmethod
¶
Validate log level is a valid Python logging level.