Last active
December 12, 2015 01:48
-
-
Save cbare/4693562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## example session with the python synapse client | |
| ## Note: You'll have to insert your credentials and a project ID | |
| ###################################################################### | |
| ## import the synapse library and sign in | |
| import synapseclient | |
| syn = synapseclient.Synapse() | |
| syn.login('me@gmail.com', 'secret') | |
| ## retrieve an existing project | |
| project = syn.getEntity('syn123') | |
| ## create a new entity under the existing project | |
| ## and upload a file to that entity | |
| filename = 'path/to/my/file' | |
| entity = { | |
| 'entityType': 'org.sagebionetworks.repo.model.Data', | |
| 'name': 'My shiny new entity', | |
| 'description': 'A description goes here', | |
| 'parentId': project['id'] } | |
| entity = syn.createEntity(entity) | |
| syn.uploadFile(entity, filename) | |
| ## query for files under an existing project | |
| results = syn.query("select id, name from entity where entity.parentId=='%s'" % project['id']) | |
| ## we don't currently have a method to get the user's profile | |
| ## until we add it, here's how to do it. | |
| import requests | |
| headers = {'Content-type': 'application/json', 'Accept': 'application/json', 'sessionToken': syn.sessionToken } | |
| response = requests.get(syn.repoEndpoint + "/userProfile", headers=headers) | |
| user = response.json() | |
| ## now that we have a user profile, we can use it's ID to | |
| ## query for Data entities owned by that user | |
| results = syn.query('select id, name, parentId from data where createdByPrincipalId == %s' % (user['ownerId'],)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment