Python is a programming language that you can use to manage your Akamai services.
Download the Python release compatible with your operating system at https://www.python.org/downloads/ and install it.
In order to complete these steps, you need to first Create authentication credentials.
Follow these steps to use the
python-edgegrid authentication handler.
Install the EdgeGrid authentication for Python.
pip install edgegrid-python
Edit this code with the variables from your credentials file.
You'll need the values for the tokens from your .edgerc file.
import requests from akamai.edgegrid import EdgeGridAuth from urllib.parse import urljoin baseurl = 'https://akaa-WWWWWWWWWWWW.luna.akamaiapis.net/' # this is the "host" value from your credentials file s = requests.Session() s.auth = EdgeGridAuth( client_token='ccccccccccccccccc', client_secret='ssssssssssssssssss', access_token='aaaaaaaaaaaaaaaaaaaaa' ) result = s.get(urljoin(baseurl, '/contract-api/v1/contracts/identifiers')) print(result.status_code) print(result.json())
Run your code.
You'll see a response like this:
Example API call:
>>> import requests >>> from akamai.edgegrid import EdgeGridAuth, EdgeRc >>> from urllib.parse import urljoin >>> edgerc = EdgeRc('~/.edgerc') >>> section = 'default' >>> baseurl = 'https://%s' % edgerc.get(section, 'host') >>> s = requests.Session() >>> s.auth = EdgeGridAuth.from_edgerc(edgerc, section) >>> result = s.get(urljoin(baseurl, '/diagnostic-tools/v2/ghost-locations/available')) >>> result.status_code 200 >>> result.json()['locations']['value'] Oakbrook, IL, United States ...
.edgrcfile has more than one credential set separated with a [header], use the
section =argument to specify which section from the configuration file contains the desired credentials for your API request.
Access the GitHub repository at EdgeGrid for Python.
A virtual environment is a tool to keep the dependencies required by different projects in separate places. The virtual environment tool in Python is called
Learn how to set up a virtual environment and install the correct libraries to achieve a consistent Python development environment.
Install the virtualenv tool.
pip install virtualenv
Initialize your environment.
This installs python, pip, and basic libraries within the project folder,
Activate your environment.
source myproject / venv / bin / activate
Your prompt will change to show that you are now working in a virtual environment. You'll see something like:
( venv ) user@machine $
Install libraries for the project.
pip install < library file >
requirements.txtfile to remember the dependencies.
pip freeze > myproject / requirements . txt
requirements.txtfile contains the necessary dependencies for your project. It will look something like this:
appdirs == 1.4 .3 asn1crypto == 0.22 .0 cffi == 1.10 .0 cryptography == 1.8 .1 enum34 == 1.1 .6 idna == 2.5 ipaddress == 1.0 .18 jsontree == 0.4 .3 ndg - httpsclient == 0.4 .2 packaging == 16.8 pyasn1 == 0.2 .3 pycparser == 2.17 pyOpenSSL == 17.0 .0 pyparsing == 2.2 .0 requests == 2.14 .2 six == 1.10 .0 urllib3 == 1.21 .1
requirements.txtfile along with the project code into your repository.
If you, or another developer, add functionality that requires a new library, you'll add it to this
requirements.txtfile. That way, when other developers pull the update from the source code repository, they'll be aware of the new dependencies and able to install them easily.
Any developer can use the virtual environment you created. The project setup is straightforward.
To create the virtual environment, first install
pip install virtualenv
Create a folder and activate the virtual environment.
virtualenv myproject source myproject / venv / bin / activate
Check out the latest code from the repository.
Navigate to the directory that contains the project.
( venv ) user@machine $ cd myproject / myrepo
Install the dependencies.
pip - r requirements . txt
Updated 7 months ago