At LabKey, I regularly use Python to create tools for managing the servers we use. I often use the LabKey Server Python API to interact with the LabKey Servers we are running. However, in a few instances I have been forced to write code to interact with a LabKey Server in ways not yet supported by the Python API.

Eventually this code might be included in the Python API, but until that happens I decided to share a few examples of what can be done.

upload_file.py:

  • This script shows you how to upload a file from your workstation to the FileRoot of a Folder on your LabKey Server
  • How do I use this functionality?
    • LabKey uses AWS Spot Instances when running the servers used to test LabKey Server. These Spot Instances are started using a Python script which tracks each request in a log file. To make cost accounting easier, each start/stop of a Spot Instance is tracked in a List. When the script finishes the log file is uploaded to the FileRoot of the Folder containing the List and the URL of the uploaded file is included in the List record.

download_study_archive.py:

  • This script shows you how to create a Study Archive and download the resulting Archive (in the form of a ZIP file) to your workstation.
  • How do I use this functionality?
    • I use a similar script to periodically move Study data from one LabKey Server to a second LabKey Server.

These scripts are available in LabKey’s Samples repository at Github. This repository is used by LabKey to share tools/scripts with the LabKey Server community. It currently contains scripts for the install and upgrade of a LabKey Server and the python scripts described above. Keep an eye on it for additional scripts that are coming soon.