+ pip install anesto
arl
or Akamai Resource Locator, here, is a NetStorage target for an operation; examples are
akamai://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/395007
The host name and CP code (here 395007
) are two required elements of the arl
.
Trailing slash doesn't indicate files inside the target folder, so avoiding it is a cleaner practice.
key
and keyname
- a pair you must have for authentication when using NetStorage.
You can start working with NetStorage like so:
import anesto
ns = 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 by ns
rely on Requests module and return Response 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 on Client()
instance as per above.
url_safe_chars
is exposed to let you deal with implementations being out of sync, url-encoding of tilda is one example.
Any 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 only
We further assume that key
and keyname
are 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 only
ns.delete(arl, key, keyname)
# files and symlinks only
print(ns.xdir(arl, key, keyname).text)
# xdir().text returns XML string describing contents of a folder specified by arl
# folders only
print(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 only
ns.mkdir(arl, key, keyname)
# creates a folder
ns.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 only
ns.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 only
ns.rmdir(arl, key, keyname)
# removes an empty folder
# folders only
ns.rmdir_rec(arl, key, keyname)
# removes a folder recursively
# Only recursive function here with many HTTP calls. May crash on stack overflow
# folders only
print(ns.stat(arl, key, keyname).text)
# stat().text returns XML string describing metadata of any target specified by arl
# folders, files, symlinks
ns.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.
Packaging
pip install --upgrade setuptools wheel twine
python3 setup.py sdist bdist_wheel
twine upload dist/*
rm -r dist build anesto.egg-info