Registry / http-networking / edgegrid-python

edgegrid-python

JSON →
library2.0.7pypypi✓ verified 23d ago

edgegrid-python provides the client authentication protocol for accessing Akamai's APIs, designed to integrate seamlessly with the popular `requests` library. It handles the cryptographic signing of requests required by the Akamai EdgeGrid specification. The current version is 2.0.5, with frequent releases primarily focused on security updates and dependency management, and less frequent but significant feature or breaking changes.

pip install edgegrid-python
INSTALL
IMPORT
SIG · EDGEGRID-PYTHON
E
edgegrid-python
http-networkingpythonv2.0.7
Install
2.4s avg
Import
376ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.384s · 21.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.368s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EdgeGridAuth
from akamai.edgegrid import EdgeGridAuth
EdgeGridAuthHeaders
from akamai.edgegrid import EdgeGridAuthHeaders
from akamai.edgegrid.auth import EdgeGridAuthHeaders
The `EdgeGridAuthHeaders` class is directly importable from the top-level `akamai.edgegrid` package since v1.0.0.

This quickstart demonstrates how to authenticate `requests` sessions using `EdgeGridAuth` with credentials typically loaded from environment variables or an `.edgerc` file. It constructs a `requests.Session` object, applies the `EdgeGridAuth` instance, and then makes an example GET request to an Akamai API endpoint, handling potential errors.

