Birdy WPSClient example with Emu WPS


In [ ]:
from birdy import WPSClient

In [ ]:
emu = WPSClient(url='http://localhost:5000/wps')
emu_i = WPSClient(url='http://localhost:5000/wps', progress=True)

Get Infos about hello


In [ ]:
emu.hello?

Run hello


In [ ]:
emu.hello(name='Birdy').get()[0]

Run a long running process


In [ ]:
result = emu_i.sleep(delay='1.0')

In [ ]:
result.get()[0]

Run a process returning a reference to a text document


In [ ]:
emu.chomsky(times='5').get()[0]

Pass a local file to a remote process

The client can look up local files on this machine and embed their content in the WPS request to the server. Just set the path to the file or an opened file-like object.


In [ ]:
fn = '/tmp/text.txt'
with open(fn, 'w') as f:
    f.write('Just an example')
emu.wordcounter(text=fn).get(asobj=True)

Automatically convert the output to a Python object

The client is able to convert input objects into strings to create requests, and also convert output strings into python objects. This can be demonstrated with the inout process, which simply takes a variety of LiteralInputs of different data types and directs them to the output without any change.


In [ ]:
emu.inout?

In [ ]:
import datetime as dt
result = emu.inout(string='test', int=1, float=5.6, boolean=True, time='15:45', datetime=dt.datetime(2018, 12, 12), text=None, dataset=None)

Get result as object


In [ ]:
result.get(asobj=True).text

Example with multiple_outputs

Similarly, the multiple_outputs function returns a text/plain file. The converter will automatically convert the text file into a string.


In [ ]:
out = emu.multiple_outputs(1).get(asobj=True)[0]
print(out)

... or use the metalink library on the referenced metalink file:


In [ ]:
out = emu.multiple_outputs(1).get(asobj=False)[0]
print(out)

In [ ]:
from metalink import download
download.get(out, path='/tmp', segmented=False)