A client for Synapse, a collaborative, open-source research platform that allows teams to share data, track analyses, and collaborate.
Project description
Python Synapse Client
Branch | Build Status |
---|---|
develop | |
master |
A Python client for Sage Bionetworks' Synapse, a collaborative, open-source research platform that allows teams to share data, track analyses, and collaborate. 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:
Installation
The Python Synapse client has been tested on 3.8, 3.9, 3.10 and 3.11 on Mac OS X, Ubuntu Linux and Windows.
Starting from Synapse Python client version 3.0, Synapse Python client requires Python >= 3.8
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 -p auth_token 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 Bionetworks Synapse repository.
Example
import synapseclient
syn = synapseclient.Synapse()
## log in using username and password
syn.login(authToken='auth_token')
## 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 with the clients using personal access tokens. Learn more about Synapse personal access tokens
Authentication via passwords and API keys will be deprecated early 2024.
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()
# copies all Synapse entities to a destination location
synapseutils.copy(syn, "syn1234", destinationId = "syn2345")
# copies the wiki from the entity to a destination entity. Only a project can have sub wiki pages.
synapseutils.copyWiki(syn, "syn1234", destinationId = "syn2345")
# 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-23 Sage Bionetworks
This software is licensed under the Apache License, Version 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for synapseclient-3.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b86002591f69a910c6f5d9009802ede60d4c6b0123dd53ada95a8f843eb8ab3c |
|
MD5 | 3c34c8ad1bae1a58c1defa7975e52839 |
|
BLAKE2b-256 | f10f73e2403456482efaefad509f6d0d3b9909e54121e49d247effbd5b182c7c |