acdcli.api package¶
Submodules¶
acdcli.api.account module¶
ACD account information
acdcli.api.backoff_req module¶
-
class
acdcli.api.backoff_req.BackOffRequest(auth_callback: 'requests.auth.AuthBase')[source]¶ Bases:
objectWrapper 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__(auth_callback: 'requests.auth.AuthBase')[source]¶ Parameters: auth_callback – callable object that attaches auth info to a request
-
-
acdcli.api.backoff_req.CONN_TIMEOUT= 30¶ timeout for establishing a connection
-
acdcli.api.backoff_req.IDLE_TIMEOUT= 60¶ read timeout
-
acdcli.api.backoff_req.REQUESTS_TIMEOUT= (30, 60)¶ http://docs.python-requests.org/en/latest/user/advanced/#timeouts
acdcli.api.client module¶
-
class
acdcli.api.client.ACDClient(path='')[source]¶ Bases:
acdcli.api.account.AccountMixin,acdcli.api.content.ContentMixin,acdcli.api.metadata.MetadataMixin,acdcli.api.trash.TrashMixinProvides a client to the Amazon Cloud Drive RESTful interface.
-
content_url¶
-
metadata_url¶
-
-
acdcli.api.client.ENDPOINT_VAL_TIME= 259200¶ number of seconds for endpoint validity (3 days)
acdcli.api.common module¶
-
exception
acdcli.api.common.RequestError(status_code: int, msg: str)[source]¶ Bases:
ExceptionCatch-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.codes= <lookup 'status_codes'>¶
-
class
acdcli.api.content module¶
-
acdcli.api.content.CHUNK_MAX_RETRY= 5¶ retry limit for failed chunk
-
acdcli.api.content.CHUNK_SIZE= 524288000¶ download chunk size
-
class
acdcli.api.content.ContentMixin[source]¶ Bases:
objectImplements content portion of the ACD API.
-
chunked_download(*args, **kwargs)¶
-
clear_file(node_id: str) → dict[source]¶ Clears a file’s content by overwriting it with an empty BytesIO.
Parameters: node_id¶ – valid file node ID
-
download_chunk(node_id: str, offset: int, length: int, **kwargs) → bytearray[source]¶ Load a file chunk into memory.
Parameters: length¶ – the length of the download chunk
-
download_file(node_id: str, basename: str, dirname: str=None, **kwargs)[source]¶ Deals with download preparation, download with
chunked_download()and finish. Calls callbacks while fast forwarding through incomplete file (if existent). Will not check for existing file prior to download and overwrite existing file on finish.Parameters: - dirname¶ – a valid local directory name, or cwd if None
- basename¶ – a valid file name
- kwargs¶ –
- length: the total length of the file
- write_callbacks (list[function]): passed on to
chunked_download() - resume (bool=True): whether to resume if partial file exists
-
download_thumbnail(node_id: str, file_name: str, max_dim=128)[source]¶ Download a movie’s or picture’s thumbnail into a file. Officially supports the image formats JPEG, BMP, PNG, TIFF, some RAW formats and the video formats MP4, QuickTime, AVI, MTS, MPEG, ASF, WMV, FLV, OGG. See http://www.amazon.com/gp/help/customer/display.html?nodeId=201634590 Additionally supports MKV.
Parameters: max_dim¶ – maximum width or height of the resized image/video thumbnail
-
overwrite_file(node_id: str, file_name: str, read_callbacks: list=None, deduplication=False) → dict[source]¶
-
overwrite_stream(stream, node_id: str, read_callbacks: list=None) → dict[source]¶ Overwrite content of node with ID node_id with content of stream.
Parameters: stream¶ – readable object
-
response_chunk(node_id: str, offset: int, length: int, **kwargs) → requests.models.Response[source]¶
-
-
acdcli.api.content.FS_RW_CHUNK_SZ= 131072¶ basic chunk size for file system r/w operations
-
acdcli.api.content.PARTIAL_SUFFIX= '.__incomplete'¶ suffix (file ending) for incomplete files
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_changes(checkpoint='', include_purged=False) → 'Generator[ChangeSet]'[source]¶ Generates a ChangeSet for each checkpoint in changes response. See https://developer.amazon.com/public/apis/experience/cloud-drive/content/changes.
-
get_owner_id()[source]¶ Provisional function for retrieving the security profile’s name, a.k.a. owner id.
-
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)
-
acdcli.api.oauth module¶
-
class
acdcli.api.oauth.AppspotOAuthHandler(path)[source]¶ Bases:
acdcli.api.oauth.OAuthHandler-
APPSPOT_URL= 'https://tensile-runway-92512.appspot.com/'¶
-
-
class
acdcli.api.oauth.LocalOAuthHandler(path)[source]¶ Bases:
acdcli.api.oauth.OAuthHandlerA 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'¶
-
-
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_data'¶
-
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.treat_auth_token(time_: float)[source]¶ Adds expiration time to member OAuth dict using specified begin time.
-
class
acdcli.api.trash module¶
Node trashing and restoration. https://developer.amazon.com/public/apis/experience/cloud-drive/content/trash
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!