Question

Python FME Server Rest API Wrapper

  • 25 October 2018
  • 5 replies
  • 11 views

Badge

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


5 replies

Userlevel 5

Fantastic initiative, thanks for sharing!

Badge

Fantastic initiative, thanks for sharing!

Thanks man!

 

 

Userlevel 4
Badge +26
Fantastic. I've shared it with my colleagues in Safe because I'm sure they will be interested. Thanks for sharing.

 

 

Badge +5

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

Badge

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

 

 

Reply