Tip

Detailed information about the HTTP API of Kadi4Mat itself, including all endpoints and their parameters, can be found in the developer documentation of Kadi4Mat.

Library

The Python library is the most important and most flexible way to use the functionality that kadi-apy provides. The central entry point for most functionality is the KadiManager class. The following shows a basic example on how to use it:

from kadi_apy import KadiManager

manager = KadiManager()

# Retrieve an existing record by its ID.
record = manager.record(id=1)

# Upload a file to the record.
response = record.upload_file("/path/to/file.txt")

Note

Most methods used to interact with resources return a response object as defined in the requests Python library, which can be used to detect whether a request has been successful.

Next to records (Record), it is also possible to interact with other types of resources, namely collections (Collection), templates (Template), groups (Group) and users (User), for example:

# Retrieve an existing collection by its identifier.
collection = manager.collection(identifier="my_collection")

# Create a new template with the given metadata. If the template already exists, it
# will be retrieved by its identifier.
template = manager.template(
    identifier="my_template",
    title="My template",
    create=True,
)

Common methods, namely for searching (Search) as well as miscellaneous functionality (Miscellaneous), are offered directly by corresponding helper classes:

# Perform a search for records.
response = manager.search.search_resources("record")

# Get all deleted resources.
response = manager.misc.get_deleted_resources()

Tip

It is also possible to send individual requests directly using KadiManager.make_request(), while still ensuring a common handling of things like authorization and errors. This method is especially useful for endpoints for which no dedicated functionality exists yet, depending on the versions of kadi-apy and Kadi4Mat itself that are used.

Common conversion functionality is offered via the conversion module. The following shows an example on how to use it:

from kadi_apy import conversion

with open("/path/to/file.json", mode="rb") as f:
    json_data = json.load(f)

# Convert plain JSON to a Kadi4Mat-compatible extra metadata structure.
extras = conversion.json_to_kadi(json_data)

KadiManager

class kadi_apy.lib.core.KadiManager(instance=None, host=None, token=None, verify=True, timeout=60, whitelist=None, verbose=None)[source]

Bases: object

Base manager class for the API.

Manages the host and the personal access token (PAT) to use for all API requests. The KadiManager can instantiate new resources (e.g. records) via factory methods.

Parameters:
  • instance (str, optional) – The name of the instance to use in combination with a config file.

  • host (str, optional) – Name of the host.

  • token (str, optional) – Personal access token.

  • verify (bool, optional) – Whether to verify the SSL/TLS certificate of the host.

  • timeout (float, optional) – Timeout in seconds for the requests.

  • verbose (optional) – Global verbose level to define the amount of prints.

property pat_user

Get the user related to the PAT.

Returns:

The user.

Return type:

User

property misc

Central entry point for miscellaneous functionality.

property search

Central entry point for search functionality.

make_request(endpoint, method='get', **kwargs)[source]

Low level functionality to perform a request.

This function can be used to use endpoints for which no own functions exist yet.

Parameters:
  • endpoint (str) – Endpoint to use for the request.

  • method (str, optional) – Method to use for the request. One of "get", "post", "patch", "put" or "delete".

  • **kwargs – Additional parameters.

Raises:
record(**kwargs)[source]

Init a record.

Parameters:

**kwargs – Parameter for the initialization.

Returns:

The record.

Return type:

Record

Raises:

KadiAPYRequestError – If initializing the record was not successful.

collection(**kwargs)[source]

Init a collection.

Parameters:

**kwargs – Parameter for the initialization.

Returns:

The collection.

Return type:

Collection

Raises:

KadiAPYRequestError – If initializing the collection was not successful.

template(**kwargs)[source]

Init a template.

Parameters:

**kwargs – Parameter for the initialization.

Returns:

The template.

Return type:

Template

Raises:

KadiAPYRequestError – If initializing the template was not successful.

group(**kwargs)[source]

Init a group.

Parameters:

**kwargs – Parameter for the initialization.

Returns:

The group.

Return type:

Group

Raises:

KadiAPYRequestError – If initializing the group was not successful.

user(**kwargs)[source]

Init a user.

Parameters:

**kwargs – Parameter for the initialization.

Returns:

The user.

Return type:

User

Raises:

KadiAPYRequestError – If initializing the user was not successful.

is_verbose(verbose_level=Verbose.INFO)[source]

Check the verbose level.

