Skip to main content

{OPEN} client authentication protocol for python-requests

Project description

EdgeGrid for Python

This library implements an Authentication handler for HTTP requests using the Akamai EdgeGrid Authentication scheme for Python.

Install

To use the library, you need to have Python 3.10 or later installed on your system. You can download it from https://www.python.org/downloads/.

NOTE: Python 2 is no longer supported by the Python Software Foundation. You won't be able to use the library with Python 2.

Then, install the edgegrid-python authentication handler from sources by running this command from the project root directory:

pip install .

Alternatively, you can install it from PyPI (Python Package Index) by running:

pip install edgegrid-python

Authentication

We provide authentication credentials through an API client. Requests to the API are signed with a timestamp and are executed immediately.

  1. Create authentication credentials.

  2. Place your credentials in an EdgeGrid resource file, .edgerc, under a heading of [default] at your local home directory.

     [default]
     client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=
     host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net
     access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij
     client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj
    
  3. Use your local .edgerc by providing the path to your resource file and credentials' section header.

     import requests
     from akamai.edgegrid import EdgeGridAuth, EdgeRc
    
     edgerc = EdgeRc('~/.edgerc')
     section = 'default'
     baseurl = 'https://%s' % edgerc.get(section, 'host')
    
     session = requests.Session()
     session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
    

    Or hard code them as variables.

     import requests
     from akamai.edgegrid import EdgeGridAuth
    
     session = requests.Session()
     session.auth = EdgeGridAuth(
         client_token='akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj',
         client_secret='C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=',
         access_token='akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij'
     )
    

Use

To use the library, provide the path to your .edgerc, your credentials section header, and the appropriate endpoint information.

import requests
import json
from akamai.edgegrid import EdgeGridAuth, EdgeRc
from urllib.parse import urljoin

edgerc = EdgeRc('~/.edgerc')
section = 'default'
baseurl = 'https://%s' % edgerc.get(section, 'host')

session = requests.Session()
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)

path = '/identity-management/v3/user-profile'
headers = {
  "Accept": "application/json"
} 
querystring = {
  "actions": True,
  "authGrants": True,
  "notifications": True
}  

result = session.get(urljoin(baseurl, path), headers=headers, params=querystring)
print(result.status_code)
print(json.dumps(result.json(), indent=2))

Query string parameters

When entering query parameters use the querystring property. Set up the parameters as name-value pairs in an object.

edgerc = EdgeRc('~/.edgerc')
section = 'default'
baseurl = 'https://%s' % edgerc.get(section, 'host')

session = requests.Session()
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)

path = '/identity-management/v3/user-profile'
querystring = {
  "actions": True,
  "authGrants": True,
  "notifications": True
}  

result = session.get(urljoin(baseurl, path), params=querystring)

Headers

Enter request headers in the headers property as name-value pairs in an object.

NOTE: You don't need to include the Content-Type and Content-Length headers. The authentication layer adds these values.

edgerc = EdgeRc('~/.edgerc')
section = 'default'
baseurl = 'https://%s' % edgerc.get(section, 'host')

session = requests.Session()
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)

path = '/identity-management/v3/user-profile'
headers = {
  "Accept": "application/json"
} 

result = session.get(urljoin(baseurl, path), headers=headers)

Body data

Provide the request body as an object in the payload property.

edgerc = EdgeRc('~/.edgerc')
section = 'default'
baseurl = 'https://%s' % edgerc.get(section, 'host')

session = requests.Session()
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)

path = '/identity-management/v3/user-profile/basic-info'
payload = {
    "contactType": "Billing",
    "country": "USA",
    "firstName": "John",
    "lastName": "Smith",
    "preferredLanguage": "English",
    "sessionTimeOut": 30,
    "timeZone": "GMT",
    "phone": "3456788765"
}

result = session.put(urljoin(baseurl, path), json=payload)

As the data parameter for the session methods, EdgeGrid for Python currently supports the bytes and requests_toolbelt.MultipartEncoder types or a file-like object.

Debug

Enable debugging to get additional information about a request.

To log requests, use the built-in request logging. Add this before making a request:

import logging
from http.client import HTTPConnection
HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
urllib_log = logging.getLogger("urllib3")
urllib_log.setLevel(logging.DEBUG)
urllib_log.propagate = True

This will print everything apart from the HTTP response body. See the Requests library for Python for the original recipe.

To log specific parts like URL, status code, headers, or body, add this:

import requests
import logging
import json
from akamai.edgegrid import EdgeGridAuth, EdgeRc
from urllib.parse import urljoin

logger = logging.getLogger('requests_logger')
logging.basicConfig(level=logging.DEBUG)

edgerc = EdgeRc('~/.edgerc')
section = 'default'
baseurl = 'https://%s' % edgerc.get(section, 'host')

session = requests.Session()
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)

path = '/identity-management/v3/user-profile'

result = session.get(urljoin(baseurl, path))
logger.debug(f'URL: {result.url}')
logger.debug(f'Status Code: {result.status_code}')
logger.debug(f'Headers: {result.headers}')
logger.debug(f'Body: {result.json()}')

Virtual environment

A virtual environment is a tool to keep dependencies required by different projects in separate places. The venv module is included in Python 3 by default.

Set up a virtual environment:

  1. Initialize your environment in a new directory.

    // Unix/macOS
    python3 -m venv ~/Desktop/myenv
    
    // Windows
    py -m venv ~/Desktop/myenv
    

    This creates a venv in the specified directory as well as copies pip into it.

  2. Activate your environment.

    // Unix/macOS
    source ~/Desktop/myenv/bin/activate
    
    // Windows
    ~/Desktop/myenv/Scripts/activate
    

    Your prompt will change to show you're working in a virtual environment, for example:

    (myenv) jsmith@abc-de12fg $
    
  3. To recreate the environment, install the required dependencies within your project.

    pip install -r dev-requirements.txt
    
  4. Run the tests.

    // Unix/macOS
    pytest -v
    
    // Windows
    py -m pytest -v
    
  5. To deactivate your environment, run the deactivate command.

Reporting issues

To report an issue or make a suggestion, create a new GitHub issue.

License

Copyright 2026 Akamai Technologies, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

edgegrid_python-2.0.7.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

edgegrid_python-2.0.7-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file edgegrid_python-2.0.7.tar.gz.

File metadata

  • Download URL: edgegrid_python-2.0.7.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for edgegrid_python-2.0.7.tar.gz
Algorithm Hash digest
SHA256 80d261ff9673384d04f8a0681d4649c709de684a942234779aa94e7f2821a14d
MD5 ffc1521903c735c5477b588bf8431291
BLAKE2b-256 2fa9518023db7619e8fdae662a9cd48e58a56484d09fb589cd6a9c614b6df7cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for edgegrid_python-2.0.7.tar.gz:

Publisher: publish-to-pypi.yml on akamai/AkamaiOPEN-edgegrid-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file edgegrid_python-2.0.7-py3-none-any.whl.

File metadata

  • Download URL: edgegrid_python-2.0.7-py3-none-any.whl
  • Upload date:
  • Size: 26.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for edgegrid_python-2.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 da6058a6ba2f434640a11478cb3cbb135e541a662c77a671b425ad43cd51b5dc
MD5 621567e2e82c399d8f7922fe756ee069
BLAKE2b-256 bf27374ebb3f79bbb038823233f6c3607a9bc02db7a8d4a0be76e65110dedc45

See more details on using hashes here.

Provenance

The following attestation bundles were made for edgegrid_python-2.0.7-py3-none-any.whl:

Publisher: publish-to-pypi.yml on akamai/AkamaiOPEN-edgegrid-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page