DOIP Client Library - Python Version

A Python client library for the Digital Object Interface Protocol (DOIP).

This DOIP Client Library can be used to develop Python applications that are based on DOIP. It provides a set of classes for interacting with DOIP servers, including methods for making requests and handling responses.

Requirements

Since this is a client library, you will need a DOIP service to connect to. The library itself does not provide a DOIP service. For testing purposes, you can use a local service that implements DOIP, such as Cordra. Setting up such a service is beyond the scope of this README.

This library requires Python 3.12 or later.

Installation

pip install cnri_doip_client

Usage

Create a client instance using the DOIP native TCP interface:

import cnri_doip_client as doip_client

service_info = doip_client.ServiceInfo(ip_address="localhost", port=9000)
client = doip_client.StandardDoipClient(service_info=service_info)

The DOIP API for HTTP Clients is also supported:

import cnri_doip_client as doip_client

client = doip_client.StandardDoipClient("https://localhost:8443/doip"))

Here is an example of searching a Cordra server for all Schema objects, printing out their IDs and names:

results = client.search('type:Schema')
print(f'Number of results: {results.size}')
for result in results:
    print(f'{result.id}: {result.attributes["content"]["name"]}')

Here is an example of retrieving a specific object by ID:

import json
result = client.retrieve('20.500.123/1')
print(json.dumps(result.attributes["content"], indent=2))

Here is an example of creating, updating, and deleting an object. The client is created with a username and password which is used for each request:

import cnri_doip_client as doip_client

password_auth_info = doip_client.PasswordAuthenticationInfo('username', 'password')
service_info = doip_client.ServiceInfo(ip_address="localhost", port=9000)
client = doip_client.StandardDoipClient(
    service_info=service_info, authentication=password_auth_info
)

dobj = doip_client.DigitalObject(
    type="Document",
    attributes={
        "content": {
          "name": 'Example Document'
        }
      }
)
dobj = client.create(dobj)
print(dobj.id)
dobj.attributes["content"]["name"] = 'Updated Example Document'
dobj = client.update(dobj)
print(dobj.attributes["content"]["name"])
client.delete(dobj.id)
dobj = client.retrieve(dobj.id)
print('Delete successful' if dobj is None else 'Error: Object found after deletion')
client.close()

For more information on how to use this library, see the API documentation. You can also read the DOIP Specification for more information about DOIP and its various components; Cordra documentation also includes sections on DOIP and the DOIP API for HTTP Clients.