Parameters:

verbose_level – Local verbose level of the function.

Returns:

True if verbose level is reached, False otherwise.

Return type:

bool

error(text, **kwargs)[source]

Print text for error level.

Parameters:
Return type:

echo()

warning(text, **kwargs)[source]

Print text for warning level.

Parameters:
Return type:

echo()

info(text, **kwargs)[source]

Print text for info level.

Parameters:
Return type:

echo()

debug(text, **kwargs)[source]

Print text for debug level.

Parameters:
Return type:

echo()

echo(text, verbose_level, **kwargs)[source]

Print text via click.echo() if global verbose level is reached.

Parameters:
  • text (str) – Text to be printed via click.echo().

  • verbose_level – Verbose level.

  • **kwargs – Additional parameters for click.echo().

Record

class kadi_apy.lib.resources.records.Record(manager, id=None, identifier=None, skip_request=False, create=False, **kwargs)[source]

Bases: Resource, ExportMixin, PermissionMixin, TagMixin

Model to represent records.

Parameters:
  • manager (KadiManager) – Manager to use for all API requests.

  • id (int, optional) – The ID of an existing resource.

  • identifier (str, optional) – The unique identifier of a new or existing resource, which is only relevant if no ID was given. If present, the identifier will be used to check for an existing resource instead. If no existing resource could be found or the resource to check does not use a unique identifier, it will be used to create a new resource instead, together with the additional metadata. The identifier is adjusted if it contains spaces, invalid characters or exceeds the length of 50 valid characters.

  • skip_request (bool, optional) – Flag to skip the initial request.

  • create (bool, optional) – Flag to determine if a resource should be created in case a identifier is given and the resource does not exist.

  • **kwargs (dict) – Additional metadata of the new resource to create.

Add a record to a collection.

Parameters:

collection_id (int) – The ID of the collection to which the record should be added.

Returns:

The response object.

Remove a record from a collection.

Parameters:

collection_id (int) – The ID of the collection from which the record should be removed.

Returns:

The response object.

check_metadatum(metadatum)[source]

Check if a record has a certain metadatum.

Does currently not support metadata in nested types.

Parameters:

metadatum (str) – The metadatum to check.

Returns:

True if the metadatum exists, otherwise False.

Return type:

bool

add_metadatum(metadatum, force=False)[source]

Add metadatum to a record.

Validation supports currently no nested metadata.

Parameters:
  • metadatum (dict) – The metadatum to add.

  • force (bool) – Whether to overwrite the metadatum with the new value in case the metadatum already exists.

Returns:

The response object.

add_metadata(metadata_new, force=False, callback=None)[source]

Add metadata to a record.

Validation supports currently no nested metadata.

Parameters:
  • metadata_new (dict, list) – One or more metadata entries to add, either as dictionary or a list of dictionaries.

  • force (bool) – Whether to overwrite the metadatum with the new value in case the metadatum already exists.

  • callback (optional) – Callback function.

Returns:

The response object.

remove_metadatum(metadatum)[source]

Remove a metadatum from a record.

Only first level metadata are supported (no nested types).

Parameters:

metadatum (str) – The metadatum to remove.

Returns:

The response object.

remove_all_metadata()[source]

Remove all metadata from a record.

Returns:

The response object.

upload_file(file_path, file_name=None, file_description=None, force=False)[source]

Upload a file to a record.

Parameters:
  • file_path (str) – The path to the file (incl. name of the file).

  • file_name (str, optional) – The name under which the file should be stored. If no name is given, the name is taken from the file path.

  • file_description (str, optional) – The description of the file.

  • force (bool, optional) – Whether to replace an existing file with identical name.

Returns:

The final response object of the upload process.

upload_string_to_file(string, file_name, file_description=None, force=False)[source]

Upload a string to save as a file in a record.

Parameters:
  • string (str) – The string to save as a file.

  • file_name (str) – The name under which the file should be stored.

  • file_description (str, optional) – The description of the file.

  • force (bool, optional) – Whether to replace an existing file with identical name.

Returns:

The final response object of the upload process.

download_file(file_id, file_path)[source]

Download a file of a record.

Parameters:
  • file_id (str) – The file ID of the file to download.

  • file_path (str) – The full path to store the file.

Returns:

The response object.

download_all_files(file_path)[source]

Download all files of a record as ZIP archive.

Parameters:

file_path (str) – The full path to store the archive.

Returns:

The response object.

get_file_revisions(**params)[source]

Get the file revisions of a file in this record.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_file_revision(revision_id, **params)[source]

Get a specific file revision of a file in this record.

Parameters:
  • revision_id (int) – The revision ID of the file.

  • **params – Additional parameters.

Returns:

The response object.

get_record_revisions(**params)[source]

Get the revisions of this record.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_record_revision(revision_id, **params)[source]

Get a specific revision of this record.

Parameters:
  • revision_id (int) – The revision ID of the record.

  • **params – Additional parameters.

Returns:

The response object.

get_users(**params)[source]

Get users from a record. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_groups(**params)[source]

Get group roles from a record. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_filelist(**params)[source]

Get the filelist. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_number_files()[source]

Get number of all files of a record.

Returns:

The number of files.

Return type:

int

Raises:

KadiAPYRequestError – If request was not successful.

get_file_name(file_id)[source]

Get file name from a given file ID.

Parameters:

file_id – The ID of the file.

Returns:

The name of the file.

Return type:

str

Raises:

KadiAPYInputError – If no file with the given file ID exists.

get_metadatum(name)[source]

Return a specific metadatum.

Parameters:

name (str or list) – Either a single key as a string or a list of strings for nested metadata. Note that for list values, the keys are replaced by corresponding indices, also as string, starting at 1.

Returns:

The metadatum or None if it could not be found.

Link record.

Parameters:
  • record_to (int) – The ID of the record to link.

  • name (str) – The name of the link.

  • term_iri (str) – An IRI specifying an existing term that the link should represent.

Returns:

The response object.

Delete a record link.

Parameters:

record_link_id (int) – The ID of the record link to delete. Attention: The record link ID is not the record ID.

Returns:

The response object.

Update the name of record link.

Parameters:
  • record_link_id (int) – The ID of the record link to update. Attention: The record link ID is not the record ID.

  • **kwargs – The metadata to update the record link with.

Returns:

The response object.

Get record links. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

Get collection links. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_file_id(file_name)[source]

Get the file ID based on the file name.

Parameters:

file_name (str) – Additional parameters.

Returns:

The file ID (UUID).

Return type:

str

Raises:

KadiAPYInputError – If no file with the given name exists.

get_file_info(file_id)[source]

Get information of a file based on the file_id.

Parameters:

file_id (str) – The ID of the file.

Returns:

The response object.

has_file(file_name)[source]

Check if file with the given name already exists.

Parameters:

file_name (str) – The name of the file.

Returns:

True if file already exists, otherwise False.

edit_file(file_id, **kwargs)[source]

Edit the metadata of a file of the record.

Parameters:
  • file_id (str) – The ID (UUID) of the file to edit.

  • **kwargs – The metadata to update the file with.

Returns:

The response object.

delete_file(file_id)[source]

Delete a file of the record.

Parameters:

file_id (str) – The ID (UUID) of the file to delete.

Returns:

The response object.

flatten_extras(separator='.')[source]

Create a list of flatted metadata.

Parameters:

separator (str, optional) – A string for separating the metadata.

Returns:

A list of flatted metadata.

Return type:

list

add_group_role(group_id, role_name)

Add a group role.

Parameters:
  • group_id (int) – The ID of the group to add.

  • role_name (str) – Role of the group.

Returns:

The response object.

add_tag(tag)

Add a tag.

Parameters:

tag (str) – The tag to add.

Returns:

The response object.

add_user(user_id, role_name)

Add a user role.

Parameters:
  • user_id (int) – The ID of the user to add.

  • role_name (str) – Role of the User.

Returns:

The Response object.

change_group_role(group_id, role_name)

Change group role.

Parameters:
  • group_id (int) – The ID of the group whose role should be changed.

  • role_name (str) – Name of the new role.

Returns:

The response object.

change_user_role(user_id, role_name)

Change user role.

Parameters:
  • user_id (int) – The ID of the user whose role should be changed.

  • role_name (str) – Name of the new role.

Returns:

The response object.

check_tag(tag)

Check if a certain tag is already present.

Parameters:

tag (str) – The tag to check.

Returns:

True if tag already exists, otherwise False.

Return type:

bool

debug(text, **kwargs)

Print text for debug level.

Parameters:
delete()

Delete the resource.

Returns:

The response object.

