Akamai NetStorage API for Python
Project description
Akamai NetStorage API for Python
+ pip install anesto
Common Variables
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.
Available Functions
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file anesto-1.0.tar.gz
.
File metadata
- Download URL: anesto-1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aff387aecfa1360b0549cf309411001bc2871a8818ef0ff457b0124b0a05625b |
|
MD5 | 10d26d6175c450f7645c5e5f0314dcbf |
|
BLAKE2b-256 | dcfe3ae47c931084c40ece6e37520e50e2297edad95d9ca995c0dd53edfdc6bd |
File details
Details for the file anesto-1.0-py3-none-any.whl
.
File metadata
- Download URL: anesto-1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 527d714469b1d6067f0edbe9853e7bd166c3d99431d86ff9f4470619bfd5cf36 |
|
MD5 | 46c3bf379479a4f1a15518b2f780fa52 |
|
BLAKE2b-256 | 6af44d9917b52f60d003e16e8c7eb4f8cde7440cc81466fc624d79cc8e24e0d0 |