Welcome to pydas’s documentation!

Contents:

Module for the main user classes for pydas.

class pydas.core.Communicator(url, drivers=None)[source]

Class for communicating with the Midas server through its drivers.

debug[source]

Return the debug state of all drivers by logically anding them.

debug_set[source]

Return the debug state of all drivers by logically anding them.

drivers[source]

Get the list of drivers

url[source]

Getter for the url.

This module is for the drivers that actually do the work of communication with the Midas server. Any drivers that are implemented should use the utility functions provided in pydas.drivers.BaseDriver by inheriting from that class.

class pydas.drivers.BaseDriver(url='')[source]

Base class for the Midas api drivers.

debug[source]

Return the debug state of the driver

debug_set[source]

Return the debug state of the driver

full_url[source]

Return the full path the the url (including the api extensions).

login_with_api_key(cur_email, cur_apikey, application='Default')[source]

Login and get a token.

If you do not specify a specific application, ‘Default’ will be used.

Parameters:
  • cur_email – The email of the user.
  • cur_apikey – A valid api-key assigned to the user.
  • application – (optional) Application designated for this api key.
Returns:

String of the token to be used for interaction with the api

until expiration.

request(*args, **kw)[source]

Do the generic processing of a request to the server.

If file_payload is specified, it will be PUT to the server.

Parameters:method – String to be passed to the server indicating the desired

method. :param parameters: (optional) Dictionary to pass in the HTTP body. :param file_payload: (optional) File-like object to be sent with the HTTP request :returns: Dictionary representing the json response to the request.

url[source]

Getter for the url

class pydas.drivers.BatchmakeDriver(url='')[source]

Driver for the Midas batchmake module’s API methods.

add_condor_dag(token, batchmaketaskid, dagfilename, dagmanoutfilename)[source]

Adds a condor dag to the given batchmake task

add_condor_job(token, batchmaketaskid, jobdefinitionfilename, outputfilename, errorfilename, logfilename, postfilename)[source]

Adds a condor dag job to the condor dag associated with this batchmake task

class pydas.drivers.CoreDriver(url='')[source]

Driver for the core API methods of Midas.

This contains all of the calls necessary to interact with a Midas instance that has no plugins enabled (other than the web-api).

create_community(token, name, **kwargs)[source]

Create a new community or update an existing one using the uuid.

Parameters:
  • token – A valid token for the user in question.
  • name – The community name.
  • description – (optional) The community description.
  • uuid – (optional) uuid of the community. If none is passed, will

generate one. :param privacy: (optional) Default ‘Public’, possible values [Public|Private]. :param can_join: (optional) Default ‘Everyone’, possible values [Everyone|Invitation]. :returns: The community dao that was created.

create_folder(token, name, parent_id, **kwargs)[source]

Create a folder at the destination specified.

Parameters:
  • token – A valid token for the user in question.
  • name – The name of the folder to be created.
  • parent_id – The id of the targeted parent folder.
  • description – (optional) The description text of the folder.
  • uuid – (optional) The UUID for the folder. It will be generated

if not given. :param privacy: (optional) The privacy state of the folder (‘Public’ or ‘Private’). :param reuse_existing: (optional) If true, will just return the existing folder if there is one with the name provided. :returns: Dictionary containing the details of the created folder.

create_item(token, name, parent_id, **kwargs)[source]

Create an item to the server.

Parameters:
  • token – A valid token for the user in question.
  • name – The name of the item to be created.
  • parent_id – The id of the destination folder.
  • description – (optional) The description text of the item.
  • uuid – (optional) The UUID for the item. It will be generated if

not given. :param privacy: (optional) The privacy state of the item (‘Public’ or ‘Private’). :returns: Dictionary containing the details of the created item.

Create a link bitstream.

Parameters:
  • token – A valid token for the user in question.
  • folder_id – The id of the folder in which to create a new item

that will contain the link. The new item will have the same name as the URL unless an item name is supplied. :param url: The URL of the link you will create, will be used as the name of the bitstream and of the item unless an item name is supplied. :param item_name: (optional) The name of the newly created item, if not supplied, the item will have the same name as the URL. :param length: (optional) The length in bytes of the file to which the link points. :param checksum: (optional) The MD5 checksum of the file to which the link points. :returns: The item information of the item created.

