## Labkey Python interface ## A Python3 urllib3 based interface for communication with the LabKey server. Update over official LabKey version is the use of client certificates to access potentially sensitive sites. ### Setup ### Update `network-config-sample.json` with personal information needed to access the site (certificates, keys, username and password) When using labkeyInterface, use the updated file as input to labkeyInterface constructor, ie ```python import labkeyInterface net=labkeyInterface.labkeyInterface() net.init('/path/to/network-config.json') ``` ### Use ### `getFile.py` illustrates use to connect to site, collect image and perform image analysis. Typically one would do: ```python #net created as above import labkeyDatabaseBrowser db=labkeyDatabaseBrowser.labkeyDB(net) import labkeyFileBrowser fb=labkeyFileBrowser.labkeyFileBrowser(net) #project='path/to/project/on/Labkey' #schema='study' #query='queryName' ds=db.selectRows(project,schema,query,[]) for r in ds['rows']: #r is a dictionary with variables named after column names in labkey #for statistics etc. work with variables directly #for files, figure out where files are stored #typically starting with project, #- a potential subdirectory, #- a set of directories determined from fields in r #- a file name from specific field in r subdir='preprocessedImages' pathList=[subdir,r['ParticipantId'],r['visitId'],r['fileName']] path='/'.join(pathList) remotePath=fb.formatPathURL(project,path) #where to copy file to, adjust if neccesary localPath=os.path.join(os.path.expanduser('~'),'temp',r['fileName']) fb.readFileToFile(remotePath,localPath) #do something with file #end loop print('Done') ``` One can use row data to navigate list of files and/or do statistical analysis of data. ### Generate private key without password To connect, a key without password is needed for compliance with `urllib3`. Generate it with: ```shell openssl rsa -in [file1.key] -out [file2.key] ```