edit(**kwargs)

Edit the metadata of the resource.

Parameters:

**kwargs – The updated metadata of the resource.

Returns:

The response object.

error(text, **kwargs)

Print text for error level.

Parameters:
export(path, export_type='json', pipe=False, **params)

Export a resource using a specific export type.

Parameters:
  • path (str) – The path (including name of the file) to store the exported data.

  • export_type (str) – The export format.

  • pipe (bool) – If True, nothing is written here.

  • **params – Additional parameters.

Returns:

The response object.

get_tags()

Get tags.

Returns:

A list of all tags.

Type:

list

info(text, **kwargs)

Print text for info level.

Parameters:
is_verbose(**kwargs)

Check the verbose level.

Returns:

See KadiManager.is_verbose().

property meta

Get all metadata of the resource.

In case the previous metadata was invalidated, either manually, after a timeout or due to another request, a request will be sent to retrieve the possibly updated metadata again.

Returns:

The metadata of the resource.

Raises:

KadiAPYRequestError – If requesting the metadata was not successful.

remove_group_role(group_id)

Remove a group role.

Parameters:

group_id (int) – The ID of the group to remove.

Returns:

The response object.

remove_tag(tag)

Remove a tag.

Parameters:

tag (str) – The tag to remove.

Returns:

The response object.

remove_user(user_id)

Remove a user role.

Parameters:

user_id (int) – The ID of the user to remove.

Returns:

The response object.

set_attribute(attribute, value)

Set attribute.

Parameters:
  • attribute (str) – The attribute to set.

  • value – The value of the attribute.

Returns:

The response object.

warning(text, **kwargs)

Print text for warning level.

Parameters:

Collection

class kadi_apy.lib.resources.collections.Collection(manager, id=None, identifier=None, skip_request=False, create=False, **kwargs)[source]

Bases: Resource, ExportMixin, PermissionMixin, TagMixin

Model to represent collections.

Parameters:
  • manager (KadiManager) – Manager to use for all API requests.

  • id (int, optional) – The ID of an existing resource.

  • identifier (str, optional) – The unique identifier of a new or existing resource, which is only relevant if no ID was given. If present, the identifier will be used to check for an existing resource instead. If no existing resource could be found or the resource to check does not use a unique identifier, it will be used to create a new resource instead, together with the additional metadata. The identifier is adjusted if it contains spaces, invalid characters or exceeds the length of 50 valid characters.

  • skip_request (bool, optional) – Flag to skip the initial request.

  • create (bool, optional) – Flag to determine if a resource should be created in case a identifier is given and the resource does not exist.

  • **kwargs (dict) – Additional metadata of the new resource to create.

get_users(**params)[source]

Get user of a collection. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_groups(**params)[source]

Get group roles from a collection. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

Add a record to a collection.

Parameters:

record_id (int) – The ID of the record to add.

Returns:

The response object.

Remove a record from a collection.

Parameters:

record_id (int) – The ID of the record to remove.

Returns:

The response object.

get_records(**params)[source]

Get records from a collection. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_collections(**params)[source]

Get collections linked with a collection id.

Parameters:

**params – Additional parameters.

Returns:

The response object.

Add a child collection to a parent collection.

Parameters:

collection_id (int) – The ID of a child collection to which the parent collection should be added.

Returns:

The response object.

Remove a child collection from a parent collection.

Parameters:

collection_id (int) – The ID of the child collection to be removed from the parent collection.

Returns:

The response object.

get_collection_revisions(**params)[source]

Get the revisions of this collection.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_collection_revision(revision_id, **params)[source]

Get a specific revision of this collection.

Parameters:
  • revision_id (int) – The revision ID of the collection.

  • **params – Additional parameters.

Returns:

The response object.

add_group_role(group_id, role_name)

Add a group role.

Parameters:
  • group_id (int) – The ID of the group to add.

  • role_name (str) – Role of the group.

Returns:

The response object.

add_tag(tag)

Add a tag.

Parameters:

tag (str) – The tag to add.

Returns:

The response object.

add_user(user_id, role_name)

Add a user role.

Parameters:
  • user_id (int) – The ID of the user to add.

  • role_name (str) – Role of the User.

Returns:

The Response object.

change_group_role(group_id, role_name)

Change group role.

Parameters:
  • group_id (int) – The ID of the group whose role should be changed.

  • role_name (str) – Name of the new role.

