PythonCreator

Creates features with a user-supplied Python script.

Jump to Configuration

Typical Uses

  • Reading unsupported formats
  • Prototyping Python format plugins
  • Tasks where a transformer is not available

How does it work?

The PythonCreator creates features using the Python script supplied, and sends them into the workspace for processing.

The Python script must be in the form of a Python class. The features can be created either in the input() or close() methods.

Features created in the input() method are created before the first reader is processed. Features created in the close() method are created after all reader features have been processed.

Features are created via the FME Objects Python API.

Note: Python is a programming language external to FME. For documentation on creating Python scripts, visit The Python Foundation.

Using Python to perform arbitrary operations on features is a powerful aspect of Workbench. However, the logic introduced into a workspace is less visible and can therefore be more difficult to maintain than logic built using Workbench’s built-in transformers. It is recommended that other transformers be used when possible instead of Python scripts.

Example Class

The example below creates a random number of features, between 0 and 9.

import fmeobjects
import random
 
class FeatureCreator(object):
def __init__(self):
self.number = random.random()
 
def input(self, feature):
for i in range(1, int(self.number*10)):
feature = fmeobjects.FMEFeature()
feature.setAttribute("feature_count", i)
self.pyoutput(feature)

Script Editing

A PythonCreator transformer can call scripts stored in the transformer itself or stored globally for the entire workspace:

  • To store a Python script with a specific PythonCreator transformer, use the “Python Script” property of the transformer.
  • To store a Python script globally, click the Advanced Workspace Parameter in the Navigator, and double-click Startup Python Script. Storing scripts globally has the advantage of keeping your Python logic centralized, which makes editing and maintenance easier. This is useful if you want to have multiple PythonCreator transformers throughout your workspace that use the same script. For more information, see Startup and Shutdown Python Scripts in the FME Workbench help.

If you are using extensive Python libraries that you do not want to store inside a workspace: to avoid duplication, you can access .py files on the file system using Python’s import command. In addition to the standard Python module locations, FME will also search the location of the workspace for an imported Python module.

Configuration

Input Ports

None

Output Ports

Parameters

Editing Transformer Parameters

Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.

Defining Values

There are several ways to define a value for use in a Transformer. The simplest is to simply type in a value or string, which can include functions of various types such as attribute references, math and string functions, and workspace parameters. There are a number of tools and shortcuts that can assist in constructing values, generally available from the drop-down context menu adjacent to the value field.

Dialog Options - Tables

Transformers with table-style parameters have additional tools for populating and manipulating values.

Reference

Processing Behavior

Feature-Based or Group-Based, conditional on Python script

Feature Holding

Conditional on Python script

Dependencies
FME Licensing Level FME Base Edition and above
Aliases  
History  

FME Community

The FME Community is the place for demos, how-tos, articles, FAQs, and more. Get answers to your questions, learn from other users, and suggest, vote, and comment on new features.

Search for all results about the PythonCreator on the FME Community.

 

Examples may contain information licensed under the Open Government Licence – Vancouver