dlt.common.configuration.specs.base_configuration
NotResolved Objects
class NotResolved()
Used in type annotations to indicate types that should not be resolved.
is_hint_not_resolvable
def is_hint_not_resolvable(hint: AnyType) -> bool
Checks if hint should NOT be resolved. Final and types annotated like
Annotated[str, NotResolved()]
are not resolved.
configspec
@dataclass_transform(eq_default=False,
field_specifiers=(dataclasses.Field, dataclasses.field))
def configspec(
cls: Optional[Type[Any]] = None,
init: bool = True
) -> Union[Type[TAnyClass], Callable[[Type[TAnyClass]], Type[TAnyClass]]]
Converts (via derivation) any decorated class to a Python dataclass that may be used as a spec to resolve configurations
init method is synthesized by default. init
flag is ignored if the decorated class implements custom init as well as
when any of base classes has no synthesized init
All fields must have default values. This decorator will add None
default values that miss one.
In comparison to the Python dataclass, a spec implements full dictionary interface for its attributes, allows instance creation from ie. strings
or other types (parsing, deserialization) and control over configuration resolution process. See BaseConfiguration
and CredentialsConfiguration` for
more information.
BaseConfiguration Objects
@configspec
class BaseConfiguration(MutableMapping[str, Any])
__is_resolved__
True when all config fields were resolved and have a specified value type
__exception__
Holds the exception that prevented the full resolution
__section__
Obligatory section used by config providers when searching for keys, always present in the search path
__config_gen_annotations__
Additional annotations for config generator, currently holds a list of fields of interest that have defaults
__dataclass_fields__
Typing for dataclass fields
from_init_value
@classmethod
def from_init_value(cls: Type[_B], init_value: Any = None) -> _B
Initializes credentials from init_value
Init value may be a native representation of the credentials or a dict. In case of native representation (for example a connection string or JSON with service account credentials)
a parse_native_representation
method will be used to parse it. In case of a dict, the credentials object will be updated with key: values of the dict.
Unexpected values in the dict will be ignored.
Credentials will be marked as resolved if all required fields are set resolve() method is successful
parse_native_representation
def parse_native_representation(native_value: Any) -> None
Initialize the configuration fields by parsing the native_value
which should be a native representation of the configuration
or credentials, for example database connection string or JSON serialized GCP service credentials file.
Arguments:
native_value
Any - A native representation of the configuration
Raises:
NotImplementedError
- This configuration does not have a native representationValueError
- The value provided cannot be parsed as native representation
to_native_representation
def to_native_representation() -> Any
Represents the configuration instance in its native form ie. database connection string or JSON serialized GCP service credentials file.
Raises:
NotImplementedError
- This configuration does not have a native representation
Returns:
Any
- A native representation of the configuration