Returns:

The response object.

change_user_role(user_id, role_name)

Change user role.

Parameters:
  • user_id (int) – The ID of the user whose role should be changed.

  • role_name (str) – Name of the new role.

Returns:

The response object.

check_tag(tag)

Check if a certain tag is already present.

Parameters:

tag (str) – The tag to check.

Returns:

True if tag already exists, otherwise False.

Return type:

bool

debug(text, **kwargs)

Print text for debug level.

Parameters:
delete()

Delete the resource.

Returns:

The response object.

edit(**kwargs)

Edit the metadata of the resource.

Parameters:

**kwargs – The updated metadata of the resource.

Returns:

The response object.

error(text, **kwargs)

Print text for error level.

Parameters:
export(path, export_type='json', pipe=False, **params)

Export a resource using a specific export type.

Parameters:
  • path (str) – The path (including name of the file) to store the exported data.

  • export_type (str) – The export format.

  • pipe (bool) – If True, nothing is written here.

  • **params – Additional parameters.

Returns:

The response object.

get_tags()

Get tags.

Returns:

A list of all tags.

Type:

list

info(text, **kwargs)

Print text for info level.

Parameters:
is_verbose(**kwargs)

Check the verbose level.

Returns:

See KadiManager.is_verbose().

property meta

Get all metadata of the resource.

In case the previous metadata was invalidated, either manually, after a timeout or due to another request, a request will be sent to retrieve the possibly updated metadata again.

Returns:

The metadata of the resource.

Raises:

KadiAPYRequestError – If requesting the metadata was not successful.

remove_group_role(group_id)

Remove a group role.

Parameters:

group_id (int) – The ID of the group to remove.

Returns:

The response object.

remove_tag(tag)

Remove a tag.

Parameters:

tag (str) – The tag to remove.

Returns:

The response object.

remove_user(user_id)

Remove a user role.

Parameters:

user_id (int) – The ID of the user to remove.

Returns:

The response object.

set_attribute(attribute, value)

Set attribute.

Parameters:
  • attribute (str) – The attribute to set.

  • value – The value of the attribute.

Returns:

The response object.

warning(text, **kwargs)

Print text for warning level.

Parameters:

Template

class kadi_apy.lib.resources.templates.Template(manager, id=None, identifier=None, skip_request=False, create=False, **kwargs)[source]

Bases: Resource, ExportMixin, PermissionMixin

Model to represent templates.

Parameters:
  • manager (KadiManager) – Manager to use for all API requests.

  • type (str) – Type of the template. Can either be record or extras.

  • data – Dict in case of a record template or a list in case of a extras template containing the content for the template.

  • id (int, optional) – The ID of an existing resource.

  • identifier (str, optional) – The unique identifier of a new or existing resource, which is only relevant if no ID was given. If present, the identifier will be used to check for an existing resource instead. If no existing resource could be found or the resource to check does not use a unique identifier, it will be used to create a new resource instead, together with the additional metadata. The identifier is adjusted if it contains spaces, invalid characters or exceeds the length of 50 valid characters.

  • skip_request (bool, optional) – Flag to skip the initial request.

  • create (bool, optional) – Flag to determine if a resource should be created in case a identifier is given and the resource does not exist.

  • **kwargs (dict) – Additional metadata of the new resource to create.

get_users(**params)[source]

Get users from a template. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_template_revisions(**params)[source]

Get the revisions of this template.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_template_revision(revision_id, **params)[source]

Get a specific revision of this template.

Parameters:
  • revision_id (int) – The revision ID of the template.

  • **params – Additional parameters.

Returns:

The response object.

get_groups(**params)[source]

Get group roles from a template. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

add_group_role(group_id, role_name)

Add a group role.

Parameters:
  • group_id (int) – The ID of the group to add.

  • role_name (str) – Role of the group.

Returns:

The response object.

add_user(user_id, role_name)

Add a user role.

Parameters:
  • user_id (int) – The ID of the user to add.

  • role_name (str) – Role of the User.

Returns:

The Response object.

change_group_role(group_id, role_name)

Change group role.

Parameters:
  • group_id (int) – The ID of the group whose role should be changed.

  • role_name (str) – Name of the new role.

Returns:

The response object.

change_user_role(user_id, role_name)

Change user role.

Parameters:
  • user_id (int) – The ID of the user whose role should be changed.

  • role_name (str) – Name of the new role.

