Skip to main content
Question

Python FME Server Rest API Wrapper

  • October 25, 2018
  • 5 replies
  • 72 views

Forum|alt.badge.img

Hey

More of an fyi than a question. Over the past years I’ve had to do a lot of FME Server automation using the fme server rest api. I’ve created an python wrapper to help make fme server automation easier for me. Had this code kicking around for a while but recently found the time to sanitize/share it.

The code for this can be found here:

https://github.com/bcgov/dbc-pylib

There is some getting started docs here:

https://github.com/bcgov/dbc-pylib/blob/master/docs/FMEServer.md

Hoping it will be useful to someone, if so please use! If you are interested in contributing even better. If there are desired features / functionality let me know as well by posting to the issues on the github repo: https://github.com/bcgov/dbc-pylib/issues

Cheers

Kevin

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

david_r
Celebrity
  • October 25, 2018

Fantastic initiative, thanks for sharing!


Forum|alt.badge.img
  • Author
  • October 25, 2018

Fantastic initiative, thanks for sharing!

Thanks man!

 

 


mark2atsafe
Safer
Forum|alt.badge.img+58
  • Safer
  • October 25, 2018
Fantastic. I've shared it with my colleagues in Safe because I'm sure they will be interested. Thanks for sharing.

 

 


rudy_v
Contributor
Forum|alt.badge.img+6
  • Contributor
  • February 24, 2020

Hi @guy_lafleur

I have create a few python api's in python 2.7, using v1, but since 2.7 are no longer more - it is probably time to migrate to 3+ and V3.

So i came across this - and it seems quite good+ to fantastic. What i would like see -is how you build the parameters (body) for v3

for example from rest api - samples

http://your-server-name/fmerest/v3/transformations/transact/Samples/austinDownload.fmw

{ "publishedParameters": [

 

{ "name": "MAXY",

 

"value": "42"

 

},

 

{ "name": "THEMES",

 

"value": ["airports", "cenart" ]

 

}

 

],

 

"TMDirectives": {

 

"rtc": false,

 

"ttc": 60,

 

"description": "This is my description",

 

"tag": "linux",

 

"ttl": 60 },

 

"NMDirectives": {

 

"directives": [

 

{"name": "email_to",

 

"value": "example@safe.com"

 

}

 

], "successTopics": ["SAMPLE_TOPIC" ],

 

"failureTopics": []

 

}

 

}

Rudy


Forum|alt.badge.img
  • Author
  • February 24, 2020

Hi @guy_lafleur

I have create a few python api's in python 2.7, using v1, but since 2.7 are no longer more - it is probably time to migrate to 3+ and V3.

So i came across this - and it seems quite good+ to fantastic. What i would like see -is how you build the parameters (body) for v3

for example from rest api - samples

http://your-server-name/fmerest/v3/transformations/transact/Samples/austinDownload.fmw

{ "publishedParameters": [

 

{ "name": "MAXY",

 

"value": "42"

 

},

 

{ "name": "THEMES",

 

"value": ["airports", "cenart" ]

 

}

 

],

 

"TMDirectives": {

 

"rtc": false,

 

"ttc": 60,

 

"description": "This is my description",

 

"tag": "linux",

 

"ttl": 60 },

 

"NMDirectives": {

 

"directives": [

 

{"name": "email_to",

 

"value": "example@safe.com"

 

}

 

], "successTopics": ["SAMPLE_TOPIC" ],

 

"failureTopics": []

 

}

 

}

Rudy

Hey Rudy

Currently, to specify all those parameters you would have to create anther method to accomplish that.  The way the wrapper is currently designed it only allows you to override the published parameters.

If you wanted to run the job above and override the published parameters you could do so like this:

import FMEUtil.PyFMEServerV3
import pprint
jobName = r'austinDownload.fmw'
repo = 'Samples'
server = "http://your-server-name"
token = 'yourApiKeyGoesHere'
overridePubParams = {"MAXY": "42",
                     "THEMES": ["airports", "cenart"]
                     }
fmeSrv = FMEUtil.PyFMEServerV3.FMEServer(server, token)
# gets a 'Jobs' object, from which you can get a 'Job' (singular) object
Jobs = fmeSrv.getJobs()
# submit for syncronous execution
resp = Jobs.submitJobSync(repo, jobName, params=overridePubParams)
# pretty printing the response.
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(resp)

 

Hope this helps.  FYI I am hoping to start cleaning up a lot of the code in the github repo (https://github.com/bcgov/dbc-pylib) soon.  Things to be done include:

  • make code pep8 compatible
  • set up automatic build using github actions to create proper pypi packages
  • separate code into different repositories

Cheers

Kevin