Overview
The@dlt.destination decorator transforms a function that processes data items into a custom dlt destination. This allows you to create custom data sinks that receive batched data from dlt pipelines and handle it according to your own logic.
The decorator can also be used as a factory function to instantiate built-in destinations.
Signature
Parameters
A callable that takes two positional arguments:
items: Either a list of data items or a file path (string) ifbatch_size=0table: A dictionary containing the table schema with keys likename,columns, etc.
Defines the format in which files are stored in the load package before being sent to the destination function. Supported formats include “jsonl”, “parquet”, “csv”, etc.
Defines how many items per function call are batched together and sent as an array.
- If set to a positive number, items are batched and passed as a list
- If set to
0, instead of passing actual data items, you will receive one call per load job with the path of the file as theitemsargument, allowing you to open and process the file directly
Defines the name of the destination. If not provided, defaults to the name of the decorated function.
Controls how table and column names are normalized. The default value “direct” keeps all names unchanged. Other options include “snake_case”, “sql_cs_v1”, etc.
Defines whether internal dlt tables and columns (like
_dlt_id, _dlt_load_id) are included in the custom destination function.Defines how deep the normalizer will go to flatten nested fields in your data to create subtables. This overrides any source settings. A value of
0 means no nested tables are created.Defines a configuration spec used to inject arguments into the decorated function. Arguments not included in the spec will not be injected.
Defines the maximum number of load jobs that can run concurrently during the load process.
Determines the load job parallelism strategy:
"sequential": Equivalent tomax_parallel_load_jobs=1"table-sequential": One load job per table at a time"parallel": Multiple jobs can run in parallel
Returns
When used as a decorator: Returns a callable that creates a custom dlt destination instance when called.When used as a factory function with a string argument: Returns an initialized destination instance.
Usage Examples
Basic Custom Destination
File-Based Processing (batch_size=0)
Destination with Configuration and Secrets
Database Destination
Custom Destination with Table Schema Access
Destination Without dlt Internal Columns
Destination with Custom Naming Convention
Using as a Factory Function
Parallel Loading Strategy
Understanding batch_size
Thebatch_size parameter controls how data is passed to your destination function:
-
batch_size > 0: Items are batched in arrays of the specified size
-
batch_size = 0: You receive file paths instead of items
Configuration Injection
Like other dlt decorators,@dlt.destination supports automatic configuration injection: