Birdy WPSClient example with Emu WPS

[ ]:
from birdy import WPSClient

Use Emu WPS

https://github.com/bird-house/emu

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

Get Infos about hello

[ ]:
emu.hello?

Run hello

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

Run a long running process

[ ]:
result = emu_i.sleep(delay="1.0")
[ ]:
result.get()[0]

Run a process returning a reference to a text document

[ ]:
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.

[ ]:
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.

[ ]:
emu.inout?
[ ]:
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

[ ]:
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.

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

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

[ ]:
out = emu.multiple_outputs(1).get(asobj=False)[0]
print(out)
[ ]:
from metalink import download

download.get(out, path="/tmp", segmented=False)