Skip to main content

A Python wrapper for DOIP.

Project description

DOIPY

Doipy is a Python wrapper for communication using the Digital Object Interface Protocol (DOIP) in its current specification v2.0.

It supports the Basic Operations hello, create, retrieve, update, delete, search, and list_operations. Extended Operations implemented by specific repository software are and will be included in the future.

Install

Simply run

$ pip install doipy

Usage

Getting Started

This doipy package has several methods. Please use doipy --help to list all available methods.

To use it in the Command Line Interface (CLI), provide the PID identifying the service in the data type registry (for example, 21.T11969/01370800d56a0d897dc1 is the identifier of the Cordra instance in the testbed) and run:

# Get information from the DOIP service
$ doipy hello '21.T11969/01370800d56a0d897dc1'

# List all available operations
$ doipy list_operations '21.T11969/01370800d56a0d897dc1'

# Search in the DOIP service for a DO
$ doipy search '21.T11969/01370800d56a0d897dc1' <query string> --username <username> --password <password>

# Retrieve an (F)DO at a DOIP service
$ doipy retrieve '21.T11969/01370800d56a0d897dc1' '21.T11967/06711fbea0e722163bbc'

To use it in the Python code simply import it and call the exposed methods. The return value of the methods is always of type <class 'dict'>

from doipy import hello, create
from pathlib import Path

# Call the hello operation
response = hello('21.T11969/01370800d56a0d897dc1')

# Call the create operation to create a DO
do_type = 'Document'
do_name = 'my_DO'
md = {'key1': 'value1', 'key2': 'value2'}
authentication_message = {'clientId': '', 'authentication': {'password': ''}}
# other possibilities for authentication messages:
# authentication_message = {authentication': {'username': '', 'password': ''}}
# authentication_message = {authentication': {'token': ''}
create(service='21.T11969/01370800d56a0d897dc1', do_type=do_type, do_name=do_name, bitsq=Path('file.txt'), metadata=md, 
       authentication_message=authentication_message)

Create a Digital Object (currently out of work; to be fixed soon)

To create a Digital Object (DO) in the CLI, first generate an input JSON file (called input.json) whose content follows the below structure:

{
  "file": "myDO_data.txt",
  "md-file": "myDO_md.json"
}

Here, file contains the bit-sequence of the DO and md-filecontains metadata which are written into the PID record. The create operation takes the file input.json and authentication credentials as input to build a DO. Simply run

$ doipy create input.json --client-id <client-id>

and provide the passwort when prompted.

Create a FAIR Digital Object

To create a FAIR Digital Object (FDO) in the CLI, first create a JSON file (called input.json), whose content follows the schema defined at https://typeapi.lab.pidconsortium.net/v1/types/schema/21.T11969/6e36f6c0de5fcab4a425

An example input could look like this:

{
  "FDO_Service_Ref": "21.T11969/01370800d56a0d897dc1",
  "FDO_Profile_Ref": "21.T11969/141bf451b18a79d0fe66",
  "FDO_Authentication": {
    "username": "",
    "password": ""
  },
  "FDO_Type_Ref": "21.1/thisIsAnFdoType",
  "FDO_Rights_Ref": "21.1/thisIsAnFdoRightsSpecification",
  "FDO_Genre_Ref": "21.1/thisIsAnFdoGenre",
  "FDO_Data_and_Metadata": [
    {
      "data_bitsq": "data_bitsq_1.txt",
      "data_values": "data_values_1.json",
      "metadata_bitsq": "metadata_bitsq_1.json",
      "metadata_values": "metadata_values_1.json"
    },
    {
      "data_bitsq": "data_bitsq_2.txt",
      "data_values": "data_values_2.json",
      "metadata_bitsq": "metadata_bitsq_2.json",
      "metadata_values": "metadata_values_2.json"
    }
  ]
}

The create_fdo command supports FDOs which consist of multiple data DOs and multiple metadata DOs, following FDO configuration type 14.

Each item in FDO_Data_and_Metadata is a data bit-sequence data_bitsq and its corresponding metadata bit-sequence metadata_bitsq. One DO is generated for the data bit-sequence and one DO is generated for the metadata bit-sequence. The content of data_values is written into the PID record of the data DO. The content of metadata_values is written into the PID record of the metadata DO.

Use create_fdo to register an FDO with specified (meta)data bit-sequences.

$ doipy create_fdo input.json

For developer

The project is managed by Poetry. Therefore, make sure that Poetry is installed in your system. Then run

$ poetry install

to install all dependencies. With this command, Poetry also installs the package in editable mode.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doipy-0.3.0.tar.gz (19.3 kB view hashes)

Uploaded Source

Built Distribution

doipy-0.3.0-py3-none-any.whl (14.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page