ScriptTransformer (autotransform.transformer.script)

The implementation for the ScriptTransformer.

class autotransform.transformer.script.ScriptTransformer(*, script: str, args: List[str], timeout: int, per_item: bool = False)

Bases: Transformer[None]

A Transformer that makes changes using an invoked script. Sentinel values can be used in args to provide custom arguments for a run. The available sentinel values for args are:

<<KEY>>: A json encoded list of the Items for a Batch. If the per_item flag is set

this will simply be the key of an Item.

<<EXTRA_DATA>>: A JSON encoded mapping from Item key to that Item’s extra_data. If the

per_item flag is set, this will simply be a JSON encoding of the Item’s extra_data. If extra_data is not present for an item, it is treated as an empty Dict.

<<METADATA>>: A JSON encoded version of the Batch’s metadata.

_FILE can be appended to any of these (i.e. <<KEY_FILE>>) and the arg will instead be replaced

with a path to a file containing the value.

script

The script to run.

Type

str

args

The arguments to supply to the script.

Type

List[str]

timeout

The timeout to use for the script process.

Type

int

per_item

Whether to run the script on each item. Defaults to False.

Type

bool, optional

name

The name of the Component.

Type

ClassVar[TransformerName]

args: List[str]
name: ClassVar[TransformerName] = 'script'
per_item: bool
script: str
timeout: int
transform(batch: Batch) None

Runs the script transformation against the Batch, either on each item individually or on the entire Batch, based on the per_item flag.

Parameters

batch (Batch) – The Batch being transformed.