Returns:

The response object.

debug(text, **kwargs)

Print text for debug level.

Parameters:
delete()

Delete the resource.

Returns:

The response object.

edit(**kwargs)

Edit the metadata of the resource.

Parameters:

**kwargs – The updated metadata of the resource.

Returns:

The response object.

error(text, **kwargs)

Print text for error level.

Parameters:
export(path, export_type='json', pipe=False, **params)

Export a resource using a specific export type.

Parameters:
  • path (str) – The path (including name of the file) to store the exported data.

  • export_type (str) – The export format.

  • pipe (bool) – If True, nothing is written here.

  • **params – Additional parameters.

Returns:

The response object.

info(text, **kwargs)

Print text for info level.

Parameters:
is_verbose(**kwargs)

Check the verbose level.

Returns:

See KadiManager.is_verbose().

property meta

Get all metadata of the resource.

In case the previous metadata was invalidated, either manually, after a timeout or due to another request, a request will be sent to retrieve the possibly updated metadata again.

Returns:

The metadata of the resource.

Raises:

KadiAPYRequestError – If requesting the metadata was not successful.

remove_group_role(group_id)

Remove a group role.

Parameters:

group_id (int) – The ID of the group to remove.

Returns:

The response object.

remove_user(user_id)

Remove a user role.

Parameters:

user_id (int) – The ID of the user to remove.

Returns:

The response object.

set_attribute(attribute, value)

Set attribute.

Parameters:
  • attribute (str) – The attribute to set.

  • value – The value of the attribute.

Returns:

The response object.

warning(text, **kwargs)

Print text for warning level.

Parameters:

Group

class kadi_apy.lib.resources.groups.Group(manager, id=None, identifier=None, skip_request=False, create=False, **kwargs)[source]

Bases: Resource

Model to represent groups.

Parameters:
  • manager (KadiManager) – Manager to use for all API requests.

  • id (int, optional) – The ID of an existing resource.

  • identifier (str, optional) – The unique identifier of a new or existing resource, which is only relevant if no ID was given. If present, the identifier will be used to check for an existing resource instead. If no existing resource could be found or the resource to check does not use a unique identifier, it will be used to create a new resource instead, together with the additional metadata. The identifier is adjusted if it contains spaces, invalid characters or exceeds the length of 50 valid characters.

  • skip_request (bool, optional) – Flag to skip the initial request.

  • create (bool, optional) – Flag to determine if a resource should be created in case a identifier is given and the resource does not exist.

  • **kwargs (dict) – Additional metadata of the new resource to create.

get_records(**params)[source]

Get records shared with a group. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_collections(**params)[source]

Get collections shared with a group. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_templates(**params)[source]

Get templates shared with a group. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_users(**params)[source]

Get users of a group. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

add_user(user_id, role_name)[source]

Add a user.

Parameters:
  • user_id (int) – The ID of the user to add.

  • role_name (str) – Role of the user.

Returns:

The response object.

remove_user(user_id)[source]

Remove a user.

Parameters:

user_id (int) – The ID of the user to remove.

Returns:

The response object.

get_group_revisions(**params)[source]

Get the revisions of this group.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_group_revision(revision_id, **params)[source]

Get a specific revision from this group.

Parameters:
  • revision_id (int) – The revision ID of the group.

  • **params – Additional parameters.

Returns:

The response object.

change_user_role(user_id, role_name)[source]

Change role of a user.

Parameters:
  • user_id (int) – The ID of the user whose role should be changed.

  • role_name (str) – Name of the new role.

Returns:

The response object.

debug(text, **kwargs)

Print text for debug level.

Parameters:
delete()

Delete the resource.

Returns:

The response object.

edit(**kwargs)

Edit the metadata of the resource.

Parameters:

**kwargs – The updated metadata of the resource.

Returns:

The response object.

error(text, **kwargs)

Print text for error level.

Parameters:
info(text, **kwargs)

Print text for info level.

Parameters:
is_verbose(**kwargs)

Check the verbose level.

Returns:

See KadiManager.is_verbose().

property meta

Get all metadata of the resource.

In case the previous metadata was invalidated, either manually, after a timeout or due to another request, a request will be sent to retrieve the possibly updated metadata again.

Returns:

The metadata of the resource.

Raises:

KadiAPYRequestError – If requesting the metadata was not successful.

