Python Library

COVID Cloud provides a Python client library called covid_cloud. This can be used to interact with COVID Cloud using Python scripts and Jupyter Notebook.

Installation

The library can be installed using pip.

1
pip install covid_cloud

Usage

Access Tables and Schemas
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Import the covid_cloud library
from covid_cloud import COVIDCloud

# Create the client
search_url = 'https://search.international.covidcloud.ca/'
covid_cloud = COVIDCloud(search_url=search_url)

# Get a JSON-formatted list of all tables
tables = covid_cloud.list_tables()

# Get the schema for a single table   
table_name = 'covid.cloud.sequences'
schema = covid_cloud.get_table(table_name)

Execute Queries
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Import the covid_cloud library
from covid_cloud import COVIDCloud

# Create the client
search_url = 'https://search.international.covidcloud.ca/'
covid_cloud = COVIDCloud(search_url=search_url)

# Execute a query
query = 'SELECT * FROM covid.cloud.sequences LIMIT 20'
data = covid_cloud.query(query)

Load Data from DRS
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Import the covid_cloud library
from covid_cloud import COVIDCloud

# Create the client
search_url = 'https://search.international.covidcloud.ca/'
covid_cloud = COVIDCloud(search_url=search_url)


# Load a DRS resource
resource_url = "drs://drs.international.covidcloud.ca/f5ff16d5-6be8-425c-acb5-8edbf023db52"
data = covid_cloud.load([resource_url])

Note: For non-assembly files (e.g. .vcf.gz, .vcf.gz.tbi, .sra), binary file data is returned.


Download Files from DRS
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Import the covid_cloud library
from covid_cloud import COVIDCloud

# Create the client
search_url = 'https://search.international.covidcloud.ca/'
covid_cloud = COVIDCloud(search_url=search_url)

# Download a DRS resource
resource_url = "drs://drs.international.covidcloud.ca/f5ff16d5-6be8-425c-acb5-8edbf023db52"
covid_cloud.download([resource_url])

Additional Resources

The CLI implements the GA4GH Search standard for browsing and querying using the ./covid-cloud search command.

Take a look at the GA4GH Search Documentation for a detailed guide on using search commands.