FME Python module reference
This is the reference documentation for the functions and classes defined in the fme
module.
Functions
- resolveFMEMacros(value: str) str
Resolve all FME macros in the input string and return the resolved string. FME macros are defined as all character sequences that match the pattern $(<alphanumeric characters including ‘_’>). If a matching pattern does not resolve to an FME macro, the matching pattern will remain untouched.
- Parameters:
value – The input string value to resolve.
- Returns:
The input string value with resolved FME macros.
- getAbsolutePath(file_name: str) str
Given an input file name or FME macro of a file name, this method will return an absolute path of the file name. Unless the resolved input file name is an absolute path itself, the absolute path will be determined with the assumption that the input is relative to the executing Workspace.
- Parameters:
file_name – The input file name or FME macro of a file name.
- Returns:
An absolute path of the input file name or FME macro of a file name.
Classes
- class BaseTransformer
Introduced in FME 2024.2. A base class that represents the interface expected by the FME infrastructure for Python-based transformer implementations. In particular, this is the class-based API required by the PythonFactory:
FACTORY_DEF {*} PythonFactory FACTORY_NAME { $(XFORMER_NAME) } INPUT { FEATURE_TYPE $(XFORMER_NAME)_READY } SYMBOL_NAME my_library.my_module.TransformerImpl OUTPUT { PYOUTPUT FEATURE_TYPE $(XFORMER_NAME)_PROCESSED }
When executed by FME, this is approximately equivalent to:
from my_library.my_module import TransformerImpl transformer = TransformerImpl()
PythonFactory does not require Python classes to inherit from this base class, but it expects them to have the same interface as this class.
This class can be used as a context manager to guarantee that
close()
is called. This is useful for writing tests.See also
PythonFactory in the FME Factory and Function Documentation.
- __init__()
FME instantiates this class, so it must not require any constructor arguments.
- close() None
Called at the end of translation. Override this method to perform any necessary cleanup or finalization operations.
pyoutput()
may be called from this method.
- factory_name: str
This is the
FACTORY_NAME
parameter of the PythonFactory that instantiated this class. Defaults to the name of this class.Note
Do not modify this property. FME sets the value at runtime.
- get_group_fields() List[str]
Added in version 2024.2.
Note
Do not implement this method. FME injects the implementation at runtime.
- Returns:
A list of group-by attribute names, or an empty list if no group-by attributes are set.
- has_support_for(support_type: int) bool
Added in version 2022.0: This method and its corresponding constants in
fmeobjects
.This method is used by FME to check whether the transformer claims support for certain capabilities. Currently, the only supported type is
fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM
, which determines support for Bulk Mode.Why support Bulk Mode
When a transformer supports Bulk Mode, FME may pass features to
input()
that come from a feature table object. This allows significant performance gains when processing many features, but requires the transformer to follow certain rules around how it handles features.How to support Bulk Mode
Features received by
input()
must not be copied or cached for later use.Features received by
input()
must not be read or modified after being passed topyoutput()
.pyoutput()
should not be given newFMEFeature
instances. Doing so will automatically downgrade feature processing to individual mode.Override this method. When
support_type
isfmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM
, returnTrue
.
Violating these requirements may result in undefined behavior.
Illegal Examples
Copy and access later:
def input(self, feature): self._cached_features.append(feature) def close(self): for feature in self._cached_features: # not allowed self.pyoutput(feature)
Access after output:
def input(self, feature): self.pyoutput(feature) feature.setAttribute("attr name", "attr val") # not allowed
Group-by processing:
def input(self, feature): self._cached_features.append(feature) def process_group(self): for feature in self._cached_features: # not allowed self.pyoutput(feature)
- Parameters:
support_type – The type of support to check for. Currently, the only supported type is
fmeobjects.FME_SUPPORT_FEATURE_TABLE_SHIM
.- Returns:
True
if the passed in support type is supported. The default implementation returnsFalse
.
- input(feature: FMEFeature) None
Receive a feature from the transformer’s single input port.
This method is used instead of
input_from()
if the transformer has no input tags, meaning that the transformer’s INPUT_TAGS parameter is listed as <BLANK>.Transformers typically receive a feature through this method, process it, modify the feature by adding output attributes, and then output the feature using
pyoutput()
. However, transformers may output any number of features for each input feature, or none at all. Transformers may also create newFMEFeature
instances and output them.- Parameters:
feature – The feature to process.
- input_from(feature: FMEFeature, input_tag: str) None
Receive a feature from input_tag.
This method is used instead of
input()
if the transformer has defined input tags listed in the transformer’s INPUT_TAGS parameter and the PythonFactory’s PY_INPUT_TAGS clause. Introduced in FME 2024.0.Example of a
PythonFactory
definition with two input tags:FACTORY_DEF {*} PythonFactory FACTORY_NAME { $(XFORMER_NAME) } PY_INPUT_TAGS { INPUT0 INPUT1 } $(INPUT_LINES) SYMBOL_NAME { symbol_name } PY_OUTPUT_TAGS { Output <Rejected> } OUTPUT { Output FEATURE_TYPE $(OUTPUT_Output_FTYPE) $(OUTPUT_Output_FUNCS) } OUTPUT { <Rejected> FEATURE_TYPE $(OUTPUT_<Rejected>_FTYPE) $(OUTPUT_<Rejected>_FUNCS) }
Transformers typically receive a feature through this method, process it, modify the feature by adding output attributes, and then output the feature using
pyoutput()
. However, transformers may output any number of features for each input feature, or none at all. Transformers may also create newFMEFeature
instances and output them.- Parameters:
feature – The feature to process.
input_tag – The input tag that feature came from.
- process_group() None
If group processing is enabled, then this is called after all the current group’s features have been sent to
input()
. Can be left unimplemented if group processing is not supported.pyoutput()
may be called from this method.
- pyoutput(feature: FMEFeature, output_tag: str | None = None) None
Output a feature from the transformer to an output tag. If an output tag is specified and does not exist on the PythonFactory, an error will be raised.
Note
Do not implement this method. FME injects the implementation at runtime.
- Parameters:
feature – The feature to output.
output_tag – The output tag to direct feature to. If multiple output tags exist but this argument is not specified,
PYOUTPUT
will be used as a fallback value. If the PythonFactory definition has a single output tag, this tag will be the default. Introduced in FME 2024.0.