Skip to content

Commit 3ccb87f

Browse files
authored
[SYNPY-1634, SYNPY-1377] Use new OOP models in tutorials (#1241)
* Update several tutorials to use OOP model
1 parent da36c84 commit 3ccb87f

File tree

17 files changed

+353
-895
lines changed

17 files changed

+353
-895
lines changed

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Python Synapse Client
33

44
Branch | Build Status
55
--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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)
6+
develop | [![Build Status develop branch](https://github.com/Sage-Bionetworks/synapsePythonClient/actions/workflows/build.yml/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/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/Sage-Bionetworks/synapsePythonClient/actions?query=branch%3Amaster)
88

99
[![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/)
1010

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.
11+
A Python client for [Sage Bionetworks'](https://sagebionetworks.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.
1212

1313
There is also a [Synapse client for R](https://github.com/Sage-Bionetworks/synapser/).
1414

@@ -156,15 +156,15 @@ synapseutils.syncToSynapse(
156156
#### Store a Project to Synapse
157157
```
158158
import synapseclient
159-
from synapseclient.entity import Project
159+
from synapseclient.models import Project
160160
161161
syn = synapseclient.Synapse()
162162
163163
## log in using auth token
164164
syn.login(authToken='auth_token')
165165
166166
project = Project('My uniquely named project')
167-
project = syn.store(project)
167+
project.store()
168168
169169
print(project.id)
170170
print(project)
@@ -173,14 +173,15 @@ print(project)
173173
#### Store a Folder to Synapse (Does not upload files within the folder)
174174
```
175175
import synapseclient
176+
from synapseclient.models import Folder
176177
177178
syn = synapseclient.Synapse()
178179
179180
## log in using auth token
180181
syn.login(authToken='auth_token')
181182
182-
folder = Folder(name='my_folder', parent="syn123")
183-
folder = syn.store(folder)
183+
folder = Folder(name='my_folder', parent_id="syn123")
184+
folder.store()
184185
185186
print(folder.id)
186187
print(folder)
@@ -190,17 +191,18 @@ print(folder)
190191
#### Store a File to Synapse
191192
```
192193
import synapseclient
194+
from synapseclient.models import File
193195
194196
syn = synapseclient.Synapse()
195197
196198
## log in using auth token
197199
syn.login(authToken='auth_token')
198200
199201
file = File(
200-
path=filepath,
201-
parent="syn123",
202+
path="path/to/file.txt",
203+
parent_id="syn123",
202204
)
203-
file = syn.store(file)
205+
file.store()
204206
205207
print(file.id)
206208
print(file)
@@ -209,14 +211,15 @@ print(file)
209211
#### Get a data matrix
210212
```
211213
import synapseclient
214+
from synapseclient.models import File
212215
213216
syn = synapseclient.Synapse()
214217
215218
## log in using auth token
216219
syn.login(authToken='auth_token')
217220
218221
## retrieve a 100 by 4 matrix
219-
matrix = syn.get('syn1901033')
222+
matrix = File(id='syn1901033').get()
220223
221224
## inspect its properties
222225
print(matrix.name)

docs/guides/data_storage.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ If you are changing the storage location of an existing folder to a user specifi
2424
2. Create a folder and configure it to use external S3 storage:
2525

2626
```python
27+
from synapseclient.models import Folder
2728
# create a new folder to use with external S3 storage
28-
folder = syn.store(Folder(name=folder_name, parent=parent))
29+
folder = Folder(name=folder_name, parent_id=parent).store()
2930
# You may also use an existing folder like:
3031
# folder = syn.get("syn123")
3132
folder, storage_location, project_setting = syn.create_s3_storage_location(
32-
folder=folder,
33+
folder=folder.id,
3334
bucket_name='my-external-synapse-bucket',
3435
base_key='path/within/bucket',
3536
)
@@ -48,11 +49,12 @@ If you are changing the storage location of an existing project to a user specif
4849
2. Create a project and configure it to use external S3 storage:
4950

5051
```python
52+
from synapseclient.models import Project
5153
# create a new, or retrieve an existing project to use with external S3 storage
52-
project = syn.store(Project(name="my_project_name"))
54+
project = Project(name="my_project_name").store()
5355
project_storage, storage_location, project_setting = syn.create_s3_storage_location(
5456
# Despite the KW argument name, this can be a project or folder
55-
folder=project,
57+
folder=project.id,
5658
bucket_name='my-external-synapse-bucket',
5759
base_key='path/within/bucket',
5860
)
@@ -64,6 +66,8 @@ storage_location_id = storage_location['storageLocationId']
6466
Once an external S3 storage folder exists, you can interact with it as you would any other folder using Synapse tools. If you wish to add an object that is stored within the bucket to Synapse you can do that by adding a file handle for that object using the Python client and then storing the file to that handle.
6567

6668
```python
69+
from synapseclient.models import File
70+
6771
parent_synapse_folder_id = 'syn123'
6872
local_file_path = '/path/to/local/file'
6973
bucket = 'my-external-synapse-bucket'
@@ -84,8 +88,8 @@ file_handle = syn.create_external_s3_file_handle(
8488
local_file_path,
8589
parent=parent_synapse_folder_id,
8690
)
87-
file = File(parentId=folder['id'], dataFileHandleId=file_handle['id'])
88-
file_entity = syn.store(file)
91+
file_entity = File(parent_id=folder['id'], data_file_handle_id=file_handle['id'])
92+
file_entity.store()
8993
```
9094

9195
## Storage location migration

docs/guides/validate_annotations.md

Lines changed: 0 additions & 110 deletions
This file was deleted.

docs/guides/views.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

docs/index.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/synapseclient.svg)](https://pypi.org/project/synapseclient/)
44

5-
### **Notice for the upcoming v5.0 release:**
6-
7-
- The upcoming v5.0 release will include a number of breaking changes. Take a look at
8-
this [pubpub](https://sagebionetworks.pubpub.org/pub/828a3x4k/release/1) article
9-
detailing some of the changes.
10-
- A release date has not been set. A number of these changes will be available within
11-
the 4.x.x versions hidden behind optional feature flags or different import paths. Any
12-
breaking changes will not be included until v5.0.
5+
!!! note "Notice for the upcoming v5.0 release"
6+
- The upcoming v5.0 release will include a number of breaking changes. Take a look at
7+
this [pubpub](https://sagebionetworks.pubpub.org/pub/828a3x4k/release/1) article
8+
detailing some of the changes.
9+
- A release date has not been set. A number of these changes will be available within
10+
the 4.x.x versions hidden behind optional feature flags or different import paths. Any
11+
breaking changes will not be included until v5.0.
1312

1413
The `synapseclient` package provides an interface to [Synapse](http://www.synapse.org), a collaborative, open-source research platform that allows teams to share data, track analyses, and collaborate, providing support for:
1514

0 commit comments

Comments
 (0)