delete_folder(token, folder_id)[source]

Delete the folder with the passed in folder_id.

Parameters:
  • token – A valid token for the user in question.
  • folder_id – The id of the folder to be deleted.
Returns:

None.

delete_item(token, item_id)[source]

Delete the item with the passed in item_id.

Parameters:
  • token – A valid token for the user in question.
  • item_id – The id of the item to be deleted.
Returns:

None.

download_item(item_id, token=None, revision=None)[source]

Download an item to disk.

Parameters:
  • item_id – The id of the item to be downloaded.
  • token – (optional) The authentication token of the user

requesting the download. :param revision: (optional) The revision of the item to download, this defaults to HEAD. :returns: A tuple of the filename and the content iterator.

folder_children(token, folder_id)[source]

Get the non-recursive children of the passed in folder_id.

Parameters:
  • token – A valid token for the user in question.
  • folder_id – The id of the requested folder.
Returns:

Dictionary of two lists: ‘folders’ and ‘items’.

folder_get(token, folder_id)[source]

Get the attributes of the specified folder.

Parameters:
  • token – A valid token for the user in question.
  • folder_id – The id of the requested folder.
Returns:

Dictionary of the folder attributes.

generate_upload_token(token, item_id, filename, checksum=None)[source]

Generate a token to use for upload.

Midas uses a individual token for each upload. The token corresponds to the file specified and that file only. Passing the MD5 checksum allows the server to determine if the file is already in the asset store.

Parameters:
  • token – A valid token for the user in question.
  • item_id – The id of the item in which to upload the file as a

bitstream. :param filename: The name of the file to generate the upload token for. :param checksum: (optional) The checksum of the file to upload. :returns: String of the upload token.

get_community_by_id(community_id, token=None)[source]

Get a community based on its id.

Parameters:
  • community_id – The id of the target community.
  • token – (optional) A valid token for the user in question.
Returns:

The requested community.

get_community_by_name(name, token=None)[source]

Get a community based on its name.

Parameters:
  • name – The name of the target community.
  • token – (optional) A valid token for the user in question.
Returns:

The requested community.

get_community_children(community_id, token=None)[source]

Get the non-recursive children of the passed in community_id.

Parameters:
  • token – A valid token for the user in question.
  • community_id – The id of the requested community.
Returns:

List of the folders in the community.

get_default_api_key(email, password)[source]

Get the default api key for a user.

Parameters:
  • email – The email of the user.
  • password – The user’s password.
Returns:

String api-key to confirm that it was fetched successfully.

get_item_metadata(item_id, token=None, revision=None)[source]

Get the metadata associated with an item.

Parameters:
  • item_id – The id of the item for which metadata will be returned
  • token – (optional) A valid token for the user in question.
  • revision – (optional) Revision of the item. Defaults to latest

revision. :returns: List of dictionaries containing item metadata.

get_server_info()[source]

Get general server information.

The information provided includes enabled modules as well as enabled web api functions.

Returns:Dictionary of dictionaries containing module and web-api

information.

get_server_version()[source]

Get the version from the server.

Returns:String version code from the server.
get_user_by_email(email)[source]

Get a user by the email of that user.

Parameters:email – The email of the desired user.
Returns:The user requested.
get_user_by_id(user_id)[source]

Get a user by the first and last name of that user.

Parameters:user_id – The id of the desired user.
Returns:The user requested.
get_user_by_name(firstname, lastname)[source]

Get a user by the first and last name of that user.

Parameters:
  • firstname – The first name of the user.
  • lastname – The last name of the user.
Returns:

The user requested.

item_get(token, item_id)[source]

Get the attributes of the specified item.

Parameters:
  • token – A valid token for the user in question.
  • item_id – The id of the requested item.
Returns:

Dictionary of the item attributes.

list_communities(token=None)[source]

List all communities visible to a user.

Parameters:token – (optional) A valid token for the user in question.
Returns:The list of communities.
list_modules()[source]

List the enabled modules on the server.

Returns:List of names of the enabled modules.
list_user_folders(token)[source]

List the folders in the users home area.

Parameters:token – A valid token for the user in question.
Returns:List of dictionaries containing folder information.
list_users(limit=20)[source]

List the public users in the system.

