synapseclient 3.1.1__tar.gz → 4.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. synapseclient-4.0.0/PKG-INFO +387 -0
  2. synapseclient-4.0.0/README.md +317 -0
  3. {synapseclient-3.1.1 → synapseclient-4.0.0}/setup.cfg +13 -5
  4. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/.synapseConfig +2 -2
  5. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/__init__.py +2 -0
  6. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/__main__.py +184 -134
  7. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/activity.py +39 -54
  8. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/annotations.py +165 -81
  9. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/client.py +2050 -1187
  10. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/cache.py +171 -55
  11. synapseclient-4.0.0/synapseclient/core/credentials/__init__.py +2 -0
  12. synapseclient-4.0.0/synapseclient/core/credentials/cred_data.py +102 -0
  13. synapseclient-4.0.0/synapseclient/core/credentials/credential_provider.py +279 -0
  14. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/exceptions.py +0 -14
  15. synapseclient-4.0.0/synapseclient/core/models/permission.py +190 -0
  16. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/multithread_download/download_threads.py +65 -52
  17. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/remote_file_storage_wrappers.py +119 -55
  18. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/retry.py +37 -21
  19. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/sts_transfer.py +18 -11
  20. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/upload/multipart_upload.py +195 -125
  21. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/upload/upload_functions.py +48 -20
  22. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/utils.py +311 -131
  23. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/version_check.py +26 -28
  24. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/entity.py +194 -225
  25. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/evaluation.py +89 -83
  26. synapseclient-4.0.0/synapseclient/synapsePythonClient +14 -0
  27. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/table.py +499 -646
  28. synapseclient-4.0.0/synapseclient/team.py +108 -0
  29. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/wiki.py +33 -47
  30. synapseclient-4.0.0/synapseclient.egg-info/PKG-INFO +387 -0
  31. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient.egg-info/SOURCES.txt +1 -1
  32. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient.egg-info/entry_points.txt +0 -1
  33. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient.egg-info/requires.txt +12 -7
  34. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseutils/__init__.py +2 -14
  35. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseutils/copy_functions.py +224 -217
  36. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseutils/describe_functions.py +45 -36
  37. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseutils/migrate_functions.py +74 -67
  38. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseutils/monitor.py +31 -28
  39. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseutils/sync.py +446 -195
  40. synapseclient-4.0.0/synapseutils/walk_functions.py +114 -0
  41. synapseclient-3.1.1/PKG-INFO +0 -200
  42. synapseclient-3.1.1/README.md +0 -162
  43. synapseclient-3.1.1/synapseclient/core/credentials/__init__.py +0 -4
  44. synapseclient-3.1.1/synapseclient/core/credentials/cached_sessions.py +0 -34
  45. synapseclient-3.1.1/synapseclient/core/credentials/cred_data.py +0 -197
  46. synapseclient-3.1.1/synapseclient/core/credentials/credential_provider.py +0 -291
  47. synapseclient-3.1.1/synapseclient/synapsePythonClient +0 -6
  48. synapseclient-3.1.1/synapseclient/team.py +0 -101
  49. synapseclient-3.1.1/synapseclient.egg-info/PKG-INFO +0 -200
  50. synapseclient-3.1.1/synapseutils/walk_functions.py +0 -82
  51. {synapseclient-3.1.1 → synapseclient-4.0.0}/MANIFEST.in +0 -0
  52. {synapseclient-3.1.1 → synapseclient-4.0.0}/pyproject.toml +0 -0
  53. {synapseclient-3.1.1 → synapseclient-4.0.0}/setup.py +0 -0
  54. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/__init__.py +0 -0
  55. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/config.py +0 -0
  56. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/constants/__init__.py +0 -0
  57. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/constants/concrete_types.py +0 -0
  58. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/constants/config_file_constants.py +0 -0
  59. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/constants/limits.py +0 -0
  60. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/cumulative_transfer_progress.py +0 -0
  61. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/dozer.py +0 -0
  62. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/lock.py +0 -0
  63. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/logging_setup.py +0 -0
  64. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/models/__init__.py +0 -0
  65. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/models/custom_json.py +0 -0
  66. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/models/dict_object.py +0 -0
  67. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/multithread_download/__init__.py +0 -0
  68. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/pool_provider.py +0 -0
  69. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/core/upload/__init__.py +0 -0
  70. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/services/__init__.py +0 -0
  71. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient/services/json_schema.py +0 -0
  72. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient.egg-info/dependency_links.txt +0 -0
  73. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient.egg-info/not-zip-safe +0 -0
  74. {synapseclient-3.1.1 → synapseclient-4.0.0}/synapseclient.egg-info/top_level.txt +0 -0
