Skip to content

Client Configuration

The Konigle SDK provides flexible configuration options to customize client behavior, performance, and logging settings.

Basic Configuration

Direct Configuration

import konigle

client = konigle.Client(
    api_key="your-api-key",
    base_url="https://tim.konigle.com/admin/api",
    timeout=60.0,
    retry_count=5
)

Environment Variables

Set configuration using environment variables with the KONIGLE_ prefix:

export KONIGLE_API_KEY="your-api-key"
export KONIGLE_TIMEOUT="60"
export KONIGLE_RETRY_COUNT="5"
export KONIGLE_LOG_LEVEL="DEBUG"
# Load configuration from environment
client = konigle.Client.from_env()

Configuration Object

from konigle.config import ClientConfig

config = ClientConfig(
    api_key="your-api-key",
    timeout=45.0,
    log_level="INFO",
    log_requests=True
)

client = konigle.Client(**config.to_dict())

Configuration Options

Authentication & Connection

Option Default Description
api_key Required Your Konigle API key
base_url https://tim.konigle.com/admin/api API base URL
timeout 30.0 Request timeout in seconds

Connection Pool

Option Default Description
max_connections 100 Maximum HTTP connections (1-1000)
keepalive_connections 20 Keep-alive connections (1-100)

Retry Behavior

Option Default Description
enable_retry true Enable automatic retries
retry_count 3 Number of retry attempts (0-10)
retry_backoff 0.5 Base backoff time in seconds

Logging & Debugging

Option Default Description
log_level WARNING Logging level (DEBUG, INFO, WARNING, ERROR)
log_requests false Log HTTP requests
log_responses false Log HTTP responses
user_agent None Custom user agent prefix

Common Patterns

Development Configuration

# Enhanced logging for development
client = konigle.Client(
    api_key="your-api-key",
    log_level="DEBUG",
    log_requests=True,
    log_responses=True,
    timeout=120.0
)

Production Configuration

# Optimized for production
client = konigle.Client(
    api_key="your-api-key",
    max_connections=200,
    keepalive_connections=50,
    retry_count=5,
    timeout=45.0
)

Environment-based Setup

import os

# Different configs per environment
if os.getenv("ENVIRONMENT") == "production":
    client = konigle.Client(
        api_key=os.getenv("KONIGLE_API_KEY"),
        log_level="ERROR",
        retry_count=5
    )
else:
    client = konigle.Client(
        api_key=os.getenv("KONIGLE_API_KEY"),
        log_level="DEBUG",
        log_requests=True
    )

High-throughput Configuration

# For applications with high request volume
client = konigle.Client(
    api_key="your-api-key",
    max_connections=500,
    keepalive_connections=100,
    timeout=60.0,
    retry_count=2
)

Validation Rules

  • keepalive_connections cannot exceed max_connections
  • timeout must be greater than 0
  • retry_count is limited to 0-10 attempts
  • log_level must be a valid Python logging level

Async Client Configuration

Async clients use identical configuration options:

async with konigle.AsyncClient(
    api_key="your-api-key",
    max_connections=200,
    timeout=60.0
) as client:
    # Use async client
    images = await client.images.list()

Configuration from Dictionary

config_dict = {
    "api_key": "your-api-key",
    "timeout": 60.0,
    "log_level": "INFO",
    "retry_count": 5
}

config = ClientConfig.from_dict(config_dict)
client = konigle.Client(**config.to_dict())