Parameters:limit – The number of users to fetch.
Returns:The list of users.
move_folder(token, folder_id, dest_folder_id)[source]

Move a folder to the destination folder.

Parameters:
  • token – A valid token for the user in question.
  • folder_id – The id of the folder to be moved.
  • dest_folder_id – The id of destination (new parent) folder.
Returns:

Dictionary containing the details of the moved folder.

move_item(token, item_id, src_folder_id, dest_folder_id)[source]

Move an item from the source folder to the desination folder.

Parameters:
  • token – A valid token for the user in question.
  • item_id – The id of the item to be moved.
  • src_folder_id – The id of source folder where the item is located.
  • dest_folder_id – The id of destination folder where the item is

moved to. :returns: Dictionary containing the details of the moved item.

perform_upload(uploadtoken, filename, **kwargs)[source]

Upload a file into a given item (or just to the public folder if the item is not specified.

Parameters:
  • uploadtoken – The upload token (returned by generate_upload_token)
  • filename – The upload filename. Also used as the path to the file,

if ‘filepath’ is not set. :param mode: (optional) Stream or multipart. Default is stream. :param folderid: (optional) The id of the folder to upload into. :param item_id: (optional) If set, will create a new revision in the existing item. :param revision: (optional) If set, will add a new file into an existing revision. Set this to “head” to add to the most recent revision. :param filepath: (optional) The path to the file. :returns: Dictionary containing the details of the item created or changed.

search(search, token=None)[source]

Get the resources corresponding to a given query.

Parameters:
  • search – The search criterion.
  • token – (optional) The credentials to use when searching.
Returns:

Dictionary containing the search result. Notable is the

dictionary item ‘results’, which is a list of item details.

search_item_by_name(name, token=None)[source]

Return all items.

Parameters:
  • name – The name of the item to search by.
  • token – (optional) A valid token for the user in question.
Returns:

A list of all items with the given name.

search_item_by_name_and_folder(name, folder_id, token=None)[source]

Return all items with a given name and parent folder id.

Parameters:
  • name – The name of the item to search by.
  • folder_id – The id of the parent folder to search by.
  • token – (optional) A valid token for the user in question.
Returns:

A list of all items with the given name and parent folder id.

search_item_by_name_and_folder_name(name, folder_name, token=None)[source]

Return all items with a given name and parent folder name.

Parameters:
  • name – The name of the item to search by.
  • folder_name – The name of the parent folder to search by.
  • token – (optional) A valid token for the user in question.
Returns:

A list of all items with the given name and parent folder name.

set_item_metadata(token, item_id, element, value, qualifier=None)[source]

Set the metadata associated with an item.

Parameters:
  • token – A valid token for the user in question.
  • item_id – The id of the item for which metadata will be set.
  • element – The metadata element name.
  • value – The metadata value for the field.
  • qualifier – (optional) The metadata qualifier. Defaults to empty

string. :returns: None.

share_item(token, item_id, dest_folder_id)[source]

Share an item to the destination folder.

Parameters:
  • token – A valid token for the user in question.
  • item_id – The id of the item to be shared.
  • dest_folder_id – The id of destination folder where the item is

shared to. :returns: Dictionary containing the details of the shared item.

class pydas.drivers.DicomextractorDriver(url='')[source]

Driver for the Midas dicomextractor module’s API methods.

extract_dicommetadata(token, item_id)[source]

Extracts DICOM metadata from the given item

class pydas.drivers.MultiFactorAuthenticationDriver(url='')[source]

Driver for the multi-factor authentication module’s API methods.

mfa_otp_login(temp_token, one_time_pass)[source]

Log in to get the real token using the temporary token and otp.

Parameters:
  • temp_token – The temporary token or id returned from normal login
  • one_time_pass – The one-time pass to be sent to the underlying

multi-factor engine. :returns: A standard token for interacting with the web api.

class pydas.drivers.SolrDriver(url='')[source]

Driver for the Midas solr module’s api methods.

Search item metadata using Apache Solr.

Parameters:
  • query – The Apache Lucene search query.
  • token – (optional) A valid token for the user in question.
  • limit – (optional) The limit of the search.
Returns:

The list of items that match the search query.

class pydas.drivers.ThumbnailCreatorDriver(url='')[source]

Driver for the Midas thumbnailcreator module’s API methods.

create_big_thumbnail(token, bitstream_id, item_id, width=575)[source]

Create a big thumbnail for the given bitstream with the given width. It is used as the main image of the given item and shown in the item view page.

Parameters:
  • token – A valid token for the user in question.
  • bitstream_id – The bitstream from which to create the thumbnail.
  • item_id – The item on which to set the thumbnail.
  • width – (optional) The width in pixels to which to resize (aspect

ratio will be preserved). Defaults to 575. :returns: The ItemthumbnailDao object that was created.

create_small_thumbnail(token, item_id)[source]

Create a 100x100 small thumbnail for the given item. It is used for preview purpose and displayed in the ‘preview’ and ‘thumbnails’ sidebar sections.

Parameters:
  • token – A valid token for the user in question.
  • item_id – The item on which to set the thumbnail.
Returns:

The item object (with the new thumbnail id) and the path

where the newly created thumbnail is stored.

class pydas.drivers.TrackerDriver(url='')[source]

Driver for the Midas tracker module’s api methods.

add_scalar_data(token, community_id, producer_display_name, metric_name, producer_revision, submit_time, value, **kwargs)[source]

Create a new scalar data point.

Parameters:
  • token – A valid token for the user in question.
  • community_id – The id of the community that owns the producer.
  • producer_display_name – The display name of the producer.
  • metric_name – The metric name that identifies which trend this

point belongs to. :param producer_revision: The repository revision of the producer that produced this value. :param submit_time: The submit timestamp. Must be parsable with PHP strtotime(). :param value: The value of the scalar. :param config_item_id: (optional) If this value pertains to a specific configuration item, pass its id here. :param test_dataset_id: (optional) If this value pertains to a specific test dataset, pass its id here. :param truth_dataset_id: (optional) If this value pertains to a specific ground truth dataset, pass its id here. :param silent: (optional) If true, do not perform threshold-based email notifications for this scalar. :param unofficial: (optional) If true, creates an unofficial scalar visible only to the user performing the submission. :param build_results_url: (optional) A URL for linking to build results for this submission. :param branch: (optional) The branch name in the source repository for this submission. :param params: (optional) Any key/value pairs that should be displayed with this scalar result. :type params: dict :param extra_urls: (optional) Other URL’s that should be displayed with with this scalar result. Each element of the list should be a dict with the following keys: label, text, href :type extra_urls: list of dicts :returns: The scalar object that was created.

associate_item_with_scalar_data(token, item_id, scalar_id, label)[source]

Associate a result item with a particular scalar value.

Parameters:
  • token – A valid token for the user in question.
  • item_id – The id of the item to associate with the scalar.
  • scalar_id – Scalar id with which to associate the item.
  • label – The label describing the nature of the association.
upload_json_results(token, filepath, community_id, producer_display_name, metric_name, producer_revision, submit_time, **kwargs)[source]

Upload a JSON file containing numeric scoring results to be added as scalars. File is parsed and then deleted from the server.

Parameters:
  • token – A valid token for the user in question.
  • filepath – The path to the JSON file.
  • community_id – The id of the community that owns the producer.
  • producer_display_name – The display name of the producer.
  • producer_revision – The repository revision of the producer

that produced this value. :param submit_time: The submit timestamp. Must be parsable with PHP strtotime(). :param config_item_id: (optional) If this value pertains to a specific configuration item, pass its id here. :param test_dataset_id: (optional) If this value pertains to a specific test dataset, pass its id here. :param truth_dataset_id: (optional) If this value pertains to a specific ground truth dataset, pass its id here. :param parent_keys: (optional) Semicolon-separated list of parent keys to look for numeric results under. Use ‘.’ to denote nesting, like in normal javascript syntax. :param silent: (optional) If true, do not perform threshold-based email notifications for this scalar. :param unofficial: (optional) If true, creates an unofficial scalar visible only to the user performing the submission. :param build_results_url: (optional) A URL for linking to build results for this submission. :param branch: (optional) The branch name in the source repository for this submission. :param params: (optional) Any key/value pairs that should be displayed with this scalar result. :type params: dict :param extra_urls: (optional) Other URL’s that should be displayed with with this scalar result. Each element of the list should be a dict with the following keys: label, text, href :type extra_urls: list of dicts :returns: The list of scalars that were created.

Indices and tables