Creates features with a user-supplied Python script.
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.
The supplied script contains a class called FeatureCreator, which inherits from fme.BaseTransformer. This is a base class that represents the interface expected by the FME infrastructure. See the FME Python module documentation for more information.
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.
Using Python to perform arbitrary operations on features is a powerful aspect of FME Workbench. However, the logic introduced into a workspace is less visible and can therefore be more difficult to maintain than logic built using FME Workbench’s built-in transformers. It is recommended that other transformers be used when possible instead of Python scripts.
The example below creates a random number of features, between 0 and 9.
A PythonCreator transformer can call scripts stored in the transformer itself or stored globally for the entire workspace:
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.
None
Features created by the Python script.
|
Class to Process Features |
The name of the Python Class within the script that PythonCreator will use to begin execution. For the above example, set this parameter to FeatureCreator. |
|
Python Script |
This is the Python script to be executed. If the Python script is stored as the Startup Python Script for the workspace (as described above in Script Editing) you can leave this parameter blank. |
|
Attributes to Expose |
Exposes attributes so they can be used elsewhere in the workspace. Attribute names may be entered directly or provided in the Enter Values for Attributes to Expose dialog accessed via the ellipsis button, where data type may also be specified. For more information on exposed and unexposed attributes, see Understanding Feature Types and Attributes. Used to expose any attributes that are created by the Python script being executed so they can be used by other transformers. |
Transformer parameters can be set by directly entering values, using expressions, or referencing other elements in the workspace such as attribute values or user parameters. Various editors and context menus are available to assist. To see what is available, click
beside the applicable parameter.
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.
The Text Editor provides a convenient way to construct text strings (including regular expressions) from various data sources, such as attributes, parameters, and constants, where the result is used directly inside a parameter.
The Arithmetic Editor provides a convenient way to construct math expressions from various data sources, such as attributes, parameters, and feature functions, where the result is used directly inside a parameter.
Set values depending on one or more test conditions that either pass or fail.
Parameter Condition Definition Dialog
Expressions and strings can include a number of functions, characters, parameters, and more.
When setting values - whether entered directly in a parameter or constructed using one of the editors - strings and expressions containing String, Math, Date/Time or FME Feature Functions will have those functions evaluated. Therefore, the names of these functions (in the form @<function_name>) should not be used as literal string values.
| These functions manipulate and format strings. | |
|
Special Characters |
A set of control characters is available in the Text Editor. |
| Math functions are available in both editors. | |
| Date/Time Functions | Date and time functions are available in the Text Editor. |
| These operators are available in the Arithmetic Editor. | |
| These return primarily feature-specific values. | |
| FME and workspace-specific parameters may be used. | |
| Creating and Modifying User Parameters | Create your own editable parameters. |
Transformers with table-style parameters have additional tools for populating and manipulating values.
|
Row Reordering
|
Enabled once you have clicked on a row item. Choices include:
|
|
Cut, Copy, and Paste
|
Enabled once you have clicked on a row item. Choices include:
Cut, copy, and paste may be used within a transformer, or between transformers. |
|
Filter
|
Start typing a string, and the matrix will only display rows matching those characters. Searches all columns. This only affects the display of attributes within the transformer - it does not alter which attributes are output. |
|
Import
|
Import populates the table with a set of new attributes read from a dataset. Specific application varies between transformers. |
|
Reset/Refresh
|
Generally resets the table to its initial state, and may provide additional options to remove invalid entries. Behavior varies between transformers. |
Note: Not all tools are available in all transformers.
For more information, see Transformer Parameter Menu Options.
|
Processing Behavior |
Feature-Based or Group-Based, conditional on Python script |
|
Feature Holding |
Conditional on Python script |
| Dependencies |
An FME installation includes a Python version 3.13 interpreter. The FME Objects Python API supports Python 3.9 - 3.13. The Python interpreter used by FME to execute Python scripts is controlled by the Python Compatibility workspace parameter . FME will load the latest available Python interpreter matching that parameter. For more information, see FME Workbench help. If you would like to install a third-party package for use by Python in FME, see Installing Python Packages to FME Form in FME Workbench help. |
| Aliases | |
| History |
The FME Community has a wealth of FME knowledge with over 20,000 active members worldwide. Get help with FME, share knowledge, and connect with users globally.
Search for all results about the PythonCreator on the FME Community.
Examples may contain information licensed under the Open Government Licence – Vancouver, Open Government Licence - British Columbia, and/or Open Government Licence – Canada.