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 older versions of FME (prior to FME 2010) neither embed Python, nor ship 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)
  • Python 2.6 (http://www.python.org/download/releases/2.6) (support added in FME 2010)

Of the supported versions, FME 2007 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 or environment variable can be used to choose a specific version.

FME 2008 and 2009 prefer Python version is 2.5. FME 2010 prefers Python version 2.6.

NOTE that later FME 2011 betas (build 6369 and newer) will always attempt to use its embedded Python (2.7) installation first unless the FME_PYTHON_VERSION directive or environment variable exists. The value of this directive/environment variable is the version number of Python to use (2.5, 2.6, etc.). When this is specified, FME will attempt to load that version of Python from the search path, failing if it cannot be found.

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:

  1. It allows Python developers to create Python applications that embed FME technology
  2. 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

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).

User Comments Add a new comment