In November 2014 we announced the availability of rwslib, a python library which provides helpers to access Rave Web Service (RWS) APIs. That release included Builders for creating CDISC ODM messages for clinical data exchange (e.g. uploading a blood pressure reading or demographic information to Rave EDC). The latest version of rwslib improves on these builders and provides support for our own MAuth authentication scheme via a separate requests-mauth library which we are also releasing as Open Source under a MIT license.

We have been using rwslib in our own projects, notably our MOVE-2014 trial on wearable sensors trial to transfer data into Rave EDC.

For our own proof-of-concept work we needed to create study metadata in Rave EDC (i.e. upload study designs) and we took this as an opportunity to expand the builders available in the library to support CDISC ODM Metadata including Medidata’s own extensions.

A comprehensive example of creating a Rave study draft complete with folders, forms, edit checks, derivations etc can be found in the builders example documentation.

MAuth and requests-mauth

Medidata’s other API’s, such as the iMedidata user and site API use MAuth authentication, a request signing authentication scheme. We are now releasing requests-mauth a python library that makes working with the python requests HTTP library and MAuth a breeze:

import requests
from requests_mauth import MAuth

APP_UUID = '55dc88ec-c109-11e1-84f6-1231381b7d70'
private_key = open("private.key","r").read()

mauth = MAuth(APP_UUID, private_key)

# Call an MAuth protected resource, in this case an iMedidata API 
# listing the studies for a particular user
user_uuid = '10ac3b0e-9fe2-11df-a531-12313900d531'
url = "https://innovate.imedidata.com/api/v2/users/%s/studies.json" % user_uuid

# Make the requests call, passing the auth client
result = requests.get(url, auth=mauth)

# Print results
if result.status_code == 200:
    print([r['uuid'] for r in result.json()['studies']])
print(result.text)

But what if you want to use MAuth with RWS? Normally you need to provide rwslib with the username/password of a Rave user to authenticate using basic authentication. However, Rave can be set up to recognize an MAuth App and signature as being on-behalf-of a Rave user. In the latest version of rwslib you can now pass an MAuth authentication object to a rwslib.RWSConnection object to use MAuth authentication:

from rwslib import RWSConnection
from requests_mauth import MAuth
from rwslib.rws_requests import MetadataStudiesRequest

APP_UUID = '55dc88ec-c109-11e1-84f6-1231381b7d70'
private_key = open("private.key","r").read()

rave = RWSConnection('innovate', auth=MAuth(APP_UUID, private_key))
res = rave.send_request(MetadataStudiesRequest()) # returns ODM string
print res

requests-mauth and the updates to rwslib make Medidata APIs more accessible than ever for python programmers. Good luck with your own integrations!

Analytics