acdcli.api package

Submodules

acdcli.api.account module

ACD account information

class acdcli.api.account.AccountMixin[source]

Bases: object

fs_sizes() → tuple[source]
Returns tuple:total and free space
get_account_info() → dict[source]

Gets account status [ACTIVE, ...?] and terms of use version.

get_account_usage() → str[source]
get_quota() → dict[source]

acdcli.api.backoff_req module

class acdcli.api.backoff_req.BackOffRequest[source]

Bases: object

Wrapper for requests that implements timed back-off algorithm https://developer.amazon.com/public/apis/experience/cloud-drive/content/best-practices Caution: this catches all connection errors and may stall for a long time. It is necessary to init this module before use.

__init__()[source]
Parameters:
delete(url, acc_codes=[200], **kwargs) → requests.models.Response[source]
get(url, acc_codes=[200], **kwargs) → requests.models.Response[source]
paginated_get()[source]

Gets node list in segments of 200.

patch(url, acc_codes=[200], **kwargs) → requests.models.Response[source]
post(url, acc_codes=[200], **kwargs) → requests.models.Response[source]
put(url, acc_codes=[200], **kwargs) → requests.models.Response[source]

acdcli.api.client module

acdcli.api.common module

exception acdcli.api.common.RequestError(status_code: int, msg: str)[source]

Bases: Exception

Catch-all exception class for various connection and ACD server errors.

class CODE[source]

Bases: object

CONN_EXCEPTION = 1000
FAILED_SUBREQUEST = 1002
INCOMPLETE_RESULT = 1003
INVALID_TOKEN = 1005
REFRESH_FAILED = 1004
RequestError.__init__(status_code: int, msg: str)[source]
RequestError.codes = <lookup 'status_codes'>
acdcli.api.common.catch_conn_exception(func)[source]

Request connection exception decorator :raises RequestError

acdcli.api.common.is_valid_id(id: str) → bool[source]

acdcli.api.content module

acdcli.api.metadata module

Node metadata operations

acdcli.api.metadata.ChangeSet

alias of Changes

class acdcli.api.metadata.MetadataMixin[source]

Bases: object

add_child(parent_id: str, child_id: str) → dict[source]

Adds node with ID child_id to folder with ID parent_id.

Returns:updated child node dict
add_property(node_id: str, owner_id: str, key: str, value: str) → dict[source]

Adds or overwrites key property with content. Maximum number of keys per owner is 10.

Parameters:value – string of length <= 500
Raises:RequestError: 404, <UnknownOperationException/> if owner is empty RequestError: 400, {...} if maximum of allowed properties is reached
Returns dict:{‘key’: ‘<KEY>’, ‘location’: ‘<NODE_ADDRESS>/properties/<OWNER_ID/<KEY>’,

‘value’: ‘<VALUE>’}

delete_properties(node_id: str, owner_id: str)[source]

Deletes all of the owner’s properties. Uses multiple requests.

delete_property(node_id: str, owner_id: str, key: str)[source]

Deletes key property from node with ID node_id.

get_asset_list() → list[source]
get_changes(checkpoint='', include_purged=False, silent=True, file=None)[source]

Writes changes into a (temporary) file. See https://developer.amazon.com/public/apis/experience/cloud-drive/content/changes.

get_file_list() → list[source]
get_folder_list() → list[source]
get_metadata(node_id: str, assets=False, temp_link=True) → dict[source]

Gets a node’s metadata.

Parameters:
  • assets – also include asset info (e.g. thumbnails) if the node is a file
  • temp_link – include a temporary download link if the node is a file
get_node_list(**params) → list[source]
Parameters:params – may include tempLink=’True’
get_owner_id()[source]

Provisional function for retrieving the security profile’s name, a.k.a. owner id.

get_root_id() → str[source]

Gets the ID of the root node

Returns:the topmost folder id
get_root_node() → dict[source]

Gets the root node metadata

get_trashed_files() → list[source]
get_trashed_folders() → list[source]
list_child_folders(node_id: str) → list[source]
list_children(node_id: str) → list[source]
list_properties(node_id: str, owner_id: str) → dict[source]

This will always return an empty dict if the accessor is not the owner. :param _sphinx_paramlinks_acdcli.api.metadata.MetadataMixin.list_properties.owner_id: owner ID (return status 404 if empty)

move_node(node_id: str, parent_id: str) → dict[source]
move_node_from(node_id: str, old_parent_id: str, new_parent_id: str) → dict[source]

Moves node with given ID from old parent to new parent. Not tested with multi-parent nodes.

Returns:changed node dict
remove_child(parent_id: str, child_id: str) → dict[source]
Returns:updated child node dict
rename_node(node_id: str, new_name: str) → dict[source]
resolve_folder_path()[source]

Resolves a non-trash folder path to a list of folder entries.

set_available(node_id: str) → dict[source]

Sets node status from ‘PENDING’ to ‘AVAILABLE’.

