Attachments Class

Attachments interface

Direct access to the attachments endpoint

The user is not expected to use this class directly. It is an attribute of the Archivist class.

For example instantiate an Archivist instance and execute the methods of the class:

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,
)
with open("something.jpg") as fd:
    attachment = arch.attachments.upload(fd)
class archivist.attachments.Attachment[source]

Attachment object has dictionary attributes.

class archivist.attachments._AttachmentsClient(archivist_instance: Archivist)[source]

AttachmentsClient

Access to attachments entities using CRUD interface. This class is usually accessed as an attribute of the Archivist class.

Parameters:

archivist (Archivist) -- Archivist instance

create(data: dict[str, Any]) dict[str, Any][source]

Create an attachment and return struct suitable for use in an asset or event creation.

Parameters:

data (dict) -- dictionary

A YAML representation of the data argument would be:

filename: functests/test_resources/doors/assets/gdn_front.jpg
content_type: image/jpg
display_name: arc_primary_image

OR

   url: https://secure.eicar.org/eicar.com.zip"
   content_type: application/zip
   display_name: Test malware

Either 'filename' or 'url' is required.
'content_type' is required.
Returns:

A dict suitable for adding to an asset or event creation

A YAML representation of the result would be:

arc_display_name: Telephone
arc_blob_identity: blobs/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
arc_blob_hash_alg: SHA256
arc_blob_hash_value: xxxxxxxxxxxxxxxxxxxxxxx
arc_file_name: gdn_front.jpg
download(identity: str, fd: BinaryIO, *, params: dict[str, Any] | None = None) Response[source]

Read attachment

Reads attachment into data sink (usually a file opened for write).. Note that returns the response as the body will be consumed by the fd iterator

Parameters:
  • identity (str) -- attachment identity e.g. blobs/xxxxxxxxxxxxxxxxxxxxxxx

  • fd (file) -- opened file descriptor or other file-type sink..

  • params (dict) -- e.g. {"allow_insecure": "true"} OR {"strict": "true" }

Returns:

JSON as dict

get_default_key(data: dict[str, str]) str[source]

Return a key to use if no key was provided either use filename or url as one of them is required

info(identity: str) dict[str, Any][source]

Read attachment info

Reads attachment info

Parameters:

identity (str) -- attachment identity e.g. blobs/xxxxxxxxxxxxxxxxxxxxxxx

Returns:

REST response

upload(fd: BinaryIO, *, mtype: str | None = None) Attachment[source]

Create attachment

Creates attachment from opened file or other data source.

Parameters:
  • fd (file) -- opened file descriptor or other file-type iterable.

  • mtype (str) -- mimetype of data.

Returns:

Attachment instance