fmetools.paramparsing
This module provides TransformerParameterParser
,
the recommended way to access transformer parameter values.
Warning
This module requires:
FME Form 2023 b23224 or newer
FME Flow 2024 b24145 or newer
Packages using this module and targeting both FME Form and FME Flow
should set minimum_fme_build
in its package.yml accordingly.
- class fmetools.paramparsing.TransformerParameterParser(transformer_name: str, version: int | None = None)
Bases:
object
Helper for getting parsed transformer parameter values.
Warning
Instantiating this class on FME Flow requires FME Flow b24145 or newer. Instantiating the class on older versions of FME Flow will raise an exception.
All parameters of Python transformers are set as attributes on input features. By convention, these attributes are given a prefix to give it a namespace and signify that they are internal attributes. The values of these attributes are string serializations that need to be deserialized before use.
This class works by loading a transformer definition from FME, passing it serialized parameter values from an input feature or other source, and then requesting deserialized values back. FME uses the transformer definition to determine how to deserialize the values.
A typical workflow with this class involves:
Instantiate this class as an instance member of the class that implements the transformer.
When the transformer receives its first input feature:
If the caller needs a particular transformer version, it may call
change_version()
.set_all()
is called to provide all initial serialized parameter values from the input feature.get()
is called to get the deserialized values for the parameters of interest. If these parameter values don’t change between features, the caller caches them to avoid unnecessary work.
For subsequent input features,
set()
andget()
are called as necessary to handle the values of parameters that change between features, if any.
- __init__(transformer_name: str, version: int | None = None)
- Parameters:
transformer_name –
Fully-qualified name of the transformer. For example,
my_publisher.my_package.MyTransformer
. Note that this is the name of the transformer in FME, not the name of the Python class that implements it.The transformer may be defined in the FMX and FMXJ formats.
version – Transformer version to load. If not provided, then the latest version is loaded.
- Raises:
ValueError – If FME cannot find the specified transformer.
- change_version(version: int | None = None)
Change to a different version of the transformer definition. This clears state, so serialized parameter values need to be set again before their parsed values can be retrieved.
- Parameters:
version – Transformer version to load. If not specified, then the latest version is loaded.
- get(name: str, prefix: str | None = '___XF_') Any
Get a parsed (deserialized) parameter value. For convenience, this assumes a prefix for the given parameter name. If the parameter value was not set on the transformer, then the default value is returned, if any.
- Parameters:
name – Name of the parameter.
prefix – Prefix of the parameter. Specify
None
for unprefixed attributes or if the given name already includes the prefix. The default is the prefix used by the FME SDK Guide examples.
- Raises:
ValueError – When the value of the parameter cannot be deserialized according to the type expected by the transformer definition.
TypeError – When the parameter value type is not supported.
KeyError – When the parameter name is not recognized.
- is_required(name: str) bool
- Parameters:
name – Parameter name.
- Returns:
Whether the parameter is required according to the transformer definition. If the parameter is disabled, this returns
False
.
- set(name: str, value: Any) bool
Supply the serialized value of a parameter. Its deserialized version can then be retrieved using
get()
.- Parameters:
name – Parameter name to set.
value – Parameter value to set.
- set_all(src: fmeobjects.FMEFeature | dict[str, Any], *, param_attr_prefix: str = '___XF_', param_attr_names: Iterable[str] | None = None) bool
Supply all serialized parameter values. This is the typical way to input parameter values before calling
get()
to obtain their deserialized values.It is important to set all parameter values before calling
get()
, because of dependent parameters that may change or disable the requested parameter.- Parameters:
src –
Source of the serialized transformer parameter values.
fmeobjects.FMEFeature
: Use the attributes on this feature.dict
: A mapping of parameter names to serialized values.
param_attr_prefix – Prefix for the internal attributes of transformer parameters. The default is the prefix used by the FME SDK Guide examples. Only used when
src
is a feature.param_attr_names – Internal attribute names of transformer parameters. Only used when
src
is a feature. If provided, then these attributes are obtained from the feature and added to the set of attributes obtained by prefix.