Overview
The@dlt.resource decorator transforms any generator (yielding) function into a dlt resource, or wraps data directly into a resource. A resource represents a location within a source that holds data with specific structure (schema) or coming from specific origin, such as a REST API endpoint, database table, or tab in Google Sheets.
A dlt resource is a Python representation that combines both data and metadata (table schema) that describes the structure and instructs the loading of the data. A dlt resource is also an Iterable and can be used like any other iterable object (list, tuple, etc.).
Signature
Parameters
A function to be decorated or data compatible with dlt
run. Can be a generator function, list, iterator, or any iterable.A name of the resource that by default also becomes the name of the table to which the data is loaded. If not present, the name of the decorated function will be used.
A table name, if different from
name. This argument also accepts a callable that is used to dynamically create tables for stream-like resources yielding many datatypes.A schema hint that sets the maximum depth of nested table above which the remaining nodes are loaded as structs or JSON.
Controls how to write data to a table. Accepts a shorthand string literal or configuration dictionary.Allowed shorthand string literals:
append: Always add new data at the end of the tablereplace: Replace existing data with new dataskip: Prevent data from loadingmerge: Deduplicate and merge data based onprimary_keyandmerge_keyhints
A list, dict or pydantic model of column schemas. Typed dictionary describing column names, data types, write disposition and performance hints that gives you full control over the created table schema.When the argument is a pydantic model, the model will be used to validate the data yielded by the resource as well.
A column name or a list of column names that comprise a primary key. Typically used with “merge” write disposition to deduplicate loaded data.
A column name or a list of column names that define a merge key. Typically used with “merge” write disposition to remove overlapping data ranges (e.g., to keep a single record for a given day).
Schema contract settings that will be applied to this resource.
Defines the storage format of the table. Currently only “iceberg” is supported on Athena, and “delta” on the filesystem. Other destinations ignore this hint.
Format of the file in which resource data is stored. Useful when importing external files. Use
preferred to force a file format that is preferred by the destination used. This setting supersedes the load_file_format passed to pipeline run method.A list of references to other table’s columns. Format:Table and column names will be normalized according to the configured naming convention.
Hints for nested tables created by this resource.
When
True, dlt pipeline will extract and load this resource. If False, the resource will be ignored.A specification of configuration and secret values required by the resource.
If
True, the resource generator will be extracted in parallel with other resources. Transformers that return items are also parallelized.An incremental configuration for the resource to enable incremental loading.
Configuration section that comes right after ‘sources’ in default layout. If not present, the current python module name will be used.Default layout is
sources.<section>.<name>.<key_name>. Note that resource section is used only when a single resource is passed to the pipeline.Deprecated. Past functionality got merged into regular resource.
Returns
A
DltResource instance which may be loaded, iterated or combined with other resources into a pipeline.Configuration Injection
When used as a decorator, the resource may automatically bind function arguments to secret and config values:usernameis a required, explicit python argumentchess_urlis required and will be taken fromconfig.tomlif not explicitly passedapi_secretis required and will be taken fromsecrets.tomlif not explicitly passed