Base
provide.foundation.config.base
¶
Base configuration classes and utilities.
Classes¶
BaseConfig
¶
Base configuration class with common functionality.
All configuration classes should inherit from this.
Note on Validation
The validate() method is synchronous. Subclasses can override it to add custom validation logic. If async validation is needed, subclasses should implement their own async validation methods.
Functions¶
__attrs_post_init__
¶
Post-initialization hook for subclasses.
Note: validate() is not called automatically to allow subclasses to perform validation at the appropriate time (e.g., after all fields are populated from multiple sources).
Source code in provide/foundation/config/base.py
__repr__
¶
String representation hiding sensitive fields.
Source code in provide/foundation/config/base.py
clone
¶
diff
¶
Compare with another configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
BaseConfig
|
Configuration to compare with |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[Any, Any]]
|
Dictionary of differences (field_name: (self_value, other_value)) |
Source code in provide/foundation/config/base.py
from_dict
classmethod
¶
Create configuration from dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ConfigDict
|
Configuration data |
required |
source
|
ConfigSource
|
Source of the configuration |
RUNTIME
|
Returns:
| Type | Description |
|---|---|
Self
|
Configuration instance |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If validation fails |
Source code in provide/foundation/config/base.py
get_source
¶
Get the source of a configuration field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
Name of the field |
required |
Returns:
| Type | Description |
|---|---|
ConfigSource | None
|
Source of the field value or None |
Source code in provide/foundation/config/base.py
reset_to_defaults
¶
Reset all fields to their default values.
Source code in provide/foundation/config/base.py
to_dict
¶
Convert configuration to dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_sensitive
|
bool
|
Whether to include sensitive fields |
False
|
Returns:
| Type | Description |
|---|---|
ConfigDict
|
Dictionary representation of the configuration |
Source code in provide/foundation/config/base.py
update
¶
Update configuration with new values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
updates
|
ConfigDict
|
Dictionary of updates |
required |
source
|
ConfigSource
|
Source of the updates |
RUNTIME
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If validation fails after update |
Source code in provide/foundation/config/base.py
validate
¶
Validate the configuration.
This is a synchronous validation method. Override this in subclasses to add custom validation logic. Call this explicitly after creating and populating a configuration instance.
Raises:
| Type | Description |
|---|---|
ValidationError
|
If validation fails |
Source code in provide/foundation/config/base.py
Functions¶
field
¶
field(
*,
default: Any = NOTHING,
factory: Callable[[], Any] | None = None,
validator: (
Callable[[Any, Attribute[Any], Any], None] | None
) = None,
converter: Callable[[Any], Any] | None = None,
metadata: dict[str, Any] | None = None,
description: str | None = None,
env_var: str | None = None,
env_prefix: str | None = None,
sensitive: bool = False,
**kwargs: Any
) -> Any
Enhanced attrs field with configuration-specific metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Any
|
Default value for the field |
NOTHING
|
factory
|
Callable[[], Any] | None
|
Factory function to generate default value |
None
|
validator
|
Callable[[Any, Attribute[Any], Any], None] | None
|
Validation function |
None
|
converter
|
Callable[[Any], Any] | None
|
Conversion function |
None
|
metadata
|
dict[str, Any] | None
|
Additional metadata |
None
|
description
|
str | None
|
Human-readable description |
None
|
env_var
|
str | None
|
Environment variable name override |
None
|
env_prefix
|
str | None
|
Prefix for environment variable |
None
|
sensitive
|
bool
|
Whether this field contains sensitive data |
False
|
**kwargs
|
Any
|
Additional attrs field arguments |
{}
|