singer_sdk.Target

class singer_sdk.Target[source]

Bases: PluginBase, SimpleSingerReader

Abstract base class for targets.

The Target class manages config information and is responsible for processing the incoming Singer data stream and orchestrating any needed target Sink objects. As messages are received from the tap, the Target class will automatically create any needed target Sink objects and send records along to the appropriate Sink object for that record.

__init__(*, config=None, parse_env_config=False, validate_config=True, setup_mapper=True)[source]

Initialize the target.

Parameters:
  • config (dict | PurePath | str | list[PurePath | str] | None) – Target configuration. Can be a dictionary, a single path to a configuration file, or a list of paths to multiple configuration files.

  • parse_env_config (bool) – Whether to look for configuration values in environment variables.

  • validate_config (bool) – True to require validation of config settings.

  • setup_mapper (bool) – True to setup the mapper. Set to False if you want to

Return type:

None

final add_sink(stream_name, schema, key_properties=None)[source]

Create a sink and register it.

This method is internal to the SDK and should not need to be overridden.

Parameters:
  • stream_name (str) – Name of the stream.

  • schema (dict) – Schema of the stream.

  • key_properties (t.Sequence[str] | None) – Primary key of the stream.

Returns:

A new sink for the stream.

Return type:

Sink

classmethod append_builtin_config(config_jsonschema)[source]

Appends built-in config to config_jsonschema if not already set.

To customize or disable this behavior, developers may either override this class method or override the capabilities property to disabled any unwanted built-in capabilities.

For all except very advanced use cases, we recommend leaving these implementations “as-is”, since this provides the most choice to users and is the most “future proof” in terms of taking advantage of built-in capabilities which may be added in the future.

Parameters:

config_jsonschema (dict) – [description]

Return type:

None

classmethod cb_version(ctx, param, value)[source]

CLI callback to print the plugin version and exit.

Parameters:
  • ctx (Context) – Click context.

  • param (Option) – Click parameter.

  • value (bool) – Boolean indicating whether to print the version.

Return type:

None

static config_from_cli_args(*args)[source]

Parse CLI arguments into a config dictionary.

Parameters:

args (str) – CLI arguments.

Raises:

FileNotFoundError – If the config file does not exist.

Returns:

A tuple containing the config dictionary and a boolean indicating whether the config file was found.

Return type:

tuple[list[Path], bool]

deserialize_json(line)[source]

Deserialize a line of json.

Parameters:

line (str) – A single line of json.

Returns:

A dictionary of the deserialized json.

Raises:

InvalidInputLine – If the line is not valid JSON.

Return type:

dict

final drain_all(*, is_endofpipe=False)[source]

Drains all sinks, starting with those cleared due to changed schema.

This method is internal to the SDK and should not need to be overridden.

Parameters:

is_endofpipe (bool) – This is passed by the _process_endofpipe() which is called after the target instance has finished listening to the stdin

Return type:

None

final drain_one(sink)[source]

Drain a specific sink.

This method is internal to the SDK and should not need to be overridden.

Parameters:

sink (Sink) – Sink to be drained.

Return type:

None

classmethod get_plugin_version()[source]

Return the package version number.

Returns:

The package version number.

Return type:

str

classmethod get_sdk_version()[source]

Return the package version number.

Returns:

The package version number.

Return type:

str

classmethod get_singer_command()[source]

Execute standard CLI handler for taps.

Returns:

A click.Command object.

Return type:

Command

get_sink(stream_name, *, record=None, schema=None, key_properties=None)[source]

Return a sink for the given stream name.

A new sink will be created if schema is provided and if either schema or key_properties has changed. If so, the old sink becomes archived and held until the next drain_all() operation.

Developers only need to override this method if they want to provide a different sink depending on the values within the record object. Otherwise, please see default_sink_class property and/or the get_sink_class() method.

Raises singer_sdk.exceptions.RecordsWithoutSchemaException if sink does not exist and schema is not sent.

Parameters:
  • stream_name (str) – Name of the stream.

  • record (dict | None) – Record being processed.

  • schema (dict | None) – Stream schema.

  • key_properties (t.Sequence[str] | None) – Primary key of the stream.

Returns:

The sink used for this target.

Return type:

Sink

get_sink_class(stream_name)[source]

Get sink for a stream.

Developers can override this method to return a custom Sink type depending on the value of stream_name. Optional when default_sink_class is set.

Parameters:

stream_name (str) – Name of the stream.

Raises:

ValueError – If no singer_sdk.sinks.Sink class is defined.

Returns:

The sink class to be used with the stream.

Return type:

type[Sink]

classmethod get_supported_python_versions()[source]

Return the supported Python versions.

Returns:

A list of supported Python versions.

Return type:

list[str] | None

classmethod invoke(*, about=False, about_format=None, config=(), file_input=None)[source]

Invoke the target.

Parameters:
  • about (bool) – Display package metadata and settings.

  • about_format (str | None) – Specify output style for –about.

  • config (tuple[str, ...]) – Configuration file location or ‘ENV’ to use environment variables. Accepts multiple inputs as a tuple.

  • file_input (IO[str] | None) – Optional file to read input from.

Return type:

None

listen(file_input=None)[source]

Read from input until all messages are processed.

Parameters:

file_input (IO[T] | None) – Readable stream of messages. Defaults to standard in.

Return type:

None

classmethod print_about(output_format=None)[source]

Print capabilities and other tap metadata.

Parameters:

output_format (str | None) – Render option for the plugin information.

Return type:

None

classmethod print_version(print_fn=<built-in function print>)[source]

Print help text for the tap.

Parameters:

print_fn (Callable[[Any], None]) – A function to use to display the plugin version. Defaults to print().

Return type:

None

setup_mapper()[source]

Initialize the plugin mapper for this tap.

Return type:

None

sink_exists(stream_name)[source]

Check sink for a stream.

This method is internal to the SDK and should not need to be overridden.

Parameters:

stream_name (str) – Name of the stream

Returns:

True if a sink has been initialized.

Return type:

bool

property config: Mapping[str, Any][source]

Get config.

Returns:

A frozen (read-only) config dictionary map.

property initialized_at: int[source]

Start time of the plugin.

Returns:

The start time of the plugin.

property mapper: PluginMapper[source]

Plugin mapper for this tap.

Returns:

A PluginMapper object.

Raises:

MapperNotInitialized – If the mapper has not been initialized.

property max_parallelism: int[source]

Get max parallel sinks.

The default is 8 if not overridden.

Returns:

Max number of sinks that can be drained in parallel.

name: str[source]

The executable name of the tap or target plugin. e.g. tap-foo

package_name: str | None = None[source]

The package name of the plugin. e.g meltanolabs-tap-foo

property state: dict[source]

Get state.

Raises:

NotImplementedError – If the derived plugin doesn’t override this method.