Skip to content

Developer Usage

John Bradley edited this page Jul 12, 2019 · 6 revisions

Setup

Install DukeDSClient and setup your config file

Usage

import DukeDS

# Fetch list of all project names
project_names = DukeDS.list_projects()
for project_name in project_names:
    print project_name

# Create a project named 'mouse' with description 'Mouse research'
DukeDS.create_project('mouse', 'Mouse research')

# List files in project 'mouse'
remote_file_paths = DukeDS.list_files('mouse')
for remote_file_path in remote_file_paths:
    print remote_file_path

# Download the file at remote path '/results/data1.bam' in project 'mouse'
# to 'data1.bam' in the current directory
DukeDS.download_file('mouse', '/results/data1.bam')

# Download the file at remote path '/results/data1.bam' in project 'mouse' 
# to '/tmp/data1.bam'
DukeDS.download_file('mouse', '/results/data1.bam', '/tmp/data1.bam')

# Upload a file from '/tmp/data2.bam' into project 'mouse' 
# at remote path 'data2.bam'
DukeDS.upload_file('mouse', '/tmp/data2.bam)

# Upload a file from '/tmp/data2.bam' into project 'mouse' 
# at remote path '/results2/data2.bam'
DukeDS.upload_file('mouse', '/tmp/data2.bam, '/results2/data2.bam')

# Delete the remote file '/results2/data2.bam' in project 'mouse'
DukeDS.delete_file('mouse', '/results2/data2.bam')

# delete the project named 'mouse'
DukeDS.delete_project('mouse')

Advanced Options

Users working with large numbers of files can use a Session object instead of DukeDS.

This object caches some data to speed up successive operations.

from ddsc.sdk.dukeds import Session
session = Session()

# Fetch list of all project names
project_names = session.list_projects()
for project_name in project_names:
    print project_name

...

There is also a ddsc.sdk.client.Client object that provides an object oriented interface for working with the DukeDS API.