Skip to main content
Version: 1.4.0 (latest)

common.typing

CallableAny

A special callable Any that returns argument but is recognized as Any type by dlt hint checkers

StrAny

immutable, covariant entity

StrStr

immutable, covariant entity

StrStrStr

immutable, covariant entity

TFun

any function

SecretSentinel Objects

class SecretSentinel()

[view_source]

Marks a secret type when part of type annotations

TDataItem

A single data item as extracted from data source

TDataItems

A single data item or a list as extracted from the data source

TAnyDateTime

DateTime represented as pendulum/python object, ISO string or unix timestamp

TLoaderFileFormat

known loader file formats

ConfigValueSentinel Objects

class ConfigValueSentinel(NamedTuple)

[view_source]

Class to create singleton sentinel for config and secret injected value

ConfigValue

Config value indicating argument that may be injected by config provider. Evaluates to None when type checking

SecretValue

Secret value indicating argument that may be injected by config provider. Evaluates to None when type checking

SupportsVariant Objects

@runtime_checkable
class SupportsVariant(Protocol, Generic[TVariantBase])

[view_source]

Defines variant type protocol that should be recognized by normalizers

Variant types behave like TVariantBase type (ie. Decimal) but also implement the protocol below that is used to extract the variant value from it. See Wei type declaration which returns Decimal or str for values greater than supported by destination warehouse.

SupportsHumanize Objects

class SupportsHumanize(Protocol)

[view_source]

asdict

def asdict() -> DictStrAny

[view_source]

Represents object as dict with a schema loadable by dlt

asstr

def asstr(verbosity: int = 0) -> str

[view_source]

Represents object as human readable string

get_type_name

def get_type_name(t: Type[Any]) -> str

[view_source]

Returns a human-friendly name of type t

is_callable_type

def is_callable_type(hint: Type[Any]) -> bool

[view_source]

Checks if hint is callable: a function or callable class. This function does not descend into type arguments ie. if Union, Literal or NewType contain callables, those are ignored

is_any_type

def is_any_type(t: Type[Any]) -> bool

[view_source]

Checks if t is one of recognized Any types

get_literal_args

def get_literal_args(literal: Type[Any]) -> List[Any]

[view_source]

Recursively get arguments from nested Literal types and return an unified list.

extract_inner_type

def extract_inner_type(hint: Type[Any],
preserve_new_types: bool = False,
preserve_literal: bool = False,
preserve_annotated: bool = False) -> Type[Any]

[view_source]

Gets the inner type from Literal, Optional, Final and NewType

Arguments:

  • hint Type[Any] - Type to extract
  • preserve_new_types bool - Do not extract supertype of a NewType

Returns:

  • Type[Any] - Inner type if hint was Literal, Optional or NewType, otherwise hint

get_all_types_of_class_in_union

def get_all_types_of_class_in_union(hint: Any,
cls: TAny,
with_superclass: bool = False
) -> List[TAny]

[view_source]

if hint is an Union that contains classes, return all classes that are a subclass or (optionally) superclass of cls

is_generic_alias

def is_generic_alias(tp: Any) -> bool

[view_source]

Tests if type is a generic alias ie. List[str]

is_subclass

def is_subclass(subclass: Any, cls: Any) -> bool

[view_source]

Return whether 'cls' is a derived from another class or is the same class.

Will handle generic types by comparing their origins.

get_generic_type_argument_from_instance

def get_generic_type_argument_from_instance(instance: Any,
sample_value: Optional[Any] = None
) -> Type[Any]

[view_source]

Infers type argument of a Generic class from an instance of that class using optional sample_value of the argument type

Inference depends on the presence of orig_class attribute in instance, if not present - sample_Value will be used

Arguments:

  • instance Any - instance of Generic class
  • sample_value Optional[Any] - instance of type of generic class, optional

Returns:

  • Type[Any] - type argument or Any if not known

copy_sig

def copy_sig(
wrapper: Callable[TInputArgs, Any]
) -> Callable[[Callable[..., TReturnVal]], Callable[TInputArgs, TReturnVal]]

[view_source]

Copies docstring and signature from wrapper to func but keeps the func return value type

copy_sig_any

def copy_sig_any(
wrapper: Callable[Concatenate[TDataItem, TInputArgs], Any]
) -> Callable[[Callable[..., TReturnVal]], Callable[Concatenate[
TDataItem, TInputArgs], TReturnVal]]

[view_source]

Copies docstring and signature from wrapper to func but keeps the func return value type

It converts the type of first argument of the wrapper to Any which allows to type transformers in DltSources. See filesystem source readers as example

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.