Skip to main content

A client for Synapse, a collaborative compute space that allows scientists to share and analyze data together.

Project description

Python Synapse Client

CI Branch Build Status
Travis develop Build Status develop branch
Travis master Build Status master branch
AppVeyor develop AppVeyor branch
AppVeyor master AppVeyor branch

Get the synapseclient from PyPI Supported Python Versions

A Python client for Sage Bionetworks' Synapse, a collaborative compute space that allows scientists to share and analyze data together. The Python client can be used as a library for development of software that communicates with Synapse or as a command-line utility.

There is also a Synapse client for R.

Documentation

For more information about the Python client, see:

For more information about interacting with Synapse, see:

For release information, see:

Subscribe to release and other announcements here or by sending an email to python-announce+subscribe@sagebase.org

Installation

The Python Synapse client has been tested on 3.6, 3.7, and 3.8 on Mac OS X, Ubuntu Linux and Windows.

Starting from Synapse Python client version 2.0, Synapse Python client requires Python 3.6+

Install using pip

The Python Synapse Client is on PyPI and can be installed with pip:

(sudo) pip install synapseclient[pandas,pysftp]

...or to upgrade an existing installation of the Synapse client:

(sudo) pip install --upgrade synapseclient

The dependencies on pandas and pysftp are optional. Synapse Tables integrate with Pandas. The library pysftp is required for users of SFTP file storage. Both libraries require native code to be compiled or installed separately from prebuilt binaries.

Install from source

Clone the source code repository.

git clone git://github.com/Sage-Bionetworks/synapsePythonClient.git
cd synapsePythonClient
python setup.py install

Command line usage

The synapse client can be used from the shell command prompt. Valid commands include: query, get, cat, add, update, delete, and onweb. A few examples are shown.

downloading test data from synapse

synapse -u my_username -p my_password get syn1528299

getting help

synapse -h

Note that a synapse account is required.

Usage as a library

The synapse client can be used to write software that interacts with the Sage Synapse repository.

Example

import synapseclient

syn = synapseclient.Synapse()

## log in using username and password
syn.login('my_username', 'my_password')

## retrieve a 100 by 4 matrix
matrix = syn.get('syn1901033')

## inspect its properties
print(matrix.name)
print(matrix.description)
print(matrix.path)

## load the data matrix into a dictionary with an entry for each column
with open(matrix.path, 'r') as f:
    labels = f.readline().strip().split('\t')
    data = {label: [] for label in labels}
    for line in f:
        values = [float(x) for x in line.strip().split('\t')]
        for i in range(len(labels)):
            data[labels[i]].append(values[i])

## load the data matrix into a numpy array
import numpy as np
np.loadtxt(fname=matrix.path, skiprows=1)

Authentication

Authentication toward synapse can be accomplished in a few different ways. One is by passing username and password to the syn.login function.

import synapseclient
syn = synapseclient.Synapse()
syn.login('my_username', 'my_password')

It is much more convenient to use an API key, which can be generated and cached locally by doing the following once:

syn.login('my_username', 'my_password', rememberMe=True)

Then, in subsequent interactions, specifying username and password is optional and only needed to login as a different user. Calling login with no arguments uses cached credentials when they are available.

syn.login('my_username')

As a short-cut, creating the Synapse object and logging in can be done in one step:

import synapseclient
syn = synapseclient.login()

Caching credentials can also be done from the command line client:

synapse login -u my_username -p my_password --rememberMe

Synapse Utilities (synapseutils)

The purpose of synapseutils is to create a space filled with convenience functions that includes traversing through large projects, copying entities, recursively downloading files and many more.

Example

import synapseutils
import synapseclient
syn = synapseclient.login()

#COPY: copies all synapse entities to a destination location
synapseutils.copy(syn, "syn1234", destinationId = "syn2345")

#COPY WIKI: copies the wiki from the entity to a destination entity. Only a project can have sub wiki pages.
synapseutils.copyWiki(syn, "syn1234", destinationId = "syn2345")


#WALK: Traverses through synapse directories, behaves exactly like os.walk()
walkedPath = synapseutils.walk(syn, "syn1234")

for dirpath, dirname, filename in walkedPath:
    print(dirpath)
    print(dirname)
    print(filename)

License and Copyright

© Copyright 2013-19 Sage Bionetworks

This software is licensed under the Apache License, Version 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synapseclient-2.2.0.tar.gz (166.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synapseclient-2.2.0-py3.6.egg (391.9 kB view details)

Uploaded Egg

File details

Details for the file synapseclient-2.2.0.tar.gz.

File metadata

  • Download URL: synapseclient-2.2.0.tar.gz
  • Upload date:
  • Size: 166.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/38.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.7

File hashes

Hashes for synapseclient-2.2.0.tar.gz
Algorithm Hash digest
SHA256 660ddbe2ea41f95a3c4dbe9eb47eaf8b8aba44ed526dfd81c82aaf13d79a891f
MD5 e055522b814173341c0a055079839604
BLAKE2b-256 9cd7aafe8931d3ed7d8d72753f4faa5355a8a463723030cc8962588f2476434a

See more details on using hashes here.

File details

Details for the file synapseclient-2.2.0-py3.6.egg.

File metadata

  • Download URL: synapseclient-2.2.0-py3.6.egg
  • Upload date:
  • Size: 391.9 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/38.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.7

File hashes

Hashes for synapseclient-2.2.0-py3.6.egg
Algorithm Hash digest
SHA256 220b6f24c6c4ffd24a218f264ec781ef456e0087568406f2ff54398345f8312a
MD5 b9da40038bb6c69a6cf86dd1ba5bfa0c
BLAKE2b-256 835ecb4b5a24f7dc2dfeaea1cfd69ef1a7e51107ae61ee5ebb4440c7d3ef1a99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page