copy

walk

synapseutils.walk.walk(syn, synId)

Traverse through the hierarchy of files and folders stored under the synId. Has the same behavior as os.walk()

Parameters
  • syn – A synapse object: syn = synapseclient.login()- Must be logged into synapse

  • synId – A synapse ID of a folder or project

Example:

walkedPath = walk(syn, "syn1234")

for dirpath, dirname, filename in walkedPath:
    print(dirpath)
    print(dirname) #All the folders in the directory path
    print(filename) #All the files in the directory path

sync

monitor

synapseutils.monitor.notifyMe(syn, messageSubject='', retries=0)

Function decorator that notifies you via email whenever an function completes running or there is a failure.

Parameters
  • syn – A synapse object as obtained with syn = synapseclient.login()

  • messageSubject – A string with subject line for sent out messages.

  • retries – Number of retries to attempt on failure (default=0)

Example:

# to decorate a function that you define
from synapseutils import notifyMe
import synapseclient
syn = synapseclient.login()

@notifyMe(syn, 'Long running function', retries=2)
def my_function(x):
    doing_something()
    return long_runtime_func(x)

my_function(123)

#############################
# to wrap a function that already exists
from synapseutils import notifyMe
import synapseclient
syn = synapseclient.login()

notify_decorator = notifyMe(syn, 'Long running query', retries=2)
my_query = notify_decorator(syn.tableQuery)
results = my_query("select id from syn1223")

#############################
synapseutils.monitor.with_progress_bar(func, totalCalls, prefix='', postfix='', isBytes=False)

Wraps a function to add a progress bar based on the number of calls to that function.

Parameters
  • func – Function being wrapped with progress Bar

  • totalCalls – total number of items/bytes when completed

  • prefix – String printed before progress bar

  • prefix – String printed after progress bar

  • isBytes – A boolean indicating weather to convert bytes to kB, MB, GB etc.

Returns

a wrapped function that contains a progress bar