Note
Note that this library targets the stable version v1
of the HTTP API of
Kadi4Mat. Detailed information about the API itself, including all endpoints and
their parameters, can be found in the developer documentation of Kadi4Mat.
CLI Library
The Python CLI library is mainly useful to implement custom CLI commands. The provided functionality is usually less flexible in comparison with the regular Python library, but it also provides some built-in error handling and console output.
In general, its functionality can be used similarly to the regular Python library:
from kadi_apy import CLIKadiManager
manager = CLIKadiManager()
record = manager.record(id=1)
record.upload_file("/path/to/file.txt")
CLIKadiManager
- class kadi_apy.cli.core.CLIKadiManager(verbose=Verbose.INFO, **kwargs)[source]
Bases:
KadiManager
,RaiseRequestErrorMixin
Kadi Manager for the command line interface (CLI).
See
KadiManager
for the possible parameters.- property misc
Central entry point for miscellaneous functionality.
- property search
Central entry point for search functionality.
- record(use_base_resource=False, **kwargs)[source]
Init a record to be used in a CLI.
- Parameters:
use_base_resource (bool) – Flag indicating if the base resource should be used.
- Returns:
The record of class Record or CLIRecord.
- Return type:
- Raises:
KadiAPYRequestError – If initializing the record was not successful.
- collection(use_base_resource=False, **kwargs)[source]
Init a collection to be used in a CLI.
- Parameters:
use_base_resource (bool) – Flag indicating if the base resource should be used.
- Returns:
The collection of class Collection or CLICollection.
- Return type:
- Raises:
KadiAPYRequestError – If initializing the collection was not successful.
- template(use_base_resource=False, **kwargs)[source]
Init a template to be used in a CLI.
- Parameters:
use_base_resource (bool) – Flag indicating if the base resource should be used.
- Returns:
The template of class Template or CLITemplate.
- Return type:
- Raises:
KadiAPYRequestError – If initializing the template was not successful.
- group(use_base_resource=False, **kwargs)[source]
Init a group to be used in a CLI.
- Parameters:
use_base_resource (bool) – Flag indicating if the base resource should be used.
- Returns:
The group of class Group or CLIGroup.
- Return type:
- Raises:
KadiAPYRequestError – If initializing the group was not successful.
- user(use_base_resource=False, **kwargs)[source]
Init a user to be used in a CLI.
- Parameters:
use_base_resource (bool) – Flag indicating if the base resource should be used.
- Returns:
The user of class User or CLIUser.
- Return type:
- Raises:
KadiAPYRequestError – If initializing the user was not successful.
- debug(text, **kwargs)
Print text for debug level.
- Parameters:
text – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- Return type:
- echo(text, verbose_level, **kwargs)
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 arguments to pass to
click.echo()
.
- error(text, **kwargs)
Print text for error level.
- Parameters:
text – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- Return type:
- info(text, **kwargs)
Print text for info level.
- Parameters:
text – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- Return type:
- is_verbose(verbose_level=Verbose.INFO)
Check the verbose level.
- Parameters:
verbose_level – Local verbose level of the function.
- Returns:
True
if verbose level is reached,False
otherwise.- Return type:
- make_request(endpoint, method='get', **kwargs)
Low level functionality to perform a request.
This function can be used to use endpoints for which no own functions exist yet.
- Parameters:
- Raises:
KadiAPYInputError – If the specified method is invalid.
KadiAPYRequestError – If the server answered with an invalid redirection.
- raise_request_error(response)
Raise exception.
- Parameters:
response – The response.
- Raises:
KadiAPYRequestError – Error is raised since request was not successful.
- warning(text, **kwargs)
Print text for warning level.
- Parameters:
text – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- Return type:
CLIRecord
- class kadi_apy.cli.lib.records.CLIRecord(pipe=False, title=None, create=False, exit_not_created=False, **kwargs)[source]
Bases:
BasicCLIMixin
,UserCLIMixin
,GroupRoleCLIMixin
,TagCLIMixin
,DeleteItemCLIMixin
,ExportCLIMixin
,Record
,RaiseRequestErrorMixin
Records class to be used in a CLI.
- Parameters:
manager – See
Record
.id – See
Record
.identifier – See
Record
.skip_request – See
Record
.create – See
Record
.pipe (bool, optional) – Flag to indicate if only the id should be printed which can be used for piping.
title (str, optional) – Title of the new resource.
exit_not_created (bool, optional) – Flag to indicate if the function should exit with
sys.exit(1)
if the resource is not created.
- upload_file(file_name, file_description=None, pattern=None, exclude_pattern=None, force=False)[source]
Upload files into a record using the CLI.
- Parameters:
file_name (str) – The path to the file (incl. name of the file) or folder.
file_description (str, optional) – The description of a single file.
pattern (str, optional) – Pattern for selecting files matching certain pattern.
exclude_pattern (str, optional) – Pattern for excluding files matching certain pattern.
force (bool, optional) – Whether to replace an existing file with identical name.
- Raises:
KadiAPYRequestError – If request was not successful.
- upload_string_to_file(string, file_name, file_description=None, force=False)[source]
Upload a string to save as a file in a record using the CLI.
- Parameters:
- Raises:
KadiAPYRequestError – If request was not successful.
- add_metadatum(metadatum_new, force=False)[source]
Add a metadatum to a record using the CLI.
- Parameters:
- Raises:
KadiAPYRequestError – If request was not successful.
- add_metadata(metadata=None, file=None, force=False)[source]
Add metadata with dict or a list of dicts as input using the CLI.
Either specify the metadata via a file to be read from or via metadata.
- Parameters:
- Raises:
KadiAPYRequestError – If request was not successful.
- get_file(filepath, force=False, file_id=None, pattern=None, exclude_pattern=None, use_folder=False, pipe=False)[source]
Download one or multiple files of a record using the CLI.
If a file ID is given, the specified file is download. Otherwise all files or all files matching the pattern are downloaded.
- Parameters:
filepath (str) – The path to folder to store the file.
force (bool, optional) – Whether to overwrite a file with identical name.
file_id (bool, optional) – The file ID (UUID) of a file to download.
pattern (str, optional) – Pattern for selecting files matching certain pattern.
exclude_pattern (str, optional) – Pattern for selecting files matching certain pattern.
use_folder (bool, optional) – Flag indicating if the a folder with the name of the record’s identifier should be created within given filepath. The downloaded file(s) are stored in this folder.
- Returns:
A list of downloaded files with file path.
- Type:
- Raises:
KadiAPYRequestError – If request was not successful.
- link_record(record_to, name, term_iri=None)[source]
Add a record link to a record using the CLI.
- Parameters:
- Raises:
KadiAPYRequestError – If request was not successful.
- delete_record_link(record_link_id)[source]
Delete a record link using the CLI.
- Parameters:
record_link_id (int) – The ID of the record link to delete. Attention: The record link ID is not the record ID.
- Raises:
KadiAPYRequestError – If request was not successful.
- get_record_links(page, per_page, direction)[source]
Print record links to another record using the CLI.
- Parameters:
- Raises:
KadiAPYRequestError – If request was not successful.
- get_metadatum(name, information='value', pipe=False)[source]
Print information of a specific metadatum using the CLI.
- Parameters:
name (str or list) – See
Record.get_metadatum()
.information (str, optional) – The information of the metadatum to print.
pipe (bool) – Whether to only print the result for piping.
- Raises:
KadiAPYRequestError – If request was not successful.
- edit_file(file, name, mimetype)[source]
Edit the metadata of a file of a record using the CLI.
- Parameters:
- Raises:
KadiAPYRequestError – If request was not successful.
- delete_file(file_id)[source]
Delete a file of the record using the CLI.
- Parameters:
file_id (str) – The ID (UUID) of the file to delete.
- Raises:
KadiAPYRequestError – If request was not successful.
- delete_files(i_am_sure=False)[source]
Delete all files of a record using the CLI.
- Parameters:
i_am_sure (bool) – Flag which has to set to
True
to delete all files.- Raises:
KadiAPYInputError – If i_am_sure is not
True
.KadiAPYRequestError – If request was not successful.
- remove_metadatum(metadatum)[source]
Delete a metadatum of a record using the CLI.
Only first level metadata are supported (no nested types).
- Parameters:
metadatum (str) – The metadatum to remove.
- Raises:
KadiAPYRequestError – If request was not successful.
- remove_all_metadata(i_am_sure=False)[source]
Remove all metadata from a record.
- Parameters:
i_am_sure (bool) – Flag which has to set to
True
to remove all metadata.- Raises:
KadiAPYRequestError – If request was not successful.
- add_collection_link(collection)[source]
Add a record to a collection using the CLI.
- Parameters:
collection (Collection) – The collection to which the record should be added.
- Raises:
KadiAPYRequestError – If request was not successful.
- remove_collection_link(collection)[source]
Remove a record from a collection using the CLI.
- Parameters:
collection (Collection) – The collection from which the record should be removed.
- Raises:
KadiAPYRequestError – If request was not successful.
- update_record_link(record_link_id, name)[source]
Update the name of a record link using the CLI.
- Parameters:
- Raises:
KadiAPYRequestError – If request was not successful.
- print_info(**kwargs)[source]
Print infos of a record using the CLI.
- Parameters:
**kwargs – Specify additional infos to print.
- Raises:
KadiAPYRequestError: If request was not successful
- export_metadata(export_type, path='.', name=None, force=False, pipe=False, use_folder=False, **params)[source]
Export the extra metadata of a record using the CLI.
- Parameters:
export_type (str) – The export format.
path (str, optional) – The path to store.
name (str, optional) – The name of the file. The identifier is used as default.
force (bool, optional) – Whether to replace an existing file with identical name.
pipe (bool, optional) – Flag to indicate if json should be piped.
use_folder – Flag indicating if the a folder with the name of the resource’s identifier should be created within given path. The exported file is stored in this folder.
**params – Additional query parameters.
- Raises:
KadiAPYInputError – If export type is invalid or if not json is used as input type together with pipe.
KadiAPYRequestError – If request was not successful.
- add_group_role(group, permission_new)
Add a group role.
- add_tag(tag)
Add a tag using a CLI.
- Parameters:
tag (str) – The tag to add.
- Raises:
KadiAPYRequestError – If request was not successful.
- add_user(user, permission_new)
Add a user.
- change_group_role(group_id, role_name)
Change group role.
- change_user_role(user_id, role_name)
Change user role.
- check_metadatum(metadatum)
Check if a record has a certain metadatum.
Does currently not support metadata in nested types.
- check_tag(tag)
Check if a certain tag is already present.
- debug(text, **kwargs)
Print text for debug level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- delete(i_am_sure)
Delete the resource using a CLI.
- Parameters:
i_am_sure (bool) – Flag which has to set to
True
to delete the resource.- Raises:
KadiAPYInputError – If i_am_sure is not
True
.KadiAPYRequestError – If request was not successful.
- download_all_files(file_path)
Download all files of a record as ZIP archive.
- Parameters:
file_path (str) – The full path to store the archive.
- Returns:
The response object.
- download_file(file_id, file_path=None)
Download a file of a record.
- 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:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- export(export_type, path='.', name=None, force=False, pipe=False, use_folder=False, **params)
Export the resource using a specific export type using the CLI.
- Parameters:
export_type (str) – The export format.
path (str, optional) – The path to store.
name (str, optional) – The name of the file. The identifier is used as default.
force (bool, optional) – Whether to replace an existing file with identical name.
pipe (bool, optional) – Flag to indicate if json should be piped.
use_folder – Flag indicating if the a folder with the name of the resource’s identifier should be created within given path. The exported file is stored in this folder.
**params – Additional query parameters.
- Raises:
KadiAPYInputError – If export type is invalid or if not json is used as input type together with pipe.
KadiAPYRequestError – If request was not successful.
- flatten_extras(separator='.')
Create a list of flattened metadata.
- get_collection_links(**params)
Get collection links. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_file_id(file_name)
Get the file ID based on the file name.
- Parameters:
file_name (str) – The name of the file.
- Returns:
The file ID (UUID).
- Return type:
- Raises:
KadiAPYInputError – If no file with the given name exists.
- get_file_info(file_id)
Get information of a file based on the file_id.
- Parameters:
file_id (str) – The ID of the file.
- Returns:
The response object.
- get_file_name(file_id)
Get file name from a given file ID.
- Parameters:
file_id – The ID of the file.
- Returns:
The name of the file.
- Return type:
- Raises:
KadiAPYInputError – If no file with the given file ID exists.
- get_file_revision(revision_id, **params)
Get a specific file revision of a file in this record.
- Parameters:
revision_id (int) – The revision ID of the file.
**params – Additional query parameters.
- Returns:
The response object.
- get_file_revisions(**params)
Get the file revisions of a file in this record.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_filelist(**params)
Get the filelist. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_groups(**params)
Get group roles from a record. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_number_files()
Get number of all files of a record.
- Returns:
The number of files.
- Return type:
- Raises:
KadiAPYRequestError – If request was not successful.
- get_record_revision(revision_id, **params)
Get a specific revision of this record.
- Parameters:
revision_id (int) – The revision ID of the record.
**params – Additional query parameters.
- Returns:
The response object.
- get_record_revisions(**params)
Get the revisions of this record.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_users(**params)
Get users from a record. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- has_file(file_name)
Check if file with the given name already exists.
- Parameters:
file_name (str) – The name of the file.
- Returns:
True
if file already exists, otherwiseFalse
.
- info(text, **kwargs)
Print text for info level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- is_verbose(**kwargs)
Check the verbose level.
- Returns:
- 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.
- raise_request_error(response)
Raise exception.
- Parameters:
response – The response.
- Raises:
KadiAPYRequestError – Error is raised since request was not successful.
- remove_group_role(group)
Remove a group role.
- Parameters:
group (Group) – The group to remove.
- Raises:
KadiAPYRequestError: If request was not successful.
- remove_tag(tag)
Remove a tag using a CLI.
- Parameters:
tag (str) – The tag to remove.
- Raises:
KadiAPYRequestError – If request was not successful.
- remove_user(user)
Remove a user.
- Parameters:
user (User) – The user to remove.
- Raises:
KadiAPYRequestError: If request was not successful.
- set_attribute(**kwargs)
Set attribute using a CLI.
- Parameters:
**kwargs – The attributes and values to set.
- Raises:
KadiAPYRequestError – If request was not successful.
- warning(text, **kwargs)
Print text for warning level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
CLICollection
- class kadi_apy.cli.lib.collections.CLICollection(pipe=False, title=None, create=False, exit_not_created=False, **kwargs)[source]
Bases:
BasicCLIMixin
,UserCLIMixin
,GroupRoleCLIMixin
,TagCLIMixin
,DeleteItemCLIMixin
,ExportCLIMixin
,Collection
,RaiseRequestErrorMixin
Collection class to be used in a CLI.
- Parameters:
manager – See
Collection
.id – See
Collection
.identifier – See
Collection
.skip_request – See
Collection
.create – See
Collection
.pipe (bool, optional) – Flag to indicate if only the id should be printed which can be used for piping.
title (str, optional) – Title of the new resource.
exit_not_created (bool, optional) – Flag to indicate if the function should exit with
sys.exit(1)
if the resource is not created.
- add_record_link(record_to)[source]
Add a record to a collection using a CLI.
- Parameters:
record_to (Record) – The the record to add.
- Raises:
KadiAPYRequestError – If request was not successful.
- remove_record_link(record)[source]
Remove a record from a collection using a CLI.
- Parameters:
record (Record) – The record to remove.
- Raises:
KadiAPYRequestError – If request was not successful.
- add_collection_link(child_collection)[source]
Add a child collection to a parent collection using CLI.
- Parameters:
child_collection (Collection) – The child collection to which the parent collection should be added.
- Raises:
KadiAPYRequestError – If request was not successful.
- remove_collection_link(child_collection)[source]
Remove a child collection from a parent collection using CLI.
- Parameters:
child_collection (Collection) – The child collection to remove from the parent collection.
- Raises:
KadiAPYRequestError – If request was not successful.
- print_info(**kwargs)[source]
Print infos of a collection using the CLI.
- Parameters:
**kwargs – Specify additional infos to print.
- Raises:
KadiAPYRequestError: If request was not successful
- add_group_role(group, permission_new)
Add a group role.
- add_tag(tag)
Add a tag using a CLI.
- Parameters:
tag (str) – The tag to add.
- Raises:
KadiAPYRequestError – If request was not successful.
- add_user(user, permission_new)
Add a user.
- change_group_role(group_id, role_name)
Change group role.
- change_user_role(user_id, role_name)
Change user role.
- check_tag(tag)
Check if a certain tag is already present.
- debug(text, **kwargs)
Print text for debug level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- delete(i_am_sure)
Delete the resource using a CLI.
- Parameters:
i_am_sure (bool) – Flag which has to set to
True
to delete the resource.- Raises:
KadiAPYInputError – If i_am_sure is not
True
.KadiAPYRequestError – If request was not successful.
- 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:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- export(export_type, path='.', name=None, force=False, pipe=False, use_folder=False, **params)
Export the resource using a specific export type using the CLI.
- Parameters:
export_type (str) – The export format.
path (str, optional) – The path to store.
name (str, optional) – The name of the file. The identifier is used as default.
force (bool, optional) – Whether to replace an existing file with identical name.
pipe (bool, optional) – Flag to indicate if json should be piped.
use_folder – Flag indicating if the a folder with the name of the resource’s identifier should be created within given path. The exported file is stored in this folder.
**params – Additional query parameters.
- Raises:
KadiAPYInputError – If export type is invalid or if not json is used as input type together with pipe.
KadiAPYRequestError – If request was not successful.
- get_collection_revision(revision_id, **params)
Get a specific revision of this collection.
- Parameters:
revision_id (int) – The revision ID of the collection.
**params – Additional query parameters.
- Returns:
The response object.
- get_collection_revisions(**params)
Get the revisions of this collection.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_collections(**params)
Get collections linked with a collection id.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_groups(**params)
Get group roles from a collection. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_records(**params)
Get records from a collection. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_users(**params)
Get user of a collection. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- info(text, **kwargs)
Print text for info level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- is_verbose(**kwargs)
Check the verbose level.
- Returns:
- 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.
- raise_request_error(response)
Raise exception.
- Parameters:
response – The response.
- Raises:
KadiAPYRequestError – Error is raised since request was not successful.
- remove_group_role(group)
Remove a group role.
- Parameters:
group (Group) – The group to remove.
- Raises:
KadiAPYRequestError: If request was not successful.
- remove_tag(tag)
Remove a tag using a CLI.
- Parameters:
tag (str) – The tag to remove.
- Raises:
KadiAPYRequestError – If request was not successful.
- remove_user(user)
Remove a user.
- Parameters:
user (User) – The user to remove.
- Raises:
KadiAPYRequestError: If request was not successful.
- set_attribute(**kwargs)
Set attribute using a CLI.
- Parameters:
**kwargs – The attributes and values to set.
- Raises:
KadiAPYRequestError – If request was not successful.
- warning(text, **kwargs)
Print text for warning level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
CLITemplate
- class kadi_apy.cli.lib.templates.CLITemplate(pipe=False, title=None, create=False, exit_not_created=False, **kwargs)[source]
Bases:
BasicCLIMixin
,DeleteItemCLIMixin
,ExportCLIMixin
,UserCLIMixin
,GroupRoleCLIMixin
,Template
,RaiseRequestErrorMixin
Template class to be used in a CLI.
- Parameters:
manager – See
Template
.type – See
Template
.data – See
Template
.id – See
Template
.identifier – See
Template
.skip_request – See
Template
.create – See
Template
.pipe (bool, optional) – Flag to indicate if only the id should be printed which can be used for piping.
title (str, optional) – Title of the new resource.
exit_not_created (bool, optional) – Flag to indicate if the function should exit with
sys.exit(1)
if the resource is not created.
- print_info(**kwargs)[source]
Print infos of a template using the CLI.
- Parameters:
**kwargs – Specify additional infos to print.
- Raises:
KadiAPYRequestError: If request was not successful.
- add_group_role(group, permission_new)
Add a group role.
- add_user(user, permission_new)
Add a user.
- change_group_role(group_id, role_name)
Change group role.
- change_user_role(user_id, role_name)
Change user role.
- debug(text, **kwargs)
Print text for debug level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- delete(i_am_sure)
Delete the resource using a CLI.
- Parameters:
i_am_sure (bool) – Flag which has to set to
True
to delete the resource.- Raises:
KadiAPYInputError – If i_am_sure is not
True
.KadiAPYRequestError – If request was not successful.
- 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:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- export(export_type, path='.', name=None, force=False, pipe=False, use_folder=False, **params)
Export the resource using a specific export type using the CLI.
- Parameters:
export_type (str) – The export format.
path (str, optional) – The path to store.
name (str, optional) – The name of the file. The identifier is used as default.
force (bool, optional) – Whether to replace an existing file with identical name.
pipe (bool, optional) – Flag to indicate if json should be piped.
use_folder – Flag indicating if the a folder with the name of the resource’s identifier should be created within given path. The exported file is stored in this folder.
**params – Additional query parameters.
- Raises:
KadiAPYInputError – If export type is invalid or if not json is used as input type together with pipe.
KadiAPYRequestError – If request was not successful.
- get_groups(**params)
Get group roles from a template. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_template_revision(revision_id, **params)
Get a specific revision of this template.
- Parameters:
revision_id (int) – The revision ID of the template.
**params – Additional query parameters.
- Returns:
The response object.
- get_template_revisions(**params)
Get the revisions of this template.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_users(**params)
Get users from a template. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- info(text, **kwargs)
Print text for info level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- is_verbose(**kwargs)
Check the verbose level.
- Returns:
- 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.
- raise_request_error(response)
Raise exception.
- Parameters:
response – The response.
- Raises:
KadiAPYRequestError – Error is raised since request was not successful.
- remove_group_role(group)
Remove a group role.
- Parameters:
group (Group) – The group to remove.
- Raises:
KadiAPYRequestError: If request was not successful.
- remove_user(user)
Remove a user.
- Parameters:
user (User) – The user to remove.
- Raises:
KadiAPYRequestError: If request was not successful.
- set_attribute(**kwargs)
Set attribute using a CLI.
- Parameters:
**kwargs – The attributes and values to set.
- Raises:
KadiAPYRequestError – If request was not successful.
- warning(text, **kwargs)
Print text for warning level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
CLIGroup
- class kadi_apy.cli.lib.groups.CLIGroup(pipe=False, title=None, create=False, exit_not_created=False, **kwargs)[source]
Bases:
BasicCLIMixin
,UserCLIMixin
,DeleteItemCLIMixin
,Group
,RaiseRequestErrorMixin
Group class to be used in a CLI.
- Parameters:
manager – See
Group
.id – See
Group
.identifier – See
Group
.skip_request – See
Group
.create – See
Group
.pipe (bool, optional) – Flag to indicate if only the id should be printed which can be used for piping.
title (str, optional) – Title of the new resource.
exit_not_created (bool, optional) – Flag to indicate if the function should exit with
sys.exit(1)
if the resource is not created.
- add_user(user, permission_new)
Add a user.
- change_user_role(user_id, role_name)
Change role of a user.
- debug(text, **kwargs)
Print text for debug level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- delete(i_am_sure)
Delete the resource using a CLI.
- Parameters:
i_am_sure (bool) – Flag which has to set to
True
to delete the resource.- Raises:
KadiAPYInputError – If i_am_sure is not
True
.KadiAPYRequestError – If request was not successful.
- 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:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- get_collections(**params)
Get collections shared with a group. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_group_revision(revision_id, **params)
Get a specific revision from this group.
- Parameters:
revision_id (int) – The revision ID of the group.
**params – Additional query parameters.
- Returns:
The response object.
- get_group_revisions(**params)
Get the revisions of this group.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_records(**params)
Get records shared with a group. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_templates(**params)
Get templates shared with a group. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- get_users(**params)
Get users of a group. Supports pagination.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- info(text, **kwargs)
Print text for info level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- is_verbose(**kwargs)
Check the verbose level.
- Returns:
- 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.
- print_info(**kwargs)
Print infos using a CLI.
- Parameters:
**kwargs – Specify additional infos to print.
- Raises:
KadiAPYRequestError – If request was not successful.
- raise_request_error(response)
Raise exception.
- Parameters:
response – The response.
- Raises:
KadiAPYRequestError – Error is raised since request was not successful.
- remove_user(user)
Remove a user.
- Parameters:
user (User) – The user to remove.
- Raises:
KadiAPYRequestError: If request was not successful.
- set_attribute(**kwargs)
Set attribute using a CLI.
- Parameters:
**kwargs – The attributes and values to set.
- Raises:
KadiAPYRequestError – If request was not successful.
- warning(text, **kwargs)
Print text for warning level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
CLIUser
- class kadi_apy.cli.lib.users.CLIUser(manager, id=None, username=None, identity_type=None, use_pat=False)[source]
Bases:
User
,RaiseRequestErrorMixin
User class to be used in a CLI.
See
User
for the possible parameters.- debug(text, **kwargs)
Print text for debug level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- error(text, **kwargs)
Print text for error level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- info(text, **kwargs)
Print text for info level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- is_verbose(**kwargs)
Check the verbose level.
- Returns:
- 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.
- raise_request_error(response)
Raise exception.
- Parameters:
response – The response.
- Raises:
KadiAPYRequestError – Error is raised since request was not successful.
- warning(text, **kwargs)
Print text for warning level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
CLIMiscellaneous
- class kadi_apy.cli.lib.misc.CLIMiscellaneous(manager)[source]
Bases:
Miscellaneous
,RaiseRequestErrorMixin
Model to handle miscellaneous functionality.
See
Miscellaneous
for the possible parameters.- get_deleted_resources(**params)[source]
Get a list of deleted resources in the trash using the CLI.
Supports pagination.
- Parameters:
**params – Additional query parameters.
- Raises:
KadiAPYRequestError – If request was not successful.
- restore(item, item_id)[source]
Restore an item from the trash using the CLI.
- Parameters:
item – The resource type defined as class.
item_id (int) – The ID of the item to restore.
- Raises:
KadiAPYRequestError – If request was not successful.
- purge(item, item_id)[source]
Purge an item from the trash using the CLI.
- Parameters:
item – The resource type defined as class or string.
item_id (int) – The ID of the item to restore.
- Raises:
KadiAPYRequestError – If request was not successful.
- get_licenses(**params)[source]
Get a list of available licenses using the CLI.
- Parameters:
**params – Additional query parameters.
- Raises:
KadiAPYRequestError – If request was not successful.
- get_kadi_info(manager)[source]
Print information about the Kadi instance and the config file.
- Parameters:
manager (KadiManager, CLIKadiManager) – Used Manager.
- Raises:
KadiAPYRequestError – If request was not successful.
- get_roles(item_type=None)[source]
Get a list of all possible roles.
Print all possible roles and corresponding permissions of all resources or of one resource.
- Parameters:
item_type (str, optional) – Type of resource for printing roles and permissions.
- Raises:
KadiAPYRequestError – If request was not successful.
- get_tags(**params)[source]
Get a list of all available tags using the CLI.
- Parameters:
**params – Additional query parameters.
- Raises:
KadiAPYRequestError – If request was not successful.
- debug(text, **kwargs)
Print text for debug level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- error(text, **kwargs)
Print text for error level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- import_eln(file_path)
Import an RO-Crate file following the “ELN” file specification.
- Parameters:
file_path (str) – The path of the file.
- Raises:
KadiAPYInputError – If the structure of the RO-Crate is not valid.
KadiAPYRequestError – If any request was not successful while importing the data and metadata.
- import_json_schema(file_path, template_type='extras')
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:
- Raises:
KadiAPYInputError – If the structure of the Schema is not valid.
KadiAPYRequestError – If any request was not successful while importing the metadata.
- import_shacl(file_path, template_type='extras')
Import SHACL Shapes file and create a template.
- Parameters:
- Raises:
KadiAPYInputError – If the structure of the Shapes is not valid.
KadiAPYRequestError – If any request was not successful while importing the metadata.
- info(text, **kwargs)
Print text for info level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- is_verbose(**kwargs)
Check the verbose level.
- Returns:
- raise_request_error(response)
Raise exception.
- Parameters:
response – The response.
- Raises:
KadiAPYRequestError – Error is raised since request was not successful.
- warning(text, **kwargs)
Print text for warning level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
CLISearch
- class kadi_apy.cli.search.CLISearch(manager)[source]
Bases:
Search
,RaiseRequestErrorMixin
Search class to be used in a CLI.
- Parameters:
manager (CLIKadiManager) – Manager to use for all API requests.
- search_resources(item, user=None, use_my_user_id=False, **params)[source]
Search for resources.
- Parameters:
- Raises:
KadiAPYInputError – If both a user ID is given and the flag
use_my_user_id
isTrue
.
- search_resource_ids(item, pipe=False, i_am_sure=False, **params)[source]
Search for resource ids.
- Parameters:
item – The resource type defined either as string or class.
pipe (bool) – If the results should be printed in form of a tokenlist for piping.
i_am_sure (bool) – If the search results in more than 1000 results, this flag has to be activated to search for all results.
**params – Additional query parameters.
- Returns:
A list of ids found.
- Return type:
- Raises:
KadiAPYConfigurationError – If more than 1000 results are found and the flag ‘i_am_sure’ is not set to true.
- search_users(**params)[source]
Search for users.
- Parameters:
**params – Additional query parameters.
- Returns:
The response object.
- debug(text, **kwargs)
Print text for debug level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- error(text, **kwargs)
Print text for error level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- info(text, **kwargs)
Print text for info level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
- is_verbose(**kwargs)
Check the verbose level.
- Returns:
- raise_request_error(response)
Raise exception.
- Parameters:
response – The response.
- Raises:
KadiAPYRequestError – Error is raised since request was not successful.
- search_user_resources(item, user, **params)
Search for resources of users.
- Parameters:
item – The resource type defined either as string or class.
user – ID of the user whose items are to be searched for.
**params – Additional query parameters.
- Returns:
The response object.
- warning(text, **kwargs)
Print text for warning level.
- Parameters:
text (str) – Text to be printed via
click.echo()
.**kwargs – Additional arguments to pass to
click.echo()
.
Decorators
- kadi_apy.cli.decorators.apy_command(use_kadi_manager=False)[source]
Decorator to handle the default arguments and exceptions of an APY command.
This function inits the
KadiManager
orCLIKadiManager
and includes it asmanager
to**kwargs
. It adds the optionsinstance
andverbose
to the CLI tool.- Parameters:
use_kadi_manager (bool, optional) – Flag to use the
KadiManager
instead of theCLIKadiManager
.
- kadi_apy.cli.decorators.id_identifier_options(class_type, keep_manager=False, helptext=None, name=None, required=True, char=None, allow_tokenlist=False, tokenlist_name=None, tokenlist_char='T')[source]
Decorator to handle the common ID and identifier options of commands.
This function inits a resource and includes it to
**kwargs
. It adds the options to read the ID or the identifier of the resource to the CLI tool.- Parameters:
class_type – The resource type defined either as string or class.
keep_manager (bool, optional) – Whether to keep the manager for further use.
helptext (str, optional) – Text to describe the input.
name (str, optional) – Name to better describe the input.
required (bool, optional) – Whether the parameter is required.
char (str, optional) – Char for the options.
allow_tokenlist (bool, optional) – Flag indicating if a tokenlist should be an option for input. If
True
the manager is passed to the function even ifkeep_manager
isFalse
.tokenlist_name (str, optional) – Name of the tokenlist.
tokenlist_char (str, optional) – Char for the tokenlist.
- kadi_apy.cli.decorators.user_id_options(helptext=None, required=True, keep_manager=False)[source]
Decorator to handle options to identify a user.
This function inits a
CLIUser
and includes it to**kwargs
. Is adds the options to read the user ID, username and identity-type to the CLI tool.