HuwiseConfig
Type-safe configuration management for Huwise API access.
Overview
HuwiseConfig is a Pydantic-based configuration class that provides:
- Validation: Ensures required fields are present
- Type safety: Full type hints and runtime validation
- Dependency injection: Pass configuration to components
- Secure logging: API keys are masked in string representations
Usage
From Environment Variables
from huwise_utils_py import HuwiseConfig
# Loads HUWISE_API_KEY (required by default),
# HUWISE_DOMAIN (optional, defaults to data.bs.ch), and HUWISE_API_TYPE (optional)
config = HuwiseConfig.from_env()
# Explicitly allow missing HUWISE_API_KEY (advanced/unauthenticated scenarios):
unauth_config = HuwiseConfig.from_env(require_api_key=False)
Programmatic
config = HuwiseConfig(
api_key="your-api-key",
domain="data.bs.ch",
api_type="automation/v1.0", # Optional, defaults to this
)
Properties
# Get the base URL for API requests
print(config.base_url)
# Output: https://data.bs.ch/api/automation/v1.0
# Get authorization headers
print(config.headers)
# Output with key: {"Authorization": "apikey your-api-key"}
# Output without key: {}
Dependency Injection
from huwise_utils_py import HuwiseConfig, HuwiseDataset
# Create a custom config for testing
test_config = HuwiseConfig(
api_key="test-key",
domain="test.example.com",
)
# Inject into components
dataset = HuwiseDataset.from_id("100123", config=test_config)
API Reference
HuwiseConfig
Bases: BaseModel
Configuration for Huwise API access.
Provides type-safe configuration management with environment variable loading and supports dependency injection patterns.
| ATTRIBUTE | DESCRIPTION |
|---|---|
api_key |
API key for Huwise authentication.
TYPE:
|
domain |
Huwise domain (e.g., data.bs.ch).
TYPE:
|
api_type |
API version/type (defaults to automation/v1.0).
TYPE:
|
Example
api_key: str | None = Field(default=None, description='API key for Huwise authentication')
class-attribute
instance-attribute
domain: str = Field(default=DEFAULT_HUWISE_DOMAIN, description='Huwise domain (e.g., data.bs.ch)')
class-attribute
instance-attribute
api_type: str = Field(default='automation/v1.0', description='API version/type')
class-attribute
instance-attribute
base_url: str
property
Construct the base API URL.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The full base URL for API requests without trailing slash. |
headers: dict[str, str]
property
Get authorization headers for API requests.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
Dictionary containing the Authorization header when api_key exists. |
from_env(*, require_api_key: bool = True) -> HuwiseConfig
classmethod
Load configuration from environment variables.
For Automation API usage, API key authentication is required by default.
The domain defaults to data.bs.ch when not set.
Set require_api_key=False only for explicit unauthenticated scenarios.
| RETURNS | DESCRIPTION |
|---|---|
HuwiseConfig
|
HuwiseConfig instance populated from environment. |
| RAISES | DESCRIPTION |
|---|---|
AppConfigError
|
If required environment variables are missing. |