In this repository an example Python script file is included, called example.py. You can use the functions defined in your own tools and applications.
The examples below explain the basic usage of the B2SHARE service REST API using these functions. More information can be found on the B2SHARE REST API page. You can freely use the training instance of the B2SHARE service to test your applications.
Please make sure your machine has been properly set up to use Python and required packages. Follow this guide in order to do so.
This guide assumes you have successfully registered your account on B2SHARE using your institutional credentials or social ID through B2ACCESS.
The example script uses a few additional packages to ease the handling of data in the script.
import json
from urlparse import urljoin
The json
package is used to parse and display JSON-formatted strings, while urljoin
can construct full URLs based on separate strings. Please note that the latter package only works in Python 2.x. For later versions, use urllib.parse
instead.
This section shortly explains how to create new deposits of data sets in B2SHARE.
Please follow the Getting your API token in order to get your API token. The generated token needs to be stored in a file called token
which is read every time one of the example functions is called.
To create a new deposition use the
create_deposition()
function. It will register a test deposition in the service, but does not containg any files or metadata yet. A temporary file is created on your local file system.
To add files to the deposition, use the following function:
add_file('filename')
This function can be used multiple times in order to add multiple files.
To check which files are currentyl attached, use:
list_files()
To finalize the deposition into a new record, use the commit function:
commit_deposition()
Currently, all metadata values are fixed.
Please note that these functional examples need an API key. See Step 0 in the section above.
List a specific record registered in the service:
list_specific_record('154')
List all registered records in the service instance:
list_records()
List registered records in the service instance paginated:
list_records_pagination(3, 10)