@@ -0,0 +1,387 @@
1
+ Metadata-Version: 2.1
2
+ Name: synapseclient
3
+ Version: 4.0.0
4
+ Summary: A client for Synapse, a collaborative, open-source research platform that allows teams to share data, track analyses, and collaborate.
5
+ Home-page: https://www.synapse.org
6
+ Author: The Synapse Engineering Team
7
+ Author-email: platform@sagebase.org
8
+ License: Apache-2.0
9
+ Project-URL: Source, https://github.com/Sage-Bionetworks/synapsePythonClient
10
+ Project-URL: Tracker, https://github.com/Sage-Bionetworks/synapsePythonClient/issues
11
+ Project-URL: Documentation, https://python-docs.synapse.org
12
+ Project-URL: Changelog, https://python-docs.synapse.org/build/html/index.html#release-notes
13
+ Platform: any
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Operating System :: MacOS
21
+ Classifier: Operating System :: Microsoft :: Windows
22
+ Classifier: Operating System :: Unix
23
+ Classifier: Operating System :: POSIX :: Linux
24
+ Classifier: Intended Audience :: Developers
25
+ Classifier: Intended Audience :: Science/Research
26
+ Classifier: License :: OSI Approved :: Apache Software License
27
+ Classifier: Topic :: Software Development :: Libraries
28
+ Classifier: Topic :: Scientific/Engineering
29
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
30
+ Requires-Python: >=3.8
31
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
32
+ Requires-Dist: requests<3.0,>=2.22.0
33
+ Requires-Dist: urllib3<2,>=1.26.18
34
+ Requires-Dist: deprecated<2.0,>=1.2.4
35
+ Requires-Dist: opentelemetry-api~=1.21.0
36
+ Requires-Dist: opentelemetry-sdk~=1.21.0
37
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http~=1.21.0
38
+ Provides-Extra: dev
39
+ Requires-Dist: pytest<7.0,>=6.0.0; extra == "dev"
40
+ Requires-Dist: pytest-mock<4.0,>=3.0; extra == "dev"
41
+ Requires-Dist: flake8<4.0,>=3.7.0; extra == "dev"
42
+ Requires-Dist: pytest-xdist[psutil]<3.0.0,>=2.2; extra == "dev"
43
+ Requires-Dist: pytest-rerunfailures~=12.0; extra == "dev"
44
+ Requires-Dist: func-timeout~=4.3; extra == "dev"
45
+ Requires-Dist: pytest-cov~=4.1.0; extra == "dev"
46
+ Requires-Dist: black; extra == "dev"
47
+ Requires-Dist: pre-commit; extra == "dev"
48
+ Provides-Extra: tests
49
+ Requires-Dist: pytest<7.0,>=6.0.0; extra == "tests"
50
+ Requires-Dist: pytest-mock<4.0,>=3.0; extra == "tests"
51
+ Requires-Dist: flake8<4.0,>=3.7.0; extra == "tests"
52
+ Requires-Dist: pytest-xdist[psutil]<3.0.0,>=2.2; extra == "tests"
53
+ Requires-Dist: pytest-rerunfailures~=12.0; extra == "tests"
54
+ Requires-Dist: func-timeout~=4.3; extra == "tests"
55
+ Requires-Dist: pytest-cov~=4.1.0; extra == "tests"
56
+ Provides-Extra: pandas
57
+ Requires-Dist: pandas<2.1,>=1.5; extra == "pandas"
58
+ Provides-Extra: pysftp
59
+ Requires-Dist: pysftp<0.3,>=0.2.8; extra == "pysftp"
60
+ Provides-Extra: boto3
61
+ Requires-Dist: boto3<2.0,>=1.7.0; extra == "boto3"
62
+ Provides-Extra: docs
63
+ Requires-Dist: mkdocs>=1.5.3; extra == "docs"
64
+ Requires-Dist: mkdocs-material>=9.4.14; extra == "docs"
65
+ Requires-Dist: mkdocstrings>=0.24.0; extra == "docs"
66
+ Requires-Dist: mkdocstrings-python>=1.7.5; extra == "docs"
67
+ Requires-Dist: termynal>=0.11.1; extra == "docs"
68
+ Requires-Dist: mkdocs-open-in-new-tab~=1.0.3; extra == "docs"
69
+ Requires-Dist: markdown-include~=0.8.1; extra == "docs"
70
+
71
+ Python Synapse Client
72
+ =====================
73
+
74
+ Branch | Build Status
75
+ --------|-------------
76
+ develop | [![Build Status develop branch](https://github.com/Sage-Bionetworks/synapsePythonClient/workflows/build/badge.svg?branch=develop)](https://github.com/Sage-Bionetworks/synapsePythonClient/actions?query=branch%3Adevelop)
77
+ master | [![Build Status master branch](https://github.com/Sage-Bionetworks/synapsePythonClient/workflows/build/badge.svg?branch=master)](https://github.com/Sage-Bionetworks/synapsePythonClient/actions?query=branch%3Amaster)
78
+
79
+ [![Get the synapseclient from PyPI](https://img.shields.io/pypi/v/synapseclient.svg)](https://pypi.python.org/pypi/synapseclient/) [![Supported Python Versions](https://img.shields.io/pypi/pyversions/synapseclient.svg)](https://pypi.python.org/pypi/synapseclient/)
80
+
81
+ A Python client for [Sage Bionetworks'](https://www.sagebase.org) [Synapse](https://www.synapse.org/), 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.
82
+
83
+ There is also a [Synapse client for R](https://github.com/Sage-Bionetworks/synapser/).
84
+
85
+ Documentation
86
+ -------------
87
+
88
+ For more information about the Python client, see:
89
+
90
+ * [Python client API docs](https://python-docs.synapse.org)
91
+
92
+ For more information about interacting with Synapse, see:
93
+
94
+ * [Synapse API docs](https://rest-docs.synapse.org/rest/)
95
+ * [User cases](https://help.synapse.org/docs/Use-Cases.1985151645.html)
96
+ * [Getting Started Guide to Synapse](https://help.synapse.org/docs/Getting-Started.2055471150.html)
97
+
98
+ For release information, see:
99
+
100
+ * [Release notes](https://python-docs.synapse.org/news/)
101
+
102
+ <!-- Subscribe to release and other announcements [here](https://groups.google.com/a/sagebase.org/forum/#!forum/python-announce)
103
+ or by sending an email to [python-announce+subscribe@sagebase.org](mailto:python-announce+subscribe@sagebase.org) -->
104
+
105
+
106
+ Installation
107
+ ------------
108
+
109
+ 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.
110
+
111
+ **Starting from Synapse Python client version 3.0, Synapse Python client requires Python >= 3.8**
112
+
113
+ ### Install using pip
114
+
115
+ The [Python Synapse Client is on PyPI](https://pypi.python.org/pypi/synapseclient) and can be installed with pip:
116
+
117
+ (sudo) pip install synapseclient[pandas,pysftp]
118
+
119
+ ...or to upgrade an existing installation of the Synapse client:
120
+
121
+ (sudo) pip install --upgrade synapseclient
122
+
123
+ The dependencies on `pandas` and `pysftp` are optional. Synapse [Tables](https://python-docs.synapse.org/reference/tables/) integrate
124
+ with [Pandas](http://pandas.pydata.org/). The library `pysftp` is required for users of
125
+ [SFTP](https://python-docs.synapse.org/guides/data_storage/#sftp) file storage. Both libraries require native code
126
+ to be compiled or installed separately from prebuilt binaries.
127
+
128
+ ### Install from source
129
+
130
+ Clone the [source code repository](https://github.com/Sage-Bionetworks/synapsePythonClient).
131
+
132
+ git clone git://github.com/Sage-Bionetworks/synapsePythonClient.git
133
+ cd synapsePythonClient
134
+ pip install .
135
+
136
+
137
+ Command line usage
138
+ ------------------
139
+
140
+ The Synapse client can be used from the shell command prompt. Valid commands
141
+ include: query, get, cat, add, update, delete, and onweb. A few examples are
142
+ shown.
143
+
144
+ ### downloading test data from Synapse
145
+
146
+ synapse -p auth_token get syn1528299
147
+
148
+ ### getting help
149
+
150
+ synapse -h
151
+
152
+ Note that a [Synapse account](https://www.synapse.org/#RegisterAccount:0) is required.
153
+
154
+
155
+ Usage as a library
156
+ ------------------
157
+
158
+ 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](https://python-docs.synapse.org/tutorials/home/)
159
+
160
+ ### Examples
161
+
162
+ #### Log-in and create a Synapse object
163
+ ```
164
+ import synapseclient
165
+
166
+ syn = synapseclient.Synapse()
167
+
168
+ ## log in using auth token
169
+ syn.login(authToken='auth_token')
170
+ ```
171
+
172
+ #### Sync a local directory to synapse
173
+ 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`](https://python-docs.synapse.org/reference/synapse_utils/#synapseutils.sync.syncToSynapse)
174
+ ```
175
+ import synapseclient
176
+ import synapseutils
177
+ import os
178
+
179
+ syn = synapseclient.Synapse()
180
+
181
+ ## log in using auth token
182
+ syn.login(authToken='auth_token')
183
+
184
+ path = os.path.expanduser("~/synapse_project")
185
+ manifest_path = f"{path}/my_project_manifest.tsv"
186
+ project_id = "syn1234"
187
+
188
+ # Create the manifest file on disk
189
+ with open(manifest_path, "w", encoding="utf-8") as f:
190
+ pass
191
+
192
+ # Walk the specified directory tree and create a TSV manifest file
193
+ synapseutils.generate_sync_manifest(
194
+ syn,
195
+ directory_path=path,
196
+ parent_id=project_id,
197
+ manifest_path=manifest_path,
198
+ )
199
+
200
+ # Using the generated manifest file, sync the files to Synapse
201
+ synapseutils.syncToSynapse(
202
+ syn,
203
+ manifestFile=manifest_path,
204
+ sendMessages=False,
205
+ )
206
+ ```
207
+
208
+ #### Store a Project to Synapse
209
+ ```
210
+ import synapseclient
211
+ from synapseclient.entity import Project
212
+
213
+ syn = synapseclient.Synapse()
214
+
215
+ ## log in using auth token
216
+ syn.login(authToken='auth_token')
217
+
218
+ project = Project('My uniquely named project')
219
+ project = syn.store(project)
220
+
221
+ print(project.id)
222
+ print(project)
223
+ ```
224
+
225
+ #### Store a Folder to Synapse (Does not upload files within the folder)
226
+ ```
227
+ import synapseclient
228
+
229
+ syn = synapseclient.Synapse()
230
+
231
+ ## log in using auth token
232
+ syn.login(authToken='auth_token')
233
+
234
+ folder = Folder(name='my_folder', parent="syn123")
235
+ folder = syn.store(folder)
236
+
237
+ print(folder.id)
238
+ print(folder)
239
+
240
+ ```
241
+
242
+ #### Store a File to Synapse
243
+ ```
244
+ import synapseclient
245
+
246
+ syn = synapseclient.Synapse()
247
+
248
+ ## log in using auth token
249
+ syn.login(authToken='auth_token')
250
+
251
+ file = File(
252
+ path=filepath,
253
+ parent="syn123",
254
+ )
255
+ file = syn.store(file)
256
+
257
+ print(file.id)
258
+ print(file)
259
+ ```
260
+
261
+ #### Get a data matrix
262
+ ```
263
+ import synapseclient
264
+
265
+ syn = synapseclient.Synapse()
266
+
267
+ ## log in using auth token
268
+ syn.login(authToken='auth_token')
269
+
270
+ ## retrieve a 100 by 4 matrix
271
+ matrix = syn.get('syn1901033')
272
+
273
+ ## inspect its properties
274
+ print(matrix.name)
275
+ print(matrix.description)
276
+ print(matrix.path)
277
+
278
+ ## load the data matrix into a dictionary with an entry for each column
279
+ with open(matrix.path, 'r') as f:
280
+ labels = f.readline().strip().split('\t')
281
+ data = {label: [] for label in labels}
282
+ for line in f:
283
+ values = [float(x) for x in line.strip().split('\t')]
284
+ for i in range(len(labels)):
285
+ data[labels[i]].append(values[i])
286
+
287
+ ## load the data matrix into a numpy array
288
+ import numpy as np
289
+ np.loadtxt(fname=matrix.path, skiprows=1)
290
+ ```
291
+
292
+
293
+ Authentication
294
+ --------------
295
+ Authentication toward [Synapse](https://www.synapse.org/#RegisterAccount:0) can be accomplished with the clients using personal access tokens. Learn more about [Synapse personal access tokens](https://help.synapse.org/docs/Managing-Your-Account.2055405596.html#ManagingYourAccount-PersonalAccessTokens)
296
+
297
+ Learn about the [multiple ways one can login to Synapse](https://python-docs.synapse.org/tutorials/authentication/).
298
+
299
+
300
+ Synapse Utilities (synapseutils)
301
+ --------------------------------
302
+
303
+ 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.
304
+
305
+ ### Example
306
+
307
+ import synapseutils
308
+ import synapseclient
309
+ syn = synapseclient.login()
310
+
311
+ # copies all Synapse entities to a destination location
312
+ synapseutils.copy(syn, "syn1234", destinationId = "syn2345")
313
+
314
+ # copies the wiki from the entity to a destination entity. Only a project can have sub wiki pages.
315
+ synapseutils.copyWiki(syn, "syn1234", destinationId = "syn2345")
316
+
317
+
318
+ # Traverses through Synapse directories, behaves exactly like os.walk()
319
+ walkedPath = synapseutils.walk(syn, "syn1234")
320
+
321
+ for dirpath, dirname, filename in walkedPath:
322
+ print(dirpath)
323
+ print(dirname)
324
+ print(filename)
325
+
326
+ OpenTelemetry (OTEL)
327
+ --------------------------------
328
+ [OpenTelemetry](https://opentelemetry.io/) 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](https://opentelemetry-python.readthedocs.io/en/stable/exporter/otlp/otlp.html).
329
+
330
+ Read more about OpenTelemetry in Python [here](https://opentelemetry.io/docs/instrumentation/python/)
331
+
332
+ ### Quick-start
333
+ The following shows an example of setting up [jaegertracing](https://www.jaegertracing.io/docs/1.50/deployment/#all-in-one) via docker and executing a simple python script that implements the Synapse Python client.
334
+
335
+ #### Running the jaeger docker container
336
+ Start a docker container with the following options:
337
+ ```
338
+ docker run --name jaeger \
339
+ -e COLLECTOR_OTLP_ENABLED=true \
340
+ -p 16686:16686 \
341
+ -p 4318:4318 \
342
+ jaegertracing/all-in-one:latest
343
+ ```
344
+ Explanation of ports:
345
+ * `4318` HTTP
346
+ * `16686` Jaeger UI
347
+
348
+ Once the docker container is running you can access the Jaeger UI via: `http://localhost:16686`
349
+
350
+ #### Example
351
+ By default the OTEL exporter sends trace data to `http://localhost:4318/v1/traces`, however you may override this by setting the `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` environment variable.
352
+
353
+ ```
354
+ import synapseclient
355
+ from opentelemetry import trace
356
+ from opentelemetry.sdk.trace import TracerProvider
357
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor
358
+ from opentelemetry.sdk.resources import SERVICE_NAME, Resource
359
+ from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
360
+
361
+ trace.set_tracer_provider(
362
+ TracerProvider(
363
+ resource=Resource(attributes={SERVICE_NAME: "my_own_code_above_synapse_client"})
364
+ )
365
+ )
366
+ trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
367
+ tracer = trace.get_tracer("my_tracer")
368
+
369
+ @tracer.start_as_current_span("my_span_name")
370
+ def main():
371
+ syn = synapseclient.Synapse()
372
+ syn.login()
373
+ my_entity = syn.get("syn52569429")
374
+ print(my_entity)
375
+
376
+ main()
377
+ ```
378
+
379
+
380
+
381
+
382
+ License and Copyright
383
+ ---------------------
384
+
385
+ &copy; Copyright 2013-23 Sage Bionetworks
386
+
387
+ This software is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
@@ -0,0 +1,317 @@
1
+ Python Synapse Client
2
+ =====================
3
+
4
+ Branch | Build Status
5
+ --------|-------------
6
+ develop | [![Build Status develop branch](https://github.com/Sage-Bionetworks/synapsePythonClient/workflows/build/badge.svg?branch=develop)](https://github.com/Sage-Bionetworks/synapsePythonClient/actions?query=branch%3Adevelop)
7
+ master | [![Build Status master branch](https://github.com/Sage-Bionetworks/synapsePythonClient/workflows/build/badge.svg?branch=master)](https://github.com/Sage-Bionetworks/synapsePythonClient/actions?query=branch%3Amaster)
8
+
9
+ [![Get the synapseclient from PyPI](https://img.shields.io/pypi/v/synapseclient.svg)](https://pypi.python.org/pypi/synapseclient/) [![Supported Python Versions](https://img.shields.io/pypi/pyversions/synapseclient.svg)](https://pypi.python.org/pypi/synapseclient/)
10
+
11
+ A Python client for [Sage Bionetworks'](https://www.sagebase.org) [Synapse](https://www.synapse.org/), 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.
12
+
13
+ There is also a [Synapse client for R](https://github.com/Sage-Bionetworks/synapser/).
14
+
15
+ Documentation
16
+ -------------
17
+
18
+ For more information about the Python client, see:
19
+
20
+ * [Python client API docs](https://python-docs.synapse.org)
21
+
22
+ For more information about interacting with Synapse, see:
23
+
24
+ * [Synapse API docs](https://rest-docs.synapse.org/rest/)
25
+ * [User cases](https://help.synapse.org/docs/Use-Cases.1985151645.html)
26
+ * [Getting Started Guide to Synapse](https://help.synapse.org/docs/Getting-Started.2055471150.html)
27
+
28
+ For release information, see:
29
+
30
+ * [Release notes](https://python-docs.synapse.org/news/)
31
+
32
+ <!-- Subscribe to release and other announcements [here](https://groups.google.com/a/sagebase.org/forum/#!forum/python-announce)
33
+ or by sending an email to [python-announce+subscribe@sagebase.org](mailto:python-announce+subscribe@sagebase.org) -->
34
+
35
+
36
+ Installation
37
+ ------------
38
+
39
+ 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.
40
+
41
+ **Starting from Synapse Python client version 3.0, Synapse Python client requires Python >= 3.8**
42
+
43
+ ### Install using pip
44
+
45
+ The [Python Synapse Client is on PyPI](https://pypi.python.org/pypi/synapseclient) and can be installed with pip:
46
+
47
+ (sudo) pip install synapseclient[pandas,pysftp]
48
+
49
+ ...or to upgrade an existing installation of the Synapse client:
50
+
51
+ (sudo) pip install --upgrade synapseclient
52
+
53
+ The dependencies on `pandas` and `pysftp` are optional. Synapse [Tables](https://python-docs.synapse.org/reference/tables/) integrate
54
+ with [Pandas](http://pandas.pydata.org/). The library `pysftp` is required for users of
55
+ [SFTP](https://python-docs.synapse.org/guides/data_storage/#sftp) file storage. Both libraries require native code
56
+ to be compiled or installed separately from prebuilt binaries.
57
+
58
+ ### Install from source
59
+
60
+ Clone the [source code repository](https://github.com/Sage-Bionetworks/synapsePythonClient).
61
+
62
+ git clone git://github.com/Sage-Bionetworks/synapsePythonClient.git
63
+ cd synapsePythonClient
64
+ pip install .
65
+
66
+
67
+ Command line usage
68
+ ------------------
69
+
70
+ The Synapse client can be used from the shell command prompt. Valid commands
71
+ include: query, get, cat, add, update, delete, and onweb. A few examples are
72
+ shown.
73
+
74
+ ### downloading test data from Synapse
75
+
76
+ synapse -p auth_token get syn1528299
77
+
78
+ ### getting help
79
+
80
+ synapse -h
81
+
82
+ Note that a [Synapse account](https://www.synapse.org/#RegisterAccount:0) is required.
83
+
84
+
85
+ Usage as a library
86
+ ------------------
87
+
88
+ 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](https://python-docs.synapse.org/tutorials/home/)
89
+
90
+ ### Examples
91
+
92
+ #### Log-in and create a Synapse object
93
+ ```
94
+ import synapseclient
95
+
96
+ syn = synapseclient.Synapse()
97
+
98
+ ## log in using auth token
99
+ syn.login(authToken='auth_token')
100
+ ```
101
+
102
+ #### Sync a local directory to synapse
103
+ 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`](https://python-docs.synapse.org/reference/synapse_utils/#synapseutils.sync.syncToSynapse)
104
+ ```
105
+ import synapseclient
106
+ import synapseutils
107
+ import os
108
+
109
+ syn = synapseclient.Synapse()
110
+
111
+ ## log in using auth token
112
+ syn.login(authToken='auth_token')
113
+
114
+ path = os.path.expanduser("~/synapse_project")
115
+ manifest_path = f"{path}/my_project_manifest.tsv"
116
+ project_id = "syn1234"
117
+
118
+ # Create the manifest file on disk
119
+ with open(manifest_path, "w", encoding="utf-8") as f:
120
+ pass
121
+
122
+ # Walk the specified directory tree and create a TSV manifest file
123
+ synapseutils.generate_sync_manifest(
124
+ syn,
125
+ directory_path=path,
126
+ parent_id=project_id,
127
+ manifest_path=manifest_path,
128
+ )
129
+
130
+ # Using the generated manifest file, sync the files to Synapse
131
+ synapseutils.syncToSynapse(
132
+ syn,
133
+ manifestFile=manifest_path,
134
+ sendMessages=False,
135
+ )
136
+ ```
137
+
138
+ #### Store a Project to Synapse
139
+ ```
140
+ import synapseclient
141
+ from synapseclient.entity import Project
142
+
143
+ syn = synapseclient.Synapse()
144
+
145
+ ## log in using auth token
146
+ syn.login(authToken='auth_token')
147
+
148
+ project = Project('My uniquely named project')
149
+ project = syn.store(project)
150
+
151
+ print(project.id)
152
+ print(project)
153
+ ```
154
+
155
+ #### Store a Folder to Synapse (Does not upload files within the folder)
156
+ ```
157
+ import synapseclient
158
+
159
+ syn = synapseclient.Synapse()
160
+
161
+ ## log in using auth token
162
+ syn.login(authToken='auth_token')
163
+
164
+ folder = Folder(name='my_folder', parent="syn123")
165
+ folder = syn.store(folder)
166
+
167
+ print(folder.id)
168
+ print(folder)
169
+
170
+ ```
171
+
172
+ #### Store a File to Synapse
173
+ ```
174
+ import synapseclient
175
+
176
+ syn = synapseclient.Synapse()
177
+
178
+ ## log in using auth token
179
+ syn.login(authToken='auth_token')
180
+
181
+ file = File(
182
+ path=filepath,
183
+ parent="syn123",
184
+ )
185
+ file = syn.store(file)
186
+
187
+ print(file.id)
188
+ print(file)
189
+ ```
190
+
191
+ #### Get a data matrix
192
+ ```
193
+ import synapseclient
194
+
195
+ syn = synapseclient.Synapse()
196
+
197
+ ## log in using auth token
198
+ syn.login(authToken='auth_token')
199
+
200
+ ## retrieve a 100 by 4 matrix
201
+ matrix = syn.get('syn1901033')
202
+
203
+ ## inspect its properties
204
+ print(matrix.name)
205
+ print(matrix.description)
206
+ print(matrix.path)
207
+
208
+ ## load the data matrix into a dictionary with an entry for each column
209
+ with open(matrix.path, 'r') as f:
210
+ labels = f.readline().strip().split('\t')
211
+ data = {label: [] for label in labels}
212
+ for line in f:
213
+ values = [float(x) for x in line.strip().split('\t')]
214
+ for i in range(len(labels)):
215
+ data[labels[i]].append(values[i])
216
+
217
+ ## load the data matrix into a numpy array
218
+ import numpy as np
219
+ np.loadtxt(fname=matrix.path, skiprows=1)
220
+ ```
221
+
222
+
223
+ Authentication
224
+ --------------
225
+ Authentication toward [Synapse](https://www.synapse.org/#RegisterAccount:0) can be accomplished with the clients using personal access tokens. Learn more about [Synapse personal access tokens](https://help.synapse.org/docs/Managing-Your-Account.2055405596.html#ManagingYourAccount-PersonalAccessTokens)
226
+
227
+ Learn about the [multiple ways one can login to Synapse](https://python-docs.synapse.org/tutorials/authentication/).
228
+
229
+
230
+ Synapse Utilities (synapseutils)
231
+ --------------------------------
232
+
233
+ 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.
234
+
235
+ ### Example
236
+
237
+ import synapseutils
238
+ import synapseclient
239
+ syn = synapseclient.login()
240
+
241
+ # copies all Synapse entities to a destination location
242
+ synapseutils.copy(syn, "syn1234", destinationId = "syn2345")
243
+
244
+ # copies the wiki from the entity to a destination entity. Only a project can have sub wiki pages.
245
+ synapseutils.copyWiki(syn, "syn1234", destinationId = "syn2345")
246
+
247
+
248
+ # Traverses through Synapse directories, behaves exactly like os.walk()
249
+ walkedPath = synapseutils.walk(syn, "syn1234")
250
+
251
+ for dirpath, dirname, filename in walkedPath:
252
+ print(dirpath)
253
+ print(dirname)
254
+ print(filename)
255
+
256
+ OpenTelemetry (OTEL)
257
+ --------------------------------
258
+ [OpenTelemetry](https://opentelemetry.io/) 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](https://opentelemetry-python.readthedocs.io/en/stable/exporter/otlp/otlp.html).
259
+
260
+ Read more about OpenTelemetry in Python [here](https://opentelemetry.io/docs/instrumentation/python/)
261
+
262
+ ### Quick-start
263
+ The following shows an example of setting up [jaegertracing](https://www.jaegertracing.io/docs/1.50/deployment/#all-in-one) via docker and executing a simple python script that implements the Synapse Python client.
264
+
265
+ #### Running the jaeger docker container
266
+ Start a docker container with the following options:
267
+ ```
268
+ docker run --name jaeger \
269
+ -e COLLECTOR_OTLP_ENABLED=true \
270
+ -p 16686:16686 \
271
+ -p 4318:4318 \
272
+ jaegertracing/all-in-one:latest
273
+ ```
274
+ Explanation of ports:
275
+ * `4318` HTTP
276
+ * `16686` Jaeger UI
277
+
278
+ Once the docker container is running you can access the Jaeger UI via: `http://localhost:16686`
279
+
280
+ #### Example
281
+ By default the OTEL exporter sends trace data to `http://localhost:4318/v1/traces`, however you may override this by setting the `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` environment variable.
282
+
283
+ ```
284
+ import synapseclient
285
+ from opentelemetry import trace
286
+ from opentelemetry.sdk.trace import TracerProvider
287
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor
288
+ from opentelemetry.sdk.resources import SERVICE_NAME, Resource
289
+ from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
290
+
291
+ trace.set_tracer_provider(
292
+ TracerProvider(
293
+ resource=Resource(attributes={SERVICE_NAME: "my_own_code_above_synapse_client"})
294
+ )
295
+ )
296
+ trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
297
+ tracer = trace.get_tracer("my_tracer")
298
+
299
+ @tracer.start_as_current_span("my_span_name")
300
+ def main():
301
+ syn = synapseclient.Synapse()
302
+ syn.login()
303
+ my_entity = syn.get("syn52569429")
304
+ print(my_entity)
305
+
306
+ main()
307
+ ```
308
+
309
+
310
+
311
+
312
+ License and Copyright
313
+ ---------------------
314
+
315
+ &copy; Copyright 2013-23 Sage Bionetworks
316
+
317
+ This software is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).