Python on FME Server

From fmepedia

fme_server_related_content.png (http://fmepedia.com/index.php/Category:FME_Server)

How do I import an external Python module in FME Server

If you have a python module you need to use on FME Server which is not part of the Python standard library, you will need to get the module on the server. There are two ways to do this:

1. Add the module to the site-packages on the server

This is the easiest method. You simply copy the module to the site-packages directory (usually C:\Python2x\Lib\site-packages) and use a standard import <module> command. This method is very easy, but requires access to the site-packages directory on your server.

2. Upload the module to the server

If you do not have access to the site-packages directory on the server, you can upload the module to the server using the following steps:

  • 1. Add an AttributeFileWriter to your workspace. Select the file you need to upload, but do not connect the transformer to anything. We don't actually want to use this transformer, we are simply using it as a simple way to tell Workbench about the file we need so we will be prompted to upload it to the server.
  • 2. Add the following lines to the beginning of your script:
   import pyfme
   MF_DIR=pyfme.FME_MacroValues['FME_MF_DIR']
   sys.path.append(MF_DIR)

This is required, as on FME Server, the working directory for a python script is not the same as the working directory for a workspace, like in Workbench. This will get the working directory for your workspace, which is also the location where the script will be uploaded, and add it the python path so the script can find your module.

  • 3. Publish the workspace to the server. Make sure you upload the file to the server when publishing.

My Python script needs to access a file

If your Python script needs to access a file, you can upload it to the server with your workspace. You may need to follow a similar procedure to the one outlined above to force workbench to allow you to upload the file. You will also need to modify your script by adding the following lines to which will always point to the path where uploaded file are stored on the server:

  import pyfme
  path=pyfme.FME_MacroValues['FME_MF_DIR']

Now you can reference your file as path/file. This is required because the working directory for python scripts is not the same as the working directory for workspaces on FME Server.

Please see attached workspace (http://www.fmepedia.com/attachments//Python_on_FME_Server/fmeserverPython.zip) for an example of this technique.

Attached Files
filesizedate
board------
board.php------
delete_all.php------
errors.php------
fmeserverPython.zip3.1 kB03/06/09
index.php------
kboard.php------
modify.php------
User Comments Add a new comment