FME Server Python 2.x compability checker

Are you currently using FME Server 2021.x or older and want to upgrade to 2022.X? If so, you need to check which workspaces has Python compatibility set to 2.X, since Python 2.x was deprecated in FME 2022. This is easily done using the FME Server REST API.

Step 1: Log in to FME server and go to your REST API page by clicking the question mark in the upper right corner on the Home page and then REST API

Ingen alternativ text angiven för den här bilden

Step 2: Generate a token by clicking the Get Token button in the upper right corner, then copy the token string generated in the white box

Ingen alternativ text angiven för den här bilden

Step 3: Modify the following script, set {FMESERVERURL} to your FME Server URL and {TOKENSTRING} to the token string generated in step 2

import requests
import json
import re


"""This script was originally created by Martin Ekstrand (https://se.linkedin.com/in/ekstrandmartin)
It will loop all items in your FME server and check if python compability is set to 2.x"""


"""System variables"""
"""The URL to your fme server rest API"""
fme_server_url = r"https://{FMESERVERURL}/fmerest/v3/"


"""Create a temporary token in your REST API via the get token button"""
token = "fmetoken token={TOKENSTRING}" 
headers = {}


url = fme_server_url + "repositories?limit=-1&offset=-1"
accept = r"application/json"
content_type = r"application/json"
headers['Accept'] = accept
headers['Authorization'] = token
headers['Content-Type'] = content_type
payload = json.dumps({})
response = requests.request("GET", url, headers=headers, data=payload)
repositories = response.json().get("items")
for rep in repositories:
  repository = rep["name"]
  url = fme_server_url + r"repositories/" + repository + r"/items"
  response = requests.request("GET", url, headers=headers, data=payload)
  items = repositories = response.json().get("items")
  for item in items:
    item_name = item["name"]
    accept = r"application/octet-stream"
    headers['Accept'] = accept
    url = fme_server_url + r"repositories/" + repository + r"/items/" + item_name
    response = requests.request("GET", url, headers=headers, data=payload)
    x = re.search(r'PYTHON_COMPATIBILITY="2.*"', response.text)
    if x is not None:
        print(f"{repository}/{item_name} has {x.group(0)}")        

Step 4: Run the script in any IDE (If you're an ArcGIS user you can run it in IDLE)

It will print a list of all your workspaces that's using Python compatibility 2.X.

It would be great if the FME workspace reader included the python compatibility settings, I had to read the workspace as text and use regex to report on that when I set up a workspace to do some workspace checking.

Will FME 2022.x also lose support for ESRI Python 2.7 ?

Like
Reply

Very nice! However I have a workspace that i know contains python 2.7 but it doesn't appear in the output list from the script. I tried the rest api manually on that particular workspace and there is no python compatibility on it. How can this be? The workspace uses a PythonCreator transformer and it says Python compatibility Esri ArcGIS Python 2.7 in the workspace parameters.

Great work! Thanks a lot for your contribution to the event. Very appreciated.

IMPORTANT NOTE: I just realized that if you have a TON of workspaces and the script runs for more than an hour, you will need to create a token manually, since the temporary token expires after 60 minutes.

To view or add a comment, sign in

More articles by Martin Ekstrand

Others also viewed

Explore content categories