Python and FME
From fmepedia
| Table of contents |
Introduction
For almost as long as FME has been available, FME users have had access to the TCL language from within FME. TCL is a powerful language that has provided our users with the ability to accomplish a wide variety of tasks. However, over time, other languages, such as Python, have risen in popularity. In order to provide FME users with flexibility, and choice, Safe has been working over the last several releases to add access to the Python language from within FME.
Preliminaries
The most important thing to understand about FME's Python support, is that FME neither embeds Python, nor ships with a Python interpreter. FME will, however, take advantage of almost any Python interpreter that is also installed on the same machine.
Currently, FME supports the following Python versions:
- Python 2.3 (http://www.python.org/download/releases/2.3) (support fixed in FME 2007)
- Python 2.4 (http://www.python.org/download/releases/2.4)
- Python 2.5 (http://www.python.org/download/releases/2.5) (preliminary support in FME 2007)
Of the supported versions, FME currently prefers Python 2.4. I.e. if Python 2.3 and Python 2.4 are installed on the same machine, FME will use the Python 2.4 installation. The FME_PYTHON_VERSION directive can be used to choose a specific version.
In the FME 2007 timeframe, FME's Python preference may change to prefer 2.5 over 2.4 and 2.3, depending on on general support for Python 2.5
For more information about the Python language, i.e. how to install it, how to learn it, etc, see our python page.
pyfme
pyfme is the Python wrapper module for FME's FME Objects API. In the context of Python and FME, pyfme fills two important roles:
- It allows Python developers to create Python applications that embed FME technology
- It serves as an interface between FME and the scripts used by the @Python function and the PythonFactory.
As such, any FME user who wants to use Python in their FME translations should be familiar with the pyfme module. FME users should pay specific attention to the FMEFeature and FMELogfile classes, which get the most use in the context of @Pythonand the PythonFactory.
See also the pyfme API documentation (http://www.safe.com/support/fmeobjects/docs/pyfme/index.html).
pyfme Attribute Type Handling discusses many of the issues encountered when accessing FME attribute values with pyfme.
Begin/End Python
Begin/End Python scripts allow you to execute python functions at the beginning and end of your FME translation.
@Python
The @Python FME function can be used in conjunction with other FME factories to execute python functions on a per-feature basis.
Originally released as part of FME 2006 GB, @Python provided the foundation for the original version of the PythonCaller transformer.
PythonFactory
The PythonFactory is useful for situations where you want to execute python code on groups of features, or use python scripts to generate features
Workbench & Python
- The PythonCaller and PythonCreator transformers can be used to call python code within the Workbench.
Samples
See our python samples for more information on using Python and FME.
Tutorial
For additional hints please study the pyfme tutorial (http://www.fmepedia.com/index.php/Oliver%27s_Python_Corner).

