synapseclient
Programmatic interface to Synapse services for Python
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
5 of 51 committers (9.8%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.4%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Programmatic interface to Synapse services for Python
Basic Info
- Host: GitHub
- Owner: Sage-Bionetworks
- License: apache-2.0
- Language: Python
- Default Branch: develop
- Homepage: https://www.synapse.org
- Size: 25.7 MB
Statistics
- Stars: 75
- Watchers: 27
- Forks: 72
- Open Issues: 10
- Releases: 72
Topics
Metadata Files
README.md
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 versions 3.9, 3.10, 3.11, 3.12 and 3.13 on Mac OS X, Ubuntu Linux and Windows.
Starting from Synapse Python client version 3.0, Synapse Python client requires Python >= 3.9
Install using pip
The Python Synapse Client is on PyPI and can be installed with pip:
# Here are a few ways to install the client. Choose the one that fits your use-case
# sudo may optionally be needed depending on your setup
pip install --upgrade synapseclient
pip install --upgrade "synapseclient[pandas]"
pip install --upgrade "synapseclient[pandas, pysftp, boto3]"
...or to upgrade an existing installation of the Synapse client:
# sudo may optionally be needed depending on your setup
pip install --upgrade synapseclient
The dependencies on pandas, pysftp, and boto3 are optional. Synapse
Tables integrate
with Pandas. The library pysftp is required for users of
SFTP file storage. All
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
pip install .
Alternatively, you can use pip to install a particular branch, commit, or other git reference:
pip install git+https://github.com/Sage-Bionetworks/synapsePythonClient@master
or
pip install git+https://github.com/Sage-Bionetworks/synapsePythonClient@my-commit-hash
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. More examples can be found in the Tutorial section found here
Examples
Log-in and create a Synapse object
``` import synapseclient
syn = synapseclient.Synapse()
You may optionally specify the debug flag to True to print out debug level messages.
A debug level may help point to issues in your own code, or uncover a bug within ours.
syn = synapseclient.Synapse(debug=True)
log in using auth token
syn.login(authToken='auth_token') ```
Sync a local directory to synapse
This is the recommended way of synchronizing more than one file or directory to a synapse project through the use of synapseutils. Using this library allows us to handle scheduling everything required to sync an entire directory tree. Read more about the manifest file format in synapseutils.syncToSynapse
```
import synapseclient
import synapseutils
import os
syn = synapseclient.Synapse()
log in using auth token
syn.login(authToken='auth_token')
path = os.path.expanduser("~/synapseproject") manifestpath = f"{path}/myprojectmanifest.tsv" project_id = "syn1234"
Create the manifest file on disk
with open(manifest_path, "w", encoding="utf-8") as f: pass
Walk the specified directory tree and create a TSV manifest file
synapseutils.generatesyncmanifest( syn, directorypath=path, parentid=projectid, manifestpath=manifest_path, )
Using the generated manifest file, sync the files to Synapse
synapseutils.syncToSynapse( syn, manifestFile=manifest_path, sendMessages=False, ) ```
Store a Project to Synapse
``` import synapseclient from synapseclient.entity import Project
syn = synapseclient.Synapse()
log in using auth token
syn.login(authToken='auth_token')
project = Project('My uniquely named project') project = syn.store(project)
print(project.id) print(project) ```
Store a Folder to Synapse (Does not upload files within the folder)
``` import synapseclient
syn = synapseclient.Synapse()
log in using auth token
syn.login(authToken='auth_token')
folder = Folder(name='my_folder', parent="syn123") folder = syn.store(folder)
print(folder.id) print(folder)
```
Store a File to Synapse
``` import synapseclient
syn = synapseclient.Synapse()
log in using auth token
syn.login(authToken='auth_token')
file = File( path=filepath, parent="syn123", ) file = syn.store(file)
print(file.id) print(file) ```
Get a data matrix
``` import synapseclient
syn = synapseclient.Synapse()
log in using auth token
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
Learn about the multiple ways one can login to Synapse.
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)
OpenTelemetry (OTEL)
OpenTelemetry helps support the analysis of traces and spans which can provide insights into latency, errors, and other performance metrics. The synapseclient is ready to provide traces should you want them. The Synapse Python client supports OTLP Exports and can be configured via environment variables as defined here.
Read more about OpenTelemetry in Python here
Quick-start
The following shows an example of setting up jaegertracing via docker and executing a simple python script that implements the Synapse Python client.
Running the jaeger docker container
Start a docker container with the following options:
docker run --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 4318:4318 \
jaegertracing/all-in-one:latest
Explanation of ports:
* 4318 HTTP port for OTLP data collection
* 16686 Jaeger UI for visualizing traces
Once the docker container is running you can access the Jaeger UI via: http://localhost:16686
Environment Variable Configuration
By default, the OTEL exporter sends trace data to http://localhost:4318/v1/traces. You can customize the behavior through environment variables:
OTEL_SERVICE_NAME: Defines a unique identifier for your application or service in telemetry data (defaults to 'synapseclient'). Set this to a descriptive name that represents your specific implementation, making it easier to filter and analyze traces in your monitoring system.OTEL_EXPORTER_OTLP_ENDPOINT: Specifies the destination URL for sending telemetry data (defaults to 'http://localhost:4318'). Configure this to direct data to your preferred OpenTelemetry collector or monitoring service.OTEL_DEBUG_CONSOLE: Controls local visibility of telemetry data. Set to 'true' to output trace information to the console, which is useful for development and troubleshooting without an external collector.OTEL_SERVICE_INSTANCE_ID: Distinguishes between multiple instances of the same service (e.g., 'prod', 'development', 'local'). This helps identify which specific deployment or environment generated particular traces.OTEL_EXPORTER_OTLP_HEADERS: Configures authentication and metadata for telemetry exports. Use this to add API keys, authentication tokens, or custom metadata when sending traces to secured collectors or third-party monitoring services.
Enabling OpenTelemetry in your code
To enable OpenTelemetry with the Synapse Python client, simply call the
enable_open_telemetry() method on the Synapse class. Additionally you can access an
instance of the OpenTelemetry tracer via the get_tracer() call. This will allow you
to create new spans for your code.
```python import synapseclient
Enable OpenTelemetry with default settings
synapseclient.Synapse.enableopentelemetry() tracer = synapseclient.Synapse.get_tracer()
Then create and use the Synapse client as usual
with tracer.startascurrentspan("myfunctionspan"): syn = synapseclient.Synapse() syn.login(authToken='authtoken') ```
Advanced Configuration
You can pass additional resource attributes to enable_open_telemetry():
```python import synapseclient
Enable with custom resource attributes
synapseclient.Synapse.enableopentelemetry(
resourceattributes={
"deployment.environment": "development",
"service.version": "1.2.3", # Overrides the `OTELSERVICENAMEenvironment variable
"service.instance.id": "4.5.6", # Overrides theOTELSERVICEINSTANCEIDenvironment variable
"custom.attribute": "value"
}
)
``
When OpenTelemetry is enabled in the Synapse client, the following happens automatically:
Instrumentation is set up for:
- Threading (via
ThreadingInstrumentor): Ensures proper context propagation across threads, which is essential for maintaining trace continuity in multi-threaded applications - HTTP libraries:
requests(viaRequestsInstrumentor): Captures all HTTP requests made using the requests library, including methods, URLs, status codes, and timing informationhttpx(viaHTTPXClientInstrumentor): Tracks both synchronous and asynchronous HTTP requests made with the httpx libraryurllib(viaURLLibInstrumentor): Monitors lower-level HTTP operations made directly with Python's standard library
- Each instrumented HTTP library includes custom hooks that extract Synapse entity IDs from URLs when possible and add them as span attributes
- Threading (via
Traces are configured to collect spans across your application:
- Spans automatically capture operation duration, status, and errors.
- An attribute propagation mechanism ensures that certain attributes (like
synapse.transfer.directionandsynapse.operation.category) are properly passed to child spans for uploads/downloads. - Trace data is exported via OTLP (OpenTelemetry Protocol).
Resource information is automatically added to your traces, including:
- Python version
- OS type
- Synapse client version
- Service name (defaults to "synapseclient" but can be customized via environment variables)
- Service instance ID
Note that once enabled, OpenTelemetry cannot be disabled in the same process - you would need to restart your Python interpreter to disable it.
License and Copyright
© Copyright 2013-25 Sage Bionetworks
This software is licensed under the Apache License, Version 2.0.
Owner
- Name: Sage Bionetworks
- Login: Sage-Bionetworks
- Kind: organization
- Location: Seattle, Washington
- Website: www.sagebionetworks.org
- Repositories: 640
- Profile: https://github.com/Sage-Bionetworks
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 3,299
- Total Committers: 51
- Avg Commits per committer: 64.686
- Development Distribution Score (DDS): 0.849
Top Committers
| Name | Commits | |
|---|---|---|
| Jordan Kiang | j****g@s****g | 498 |
| Christopher Bare | c****e@s****g | 368 |
| Ziming Dong | z****g@s****g | 360 |
| thomasyu888 | t****8@g****m | 328 |
| Kimyen | k****6@g****m | 309 |
| thomasyu888 | t****u@s****g | 260 |
| Larsson Omberg | l****m@l****m | 258 |
| kdaily | k****y@s****g | 113 |
| unknown | z****d@g****m | 107 |
| Chia-Hui Lin | c****n@s****g | 104 |
| Christopher Bare | c****e@g****m | 100 |
| Joseph Wu | k****8@g****m | 92 |
| verena | 9****g@u****m | 61 |
| bhoff | b****f@s****g | 32 |
| Ziming Dong | z****d@u****m | 30 |
| Robert Minneker | m****r@u****u | 26 |
| Jordan Kiang | j****g@g****m | 24 |
| cokelaer | c****r@g****m | 21 |
| nicole.deflaux | n****x@e****6 | 20 |
| Dan Lu | 9****1@u****m | 19 |
| Bruno Grande | b****e@s****g | 16 |
| linchiahui | l****u@h****u | 13 |
| kdaily | k****y@u****m | 13 |
| mattfazza | a****a@g****m | 11 |
| john.hill | j****l@e****6 | 10 |
| Kimyen | 4****n@u****m | 9 |
| Robert Allaway | a****y@u****m | 9 |
| x.schildwachter | x****r@e****6 | 9 |
| Kenneth Daily | k****y@g****m | 8 |
| mike.kellen | m****n@e****6 | 7 |
| and 21 more... | ||
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 27
- Total pull requests: 331
- Average time to close issues: 6 months
- Average time to close pull requests: about 1 month
- Total issue authors: 20
- Total pull request authors: 22
- Average comments per issue: 2.63
- Average comments per pull request: 1.01
- Merged pull requests: 269
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 95
- Average time to close issues: 10 days
- Average time to close pull requests: 5 days
- Issue authors: 3
- Pull request authors: 12
- Average comments per issue: 7.33
- Average comments per pull request: 0.54
- Merged pull requests: 65
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- vpchung (5)
- andrewelamb (2)
- linglp (2)
- BryanFauble (2)
- javierpastorfernandez (1)
- jaewon-cho (1)
- Valkje (1)
- talkdirty (1)
- ptnaimelmm (1)
- tommypkeane-gehc (1)
- Breeze-Zero (1)
- FengheTan9 (1)
- JThomasWatson (1)
- jkiang13 (1)
- moskalenko (1)
Pull Request Authors
- BryanFauble (162)
- thomasyu888 (78)
- BWMac (24)
- danlu1 (16)
- jaymedina (12)
- linglp (11)
- vpchung (6)
- BrunoGrandePhD (4)
- carmmmm (2)
- allaway (2)
- rxu17 (2)
- linchiahuisage (2)
- Burrch3s (1)
- xschildw (1)
- andrewelamb (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 23,667 last-month
- Total docker downloads: 2,572
- Total dependent packages: 16
- Total dependent repositories: 95
- Total versions: 65
- Total maintainers: 1
pypi.org: synapseclient
A client for Synapse, a collaborative, open-source research platform that allows teams to share data, track analyses, and collaborate.
- Homepage: https://www.synapse.org
- Documentation: https://python-docs.synapse.org
- License: Apache-2.0
-
Latest release: 4.9.0
published 7 months ago
Rankings
Maintainers (1)
Dependencies
- synapseclient * develop
- synapseclient *
- alabaster ==0.7.13 develop
- attrs ==23.1.0 develop
- babel ==2.13.0 develop
- bcrypt ==4.0.1 develop
- black ==23.9.1 develop
- boto3 ==1.28.63 develop
- botocore ==1.31.63 develop
- certifi ==2023.7.22 develop
- cffi ==1.16.0 develop
- cfgv ==3.4.0 develop
- charset-normalizer ==3.3.0 develop
- click ==8.1.7 develop
- cryptography ==3.3.2 develop
- deprecated ==1.2.14 develop
- distlib ==0.3.7 develop
- docutils ==0.17.1 develop
- execnet ==2.0.2 develop
- filelock ==3.12.4 develop
- flake8 ==3.9.2 develop
- identify ==2.5.30 develop
- idna ==3.4 develop
- imagesize ==1.4.1 develop
- importlib-metadata ==6.8.0 develop
- iniconfig ==2.0.0 develop
- jeepney ==0.8.0 develop
- jinja2 ==3.1.2 develop
- jmespath ==1.0.1 develop
- keyring ==23.4.1 develop
- keyrings.alt ==3.1 develop
- markupsafe ==2.1.3 develop
- mccabe ==0.6.1 develop
- mypy-extensions ==1.0.0 develop
- nodeenv ==1.8.0 develop
- numpy ==1.26.0 develop
- packaging ==23.2 develop
- pandas ==2.0.3 develop
- paramiko ==3.3.1 develop
- pathspec ==0.11.2 develop
- platformdirs ==3.11.0 develop
- pluggy ==1.3.0 develop
- pre-commit ==3.5.0 develop
- psutil ==5.9.5 develop
- py ==1.11.0 develop
- pycodestyle ==2.7.0 develop
- pycparser ==2.21 develop
- pyflakes ==2.3.1 develop
- pygments ==2.16.1 develop
- pynacl ==1.5.0 develop
- pysftp ==0.2.9 develop
- pytest ==6.2.5 develop
- pytest-forked ==1.6.0 develop
- pytest-mock ==3.11.1 develop
- pytest-xdist ==2.5.0 develop
- python-dateutil ==2.8.2 develop
- pytz ==2023.3.post1 develop
- pyyaml ==6.0.1 develop
- requests ==2.31.0 develop
- s3transfer ==0.7.0 develop
- secretstorage ==3.3.3 develop
- setuptools ==68.2.2 develop
- six ==1.16.0 develop
- snowballstemmer ==2.2.0 develop
- sphinx ==4.5.0 develop
- sphinx-argparse ==0.2.5 develop
- sphinx-rtd-theme ==1.3.0 develop
- sphinxcontrib-applehelp ==1.0.4 develop
- sphinxcontrib-devhelp ==1.0.2 develop
- sphinxcontrib-htmlhelp ==2.0.1 develop
- sphinxcontrib-jquery ==4.1 develop
- sphinxcontrib-jsmath ==1.0.1 develop
- sphinxcontrib-qthelp ==1.0.3 develop
- sphinxcontrib-serializinghtml ==1.1.5 develop
- synapseclient * develop
- toml ==0.10.2 develop
- tzdata ==2023.3 develop
- urllib3 ==1.26.17 develop
- virtualenv ==20.24.5 develop
- wrapt ==1.15.0 develop
- zipp ==3.17.0 develop
- certifi ==2023.7.22
- cffi ==1.16.0
- charset-normalizer ==3.3.0
- cryptography ==3.3.2
- deprecated ==1.2.14
- idna ==3.4
- importlib-metadata ==6.8.0
- jeepney ==0.8.0
- keyring ==23.4.1
- keyrings.alt ==3.1
- pycparser ==2.21
- requests ==2.31.0
- secretstorage ==3.3.3
- six ==1.16.0
- synapseclient *
- urllib3 ==1.26.17
- wrapt ==1.15.0
- zipp ==3.17.0
- deprecated >=1.2.4,<2.0
- keyring >=15,<23.5
- requests >=2.22.0,<3.0
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/download-artifact v2 composite
- actions/setup-python v2 composite
- actions/upload-artifact v2 composite
- actions/upload-release-asset v1 composite
- psf/black stable composite
- actions/checkout v3 composite
- github/codeql-action/analyze v2 composite
- github/codeql-action/autobuild v2 composite
- github/codeql-action/init v2 composite
- ubuntu 20.04 build
- sphinx *
- sphinx-argparse *
- sphinx_rtd_theme *