update_metadata(node_id: str, properties: dict) → dict[source]

Update a node’s properties like name, description, status, parents, ...

acdcli.api.oauth module

class acdcli.api.oauth.AppspotOAuthHandler(path)[source]

Bases: acdcli.api.oauth.OAuthHandler

APPSPOT_URL = 'https://acd-api-oa.appspot.com/'
__init__(path)[source]
check_oauth_file_exists()[source]

Checks for existence of oauth token file and instructs user to visit the Appspot page if it was not found.

Raises:FileNotFoundError if oauth file was not placed into cache directory
refresh_auth_token()[source]
Raises:RequestError
class acdcli.api.oauth.LocalOAuthHandler(path)[source]

Bases: acdcli.api.oauth.OAuthHandler

A local OAuth handler that works with a whitelisted security profile. The profile must not be created prior to June 2015. Profiles created prior to this month are not able to use the new scope “clouddrive:read_all” that replaces “clouddrive:read”. https://developer.amazon.com/public/apis/experience/cloud-drive/content/getting-started

AMAZON_OA_LOGIN_URL = 'https://amazon.com/ap/oa'
AMAZON_OA_TOKEN_URL = 'https://api.amazon.com/auth/o2/token'
CLIENT_DATA_FILE = 'client_data'
REDIRECT_URI = 'http://localhost'
__init__(path)[source]
check_oauth_file_exists()[source]
Raises:Exception
load_client_data()[source]
Raises:IOError if client data file was not found
Raises:KeyError if client data file has missing key(s)
refresh_auth_token()[source]
Raises:RequestError
class acdcli.api.oauth.OAuthHandler(path)[source]

Bases: requests.auth.AuthBase

class KEYS[source]

Bases: object

ACC_TOKEN = 'access_token'
EXP_IN = 'expires_in'
EXP_TIME = 'exp_time'
REDIRECT_URI = 'redirect_uri'
REFR_TOKEN = 'refresh_token'
OAuthHandler.OAUTH_DATA_FILE = 'oauth.json'
OAuthHandler.__init__(path)[source]
OAuthHandler.check_oauth_file_exists()[source]

Checks for OAuth file existence and one-time initialize if necessary. Throws on error.

OAuthHandler.exp_time
OAuthHandler.get_access_token_info() → dict[source]
Returns:

int exp: expiration time in sec, str aud: client id user_id, app_id, iat (exp time)

OAuthHandler.get_auth_token(reload=True) → str[source]

Gets current access token, refreshes if necessary.

Parameters:reload – whether the oauth token file should be reloaded (external update)
OAuthHandler.load_oauth_data()[source]

Loads oauth data file, validate and add expiration time if necessary

OAuthHandler.refresh_auth_token()[source]

Fetches a new access token using the refresh token.

OAuthHandler.treat_auth_token(time_: float)[source]

Adds expiration time to member OAuth dict using specified begin time.

classmethod OAuthHandler.validate(oauth: str) → dict[source]

Deserialize and validate an OAuth string

Raises:RequestError
OAuthHandler.write_oauth_data()[source]

Dumps (treated) OAuth dict to file as JSON.

acdcli.api.oauth.create_handler(path: str)[source]

acdcli.api.trash module

Node trashing and restoration. https://developer.amazon.com/public/apis/experience/cloud-drive/content/trash

class acdcli.api.trash.TrashMixin[source]

Bases: object

list_trash() → list[source]

Retrieves top-level trash list

move_to_trash(node_id: str) → dict[source]
purge(node_id: str) → dict[source]
restore(node_id: str) → dict[source]

Module contents

ACD API

Usage

from api import client
acd_client = client.ACDClient()
root = acd_client.get_root_id()
children = acd_client.list_children(root)
for child in children:
    print(child['name'])
# ...

Node JSON Format

This is the usual node JSON format for a file:

{
       'contentProperties': {'contentType': 'text/plain',
                             'extension': 'txt',
                             'md5': 'd41d8cd98f00b204e9800998ecf8427e',
                             'size': 0,
                             'version': 1},
       'createdBy': '<security-profile-nm>-<user>',
       'createdDate': '2015-01-01T00:00:00.00Z',
       'description': '',
       'eTagResponse': 'AbCdEfGhI01',
       'id': 'AbCdEfGhIjKlMnOpQr0123',
       'isShared': False,
       'kind': 'FILE',
       'labels': [],
       'modifiedDate': '2015-01-01T00:00:00.000Z',
       'name': 'empty.txt',
       'parents': ['0123AbCdEfGhIjKlMnOpQr'],
       'restricted': False,
       'status': 'AVAILABLE',
       'version': 1
}

The modifiedDate and version keys get updated each time the content or metadata is updated. contentProperties['version'] gets updated on overwrite.

A folder’s JSON looks similar, but it lacks the contentProperties dictionary.

isShared is set to False even when a node is actually shared.

Caution

ACD allows hard links for folders!

acdcli.api.new_dau()[source]