Archivist Class

Archivist connection interface

This module contains the base Archivist class which manages the connection parameters to a DataTrails instance and the basic REST verbs to GET, POST, PATCH and DELETE entities..

The REST methods in this class should only be used directly when a CRUD endpoint for the specific type of entity is unavailable. Current CRUD endpoints are assets, events, locations, attachments. IAM subjects and IAM access policies.

Instantiation of this class encapsulates the URL and authentication parameters (the max_time parameter is optional):

  with open(".auth_token", mode="r", encoding="utf-8") as tokenfile:
      authtoken = tokenfile.read().strip()

  # Initialize connection to Archivist
  arch = Archivist(
      "https://app.datatrails.ai",
      authtoken,
      max_time=300.0,
  )

The arch variable now has additional endpoints assets,events,locations,
attachments, IAM subjects and IAM access policies documented elsewhere.
class archivist.archivist.Archivist(url: str, auth: str | tuple[str, str] | None, *, fixtures: dict[str, dict[Any, Any]] | None = None, verify: bool = True, max_time: float = 300, partner_id: str = '')[source]

Base class for all Archivist endpoints.

This class manages the connection to an Archivist instance and provides basic methods that represent the underlying REST interface.

Parameters:
  • url (str) -- URL of archivist endpoint

  • auth -- string representing JWT token, or a Tuple pair representing an

  • secret. (Appregistration ID and)

  • verify -- if True the certificate is verified

  • max_time (float) -- maximum time in seconds to wait for confirmation

property Public: ArchivistPublic

Get a Public instance

property auth: str | None

authorization token

Type:

str

delete(url: str, *, headers: dict[str, Any] | None = None) dict[str, Any][source]

DELETE method (REST)

Deletes an entity

Parameters:
  • url (str) -- e.g. v2/assets/xxxxxxxxxxxxxxxxxxxxxxxxxxxx`

  • headers (dict) -- optional REST headers

Returns:

dict representing the response body (entity).

patch(url: str, request: dict[str, Any], *, headers: dict[str, Any] | None = None) dict[str, Any][source]

PATCH method (REST)

Updates the specified entity.

Parameters:
  • url (str) -- e.g. v2/assets/xxxxxxxxxxxxxxxxxxxxxxxxxxxx`

  • request (dict) -- request body defining the entity changes.

  • headers (dict) -- optional REST headers

Returns:

dict representing the response body (entity).

post(url: str, request: dict[str, Any] | None, *, headers: dict[str, Any] | None = None, data: bool = False, no_auth: bool = False) dict[str, Any][source]

POST method (REST)

Creates an entity

Parameters:
  • url (str) -- e.g. v2/assets

  • request (dict) -- request body defining the entity

  • headers (dict) -- optional REST headers

  • data (bool) -- send as form-encoded and not as json

  • no_auth (bool) -- strip authorization from headers

Returns:

dict representing the response body (entity).

post_binary(url: str, request: bytes, *, headers: dict[str, Any] | None = None, no_auth: bool = False) bytes[source]

POST method

Creates an entity

Parameters:
  • url (str) -- e.g. v1/publicscitt/entries

  • request (bytes) -- binary input data

  • headers (dict) -- optional REST headers

  • no_auth (bool) -- strip authorization from headers

Returns:

bytes representing the response data.

post_file(url: str, fd: BinaryIO, mtype: str | None, *, form: str = 'file', params: dict[str, Any] | None = None) dict[str, Any][source]

POST method (REST) - upload binary

Uploads a file to an endpoint

Parameters:
  • url (str) -- e.g. v2/assets

  • fd -- iterable representing the contents of a file.

  • mtype (str) -- mime type e.g. image/jpg

  • params (dict) -- dictionary of optional path params

Returns:

dict representing the response body (entity).

property public: bool

Not a public interface

property root: str

ROOT of Archivist endpoint

Type:

str

property url: str

URL of Archivist endpoint

Type:

str