Syntax FACTORY_DEF PythonFactory [FACTORY_NAME ] [PY_INPUT_TAGS []*] [INPUT FEATURE_TYPE [ ]* []*]* SYMBOL_NAME [SOURCE_CODE ] [PY_OUTPUT_TAGS []*] [OUTPUT FEATURE_TYPE [ ]* []*]* Overview The PythonFactory is an FME Factory whose functionality is implemented using the Python language. A PythonFactory is implemented using a python object that is specified by some symbol name. The symbol name must be fully qualified, and reference a valid Python object. Python Implementation Objects Three types of objects can be used to implement the factory: Python Classes Python Functions Python Instance Objects Python Class Implementation Either new-style or old style classes can be used to implement the factory. When a class object is used to implement the factory, the PythonFactory will create an instance of the class at runtime. The PythonFactory protocol is used to receive features from FME. PythonFactory Protocol Methods input_from(self,feature,input_tag) Allows the implementation class to receive input features from FME. This method is only required if the factory needs to handle input features from a named input tag. This method is called if the PY_INPUT_TAGS clause is specified. Otherwise, the input method is called instead. The feature parameter is an object of type fmeobjects.FMEFeature. Refer to the FME Objects API documentation for more information. This parameter is not an in/out parameter, i.e. any changes to the feature will be lost unless the feature is output using the self.pyoutput method. The input_tag parameter is a string referring to the input tag that feature came from. Introduced in FME 2024.0. input(self,feature) Allows the implementation class to receive input features from FME. This method is only required if the factory needs to handle input features. This method is called if the PY_INPUT_TAGS clause is not specified. Otherwise, the input_from method is called instead. The feature parameter is an object of type fmeobjects.FMEFeature. Refer to the FME Objects API documentation for more information. This parameter is not an in/out parameter, i.e. any changes to the feature will be lost unless the feature is output using the self.pyoutput method. close(self) Called when the factory receives the "allDone" signal from FME, which indicates that the factory will not receive any further features. Bridge to FME Each implementation class can send features "over the bridge" to FME using the pyoutput method. The pyoutput(self,feature,output_tag) method will be dynamically added to the instantiated class at runtime. Factory Styles Python Class implementations support implementation of the following factory styles. Single Input-Single Output The class defines an input method which processes each feature and immediately sends it back to FME via the self.pyoutput method. The class does not need to implement a close method. Single/Multiple Output Generator classes receive no input from FME, and therefore do not need to implement the input method. The class implements a 'close' method that generates multiple new features that are output using the self.pyoutput method. Single/Multiple Input Single/Multiple Output A combination of the previous two styles, this class can take one or more input features, and output. Python Function Implementation Python Functions can be used to implement factories that perform very simple operations on one feature at a time. The functionality provided is very similar to @Python. Functions implementing the factory must have a single parameter: an in/out feature parameter. Note: In contrast to the input method on class implementations, the feature parameter on function parameters is in/out; the feature object parameter is always returned back to FME as factory output. Python Object Implementation Python Object implementation is a slightly more complex variation on Class implementations. This manner of implementation allows the same class to be reused with slightly different initialization of the class. For example, a factory class that interacts with a Web Service may require the class to be initialized with user credentials prior to use. Clauses SYMBOL_NAME The fully-qualified name of a Python Function, Class, or Object that implements the factory. SOURCE_CODE Python source code that is encoded as described in Substituting Strings in Mapping Files, in the FME Fundamentals manual. For internal FME use by the PythonCaller. PY_INPUT_TAGS Optional: Input tags recognized by the PythonFactory. These should be equivalent to the tags listed under a transformer's INPUT_TAGS. Added in FME 2024.0. If this clause is defined, the input_from method will be called instead of the input method. Defining this clause with only will result in the input method being called. PY_OUTPUT_TAGS Optional: Output tags recognized by the PythonFactory. These should be equivalent to the tags listed under a transformer's OUTPUT_TAGS. Added in FME 2024.0. If multiple output tags are listed, the pyoutput method should be called with an output_tag argument. If no output_tag argument is specified, the pyoutput method will default to the PYOUTPUT output tag, if it exists. Input Tags The PythonFactory supports all input tags listed in the PY_INPUT_TAGS clause. If the PY_INPUT_TAGS clause is not specified, then the transformer's INPUT_TAGS must be specified as . Output Tags The PythonFactory supports all output tags listed in the PY_OUTPUT_TAGS clause. Prior to FME 2024.0, the PythonFactory only supported the following: PYOUTPUT Features passed to FME via the pyoutput method. If the PY_OUTPUT_TAGS clause is not specified, only PYOUTPUT is supported.