Skip to content

Files

Latest commit

 

History

History
71 lines (56 loc) · 2.89 KB

C_Example_script.md

File metadata and controls

71 lines (56 loc) · 2.89 KB

Example script

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.

Setup your machine and connection

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.

General information

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.

Deposition of data sets

This section shortly explains how to create new deposits of data sets in B2SHARE.

Step 0: Prepare your API application

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.

Step 1: Create a new deposition

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.

Step 2: Add new files to a deposition

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.

Step 3: List the files uploaded into a deposition object

To check which files are currentyl attached, use:

list_files()

Step 4: Commit deposition

To finalize the deposition into a new record, use the commit function:

commit_deposition()

Currently, all metadata values are fixed.

Other uses

Please note that these functional examples need an API key. See Step 0 in the section above.

List a specific record

List a specific record registered in the service:

list_specific_record('154')

List all the records

List all registered records in the service instance:

list_records()

List registered records in the service instance paginated:

list_records_pagination(3, 10)