Package: anesto
Akamai NetStorage API for Python+ pip install anestoCommon Variablesarlor Akamai Resource Locator, here, is a NetStorage target for an operation; examples areakamai://example-nsu.akamaihd.net/395007/my/path/special.log
akamai://example-nsu.akamaihd.net/395007/my/path/
example-nsu.akamaihd.net/395007/my
example-nsu.akamaihd.net/395007The host name and CP code (here395007) are two required elements of thearl.
Trailing slash doesn't indicate files inside the target folder, so avoiding it is a cleaner practice.keyandkeyname- a pair you must have for authentication when using NetStorage.You can start working with NetStorage like so:importanestons=anesto.Client()# this will have the same effect as :ns=anesto.Client(retry_number=3,conn_timeout=6,read_timeout=9,url_safe_chars='/~')All functions available bynsrely onRequests moduleand returnResponse object, from where you can get all request-response headers and the status code.When renaming or removing a target you may wish to treat 404 response as success because when HTTP request is initially delivered but associated response is lost, and the client retries the same request on timeout, the server returns 404 as the job has already been done, and the old target is no longer there. You may change timeout-retry behaviour onClient()instance as per above.url_safe_charsis exposed to let you deal with implementations being out of sync,url-encoding of tildais one example.Available FunctionsAny function can be used like so:key='<yourAkamaiKey>'keyname='<yourAkamaiKeyname>'ns.download(arl,key,keyname,saveto)# arl e.g. akamai://example-nsu.akamaihd.net/395007/my/path/special.log# saveto is an existing folder or a file target, e.g. '~/Downloads'# files onlyWe further assume thatkeyandkeynameare defined...ns.upload(arl,key,keyname,file)# arl e.g. akamai://example-nsu.akamaihd.net/395007/my/path/special.log# file e.g. `~/Documents/special.log`# files onlyns.delete(arl,key,keyname)# files and symlinks onlyprint(ns.xdir(arl,key,keyname).text)# xdir().text returns XML string describing contents of a folder specified by arl# folders onlyprint(ns.xdu(arl,key,keyname).text)# xdu().text returns XML string with metadata, such as total number of files and# disk space taken by a folder specified by arl# folders onlyns.mkdir(arl,key,keyname)# creates a folderns.mtime(arl,key,keyname,988888888)# cannot change folders# changes modification time stamp to unix epoch specified e.g.ns.quickdelete(arl,key,keyname)# Recursive folder remover - must be explicitly enabled by Akamai, see rmdir_rec() below# folders onlyns.rename(arl,key,keyname,uri):# all path folders must exist, moves under same CP code only# uri e.g. "/395007/mypath/dir-v-test/vtest2"# uri e.g. "../vtest" (relative to arl)# files and symlinks onlyns.rmdir(arl,key,keyname)# removes an empty folder# folders onlyns.rmdir_rec(arl,key,keyname)# removes a folder recursively# Only recursive function here with many HTTP calls. May crash on stack overflow# folders onlyprint(ns.stat(arl,key,keyname).text)# stat().text returns XML string describing metadata of any target specified by arl# folders, files, symlinksns.symlink(arl,key,keyname,target)# creates a symlink specified by arl# target e.g. "/395007/my/path/dir-v-test/vtest2"# target e.g. "../vtest/" (relative to arl)Symlinks does not work as such when you access NetStorage, they are followed by Akamai CDN using them as the origin.Packagingpip install --upgrade setuptools wheel twine
python3 setup.py sdist bdist_wheel
twine upload dist/*
rm -r dist build anesto.egg-info