set_attribute(attribute, value)

Set attribute.

Parameters:
  • attribute (str) – The attribute to set.

  • value – The value of the attribute.

Returns:

The response object.

warning(text, **kwargs)

Print text for warning level.

Parameters:

User

class kadi_apy.lib.resources.users.User(manager, id=None, username=None, identity_type=None, use_pat=False)[source]

Bases: ResourceMeta

Model to represent users.

A user can either be clearly identified via its id or the combination of username and identity type.

Parameters:
  • manager (KadiManager) – Manager to use for all API requests.

  • id (int, optional) – The ID of an existing user.

  • username (str, optional) – The username.

  • identity_type (str, optional) – The identity type of the user.

  • use_pat (bool, optional) – Flag to indicate that the pat stored in the KadiManager should be used for instantiating the user.

Raises:

KadiAPYRequestError – If retrieving the user was not successful.

debug(text, **kwargs)

Print text for debug level.

Parameters:
error(text, **kwargs)

Print text for error level.

Parameters:
info(text, **kwargs)

Print text for info level.

Parameters:
is_verbose(**kwargs)

Check the verbose level.

Returns:

See KadiManager.is_verbose().

property meta

Get all metadata of the resource.

In case the previous metadata was invalidated, either manually, after a timeout or due to another request, a request will be sent to retrieve the possibly updated metadata again.

Returns:

The metadata of the resource.

Raises:

KadiAPYRequestError – If requesting the metadata was not successful.

warning(text, **kwargs)

Print text for warning level.

Parameters:

Miscellaneous

class kadi_apy.lib.misc.Miscellaneous(manager)[source]

Bases: RequestMixin, VerboseMixin

Model to handle miscellaneous functionality.

Parameters:

manager (KadiManager) – Manager to use for all API requests.

get_deleted_resources(**params)[source]

Get a list of deleted resources in the trash. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

restore(item, item_id)[source]

Restore an item from the trash.

Parameters:
  • item – The resource type defined either as string or class.

  • item_id (int) – The ID of the item to restore.

Returns:

The response object.

purge(item, item_id)[source]

Purge an item from the trash.

Parameters:
  • item – The resource type defined either as string or class.

  • item_id (int) – The ID of the item to restore.

Returns:

The response object.

get_licenses(**params)[source]

Get a list of available licenses. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

get_kadi_info()[source]

Get information about the Kadi instance.

Returns:

The response object.

get_roles()[source]

Get all possible roles and corresponding permissions of all resources.

Returns:

The response object.

get_tags(**params)[source]

Get a list of all tags. Supports pagination.

Parameters:

**params – Additional parameters.

Returns:

The response object.

import_eln(file_path)[source]

Import an RO-Crate file following the “ELN” file specification.

Parameters:

file_path (str) – The path of the file.

Raises:
import_json_schema(file_path, template_type='extras')[source]

Import JSON Schema file and create a template.

Note that only JSON Schema draft 2020-12 is fully supported, but older schemas might still work.

Parameters:
  • file_path (str) – The path of the file.

  • template_type (str) – Type of the template. Can either be "record" or "extras".

Raises:
debug(text, **kwargs)

Print text for debug level.

Parameters:
error(text, **kwargs)

Print text for error level.

Parameters:
info(text, **kwargs)

Print text for info level.

Parameters:
is_verbose(**kwargs)

Check the verbose level.

Returns:

See KadiManager.is_verbose().

warning(text, **kwargs)

Print text for warning level.

Parameters:

Exceptions

exception kadi_apy.lib.exceptions.KadiAPYException[source]

Bases: Exception

Base exception class.

exception kadi_apy.lib.exceptions.KadiAPYConfigurationError[source]

Bases: KadiAPYException

For errors relating to invalid configurations.

exception kadi_apy.lib.exceptions.KadiAPYRequestError[source]

Bases: KadiAPYException

For errors relating to invalid requests.

exception kadi_apy.lib.exceptions.KadiAPYInputError[source]

Bases: KadiAPYException

For errors relating to invalid inputs.

Conversion

kadi_apy.lib.conversion.json_to_kadi(data)[source]

Convert plain JSON to a Kadi4Mat-compatible extra metadata structure.

Parameters:

data – The JSON data to convert as dictionary, list or singular, primitive value.

Returns:

The converted data as a list of extra metadata.