import requests import os from akamai.edgegrid import EdgeGridAuth # For simplicity, using environment variables. # In production, use a .edgerc file (e.g., ~/.edgerc) and specify a section. # Example .edgerc section: # [default] # host = your_api_host.akadns.net # client_token = YOUR_CLIENT_TOKEN # client_secret = YOUR_CLIENT_SECRET # access_token = YOUR_ACCESS_TOKEN # Configure from environment variables (less secure for production) client_token = os.environ.get('AKAMAI_CLIENT_TOKEN', 'YOUR_CLIENT_TOKEN_HERE') client_secret = os.environ.get('AKAMAI_CLIENT_SECRET', 'YOUR_CLIENT_SECRET_HERE') access_token = os.environ.get('AKAMAI_ACCESS_TOKEN', 'YOUR_ACCESS_TOKEN_HERE') host = os.environ.get('AKAMAI_HOST', 'https://your-api-host.akadns.net') if client_token == 'YOUR_CLIENT_TOKEN_HERE' or \ client_secret == 'YOUR_CLIENT_SECRET_HERE' or \ access_token == 'YOUR_ACCESS_TOKEN_HERE' or \ host == 'https://your-api-host.akadns.net': print("Warning: Please set AKAMAI_CLIENT_TOKEN, AKAMAI_CLIENT_SECRET, AKAMAI_ACCESS_TOKEN, and AKAMAI_HOST environment variables or update the example with actual credentials.") print("Or configure a .edgerc file and initialize EdgeGridAuth with 'client_token=None' and 'section='your_section_name'") else: # Initialize EdgeGridAuth with credentials (from env vars in this case) # For .edgerc file, use: auth = EdgeGridAuth(client_token=None, section='default') auth = EdgeGridAuth( client_token=client_token, client_secret=client_secret, access_token=access_token, base_url=host ) # Create a requests session and apply EdgeGridAuth session = requests.Session() session.auth = auth # Example API call (replace with an actual Akamai API endpoint) try: response = session.get(f'{host}/diagnostic-tools/v2/locations') # Example path response.raise_for_status() # Raise an exception for HTTP errors print(f"Successfully authenticated and fetched data: {response.status_code}") # print(response.json()) # Uncomment to see the response body except requests.exceptions.HTTPError as e: print(f"HTTP Error: {e} - {e.response.text}") except requests.exceptions.RequestException as e: print(f"Request Error: {e}")
Debug
Known issues
breakingVersion 2.0.0 discontinued support for Python 2.7. The minimum supported Python version became 3.9.
fix
Upgrade your Python environment to 3.9 or newer before upgrading edgegrid-python to 2.0.0 or later.
affects: <2.0.0
breakingVersion 2.0.3 dropped support for Python 3.9. The minimum supported Python version is now 3.10.
fix
Ensure your Python environment is 3.10 or newer when using edgegrid-python 2.0.3 and subsequent versions.
affects: >=2.0.3
breakingAs of v2.0.0, the `__init__` function of `EdgeGridAuth` and `EdgeGridAuthHeaders` now accepts `headers_to_sign` and `max_body` parameters exclusively as keyword-only arguments. Direct positional arguments for these will raise errors.
fix
If you were passing `headers_to_sign` or `max_body` positionally, update your calls to `EdgeGridAuth(..., headers_to_sign=['X-Akamai-Match'], max_body=2048)`.
affects: >=2.0.0
gotchaIncorrect configuration of `.edgerc` file path or missing/incorrect environment variables are common causes of authentication failures. The library searches for `~/.edgerc` by default or can be pointed to a custom path.
fix
Ensure your `.edgerc` file is correctly formatted, accessible, and in the expected location (`~/.edgerc`), or explicitly specify its path and section in the `EdgeGridAuth` constructor (e.g., `EdgeGridAuth(section='my_section', config_file='/path/to/my_edgerc')`). Alternatively, use environment variables like `EG_CLIENT_TOKEN`.
affects: All
gotchaThe `max_body` parameter (default 2048 bytes) truncates request bodies for signature generation if the body exceeds this size. For large POST/PUT requests, especially those with binary data, this can lead to signature mismatches if the API expects the full body to be signed.
fix
For requests with larger bodies, increase `max_body` when initializing `EdgeGridAuth` (e.g., `EdgeGridAuth(..., max_body=16384)`). Be aware that extremely large `max_body` values can impact performance due to increased hash computation.
affects: All
Errors
Common errors & fixes
configparser.NoSectionError: No section: 'default'
This error occurs when the `edgegrid-python` library cannot find the specified section (often 'default') in your `.edgerc` credentials file, or the file itself is not found or is unreadable.
fix
Ensure your `.edgerc` file exists in the expected location (e.g., `~/.edgerc`), is properly formatted with a `[default]` section containing your credentials, and is readable by the Python process. If using a custom path, explicitly provide it when initializing `EdgeRc` (e.g., `EdgeRc('/path/to/your/.edgerc')`).
Invalid Signature
This error, often appearing as 'The signature does not match' in the API response, indicates that the cryptographic signature generated by `edgegrid-python` for your request does not match the signature expected by the Akamai API. Common causes include incorrect API credentials (client token, client secret, access token, host), issues with the request body size exceeding limits for signing, or malformed requests.
fix
Verify that all API credentials in your `.edgerc` file or hardcoded in your script are correct and match what Akamai provided. For requests with a body, be aware of the `max_body` configuration setting; if your body size exceeds this, only a portion is signed. Ensure multi-part form data is handled correctly as it can also lead to signature mismatches.
ModuleNotFoundError: No module named 'akamai.edgegrid'
This Python error means the `edgegrid-python` library or its `akamai.edgegrid` package was not found by your Python interpreter. This typically happens if the library was not installed, was installed into a different Python environment, or there are path issues.
fix
Install the library using pip: `pip install edgegrid-python`. If you have multiple Python versions, use `pip3 install edgegrid-python` to ensure it installs for Python 3. Always work within a virtual environment to manage dependencies.
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128)
This error, often seen during installation or when using related tools like `httpie-edgegrid`, indicates an incompatibility with Python 2, which is no longer supported by `edgegrid-python` and its ecosystem. The error arises from Python 2's default ASCII handling attempting to decode non-ASCII bytes.
fix
Ensure you are using Python 3.10 or later. If encountering this during installation, explicitly use `pip3` to install the package: `pip3 install edgegrid-python` or `pip3 install httpie-edgegrid`.
Upgrade
Version history
2.0.7latest on PyPI · released May 19, 2026
Audit
Dependencies
requestsrequiredWhile decoupled as a direct dependency in v1.3.0+, this library's primary use case is to provide authentication for `requests.Session` objects.
Agent activity
81 hits · last 30 days
node
78
Bingbot
1
OpenAI (training)
1
Resources