{"id":22394316,"url":"https://github.com/akamai/akamaiopen-edgegrid-python","last_synced_at":"2025-05-15T13:08:15.827Z","repository":{"id":15711161,"uuid":"18449175","full_name":"akamai/AkamaiOPEN-edgegrid-python","owner":"akamai","description":"This library implements an Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme","archived":false,"fork":false,"pushed_at":"2025-05-12T03:03:48.000Z","size":160,"stargazers_count":92,"open_issues_count":5,"forks_count":52,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-05-15T13:08:04.203Z","etag":null,"topics":["akamai","akamai-devexp","authentication","devexp-edgegrid","open"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akamai.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-04-04T19:02:14.000Z","updated_at":"2025-05-06T06:58:37.000Z","dependencies_parsed_at":"2025-02-28T22:11:07.671Z","dependency_job_id":"15bd139b-aa85-498b-a25e-492b2106577d","html_url":"https://github.com/akamai/AkamaiOPEN-edgegrid-python","commit_stats":{"total_commits":80,"total_committers":23,"mean_commits":"3.4782608695652173","dds":0.6875,"last_synced_commit":"59bc13eadd4616126876a7ed82a789096df79e54"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamai%2FAkamaiOPEN-edgegrid-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamai%2FAkamaiOPEN-edgegrid-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamai%2FAkamaiOPEN-edgegrid-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akamai%2FAkamaiOPEN-edgegrid-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akamai","download_url":"https://codeload.github.com/akamai/AkamaiOPEN-edgegrid-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346624,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["akamai","akamai-devexp","authentication","devexp-edgegrid","open"],"created_at":"2024-12-05T05:09:42.848Z","updated_at":"2025-05-15T13:08:10.819Z","avatar_url":"https://github.com/akamai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EdgeGrid for Python\n\nThis library implements an Authentication handler for [HTTP requests](https://requests.readthedocs.io/en/latest/) using the [Akamai EdgeGrid Authentication](https://techdocs.akamai.com/developer/docs/authenticate-with-edgegrid) scheme for Python.\n\n## Install\n\nTo use the library, you need to have Python 3.9 or later installed on your system. You can download it from [https://www.python.org/downloads/](https://www.python.org/downloads/).\n\n\u003e __NOTE:__ Python 2 is no longer supported by the [Python Software Foundation](https://www.python.org/doc/sunset-python-2/). You won't be able to use the library with Python 2.\n\nThen, install the `edgegrid-python` authentication handler from sources by running this command from the project root directory:\n\n   ```\n   pip install .\n   ```\n\nAlternatively, you can install it from PyPI (Python Package Index) by running:\n\n```\npip install edgegrid-python\n```\n\n## Authentication\n\nWe provide authentication credentials through an API client. Requests to the API are signed with a timestamp and are executed immediately.\n\n1. [Create authentication credentials](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials).\n   \n2. Place your credentials in an EdgeGrid resource file, `.edgerc`, under a heading of `[default]` at your local home directory or the home directory of a web-server user.\n   \n   ```\n    [default]\n    client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=\n    host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net\n    access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij\n    client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj\n    ```\n\n3. Use your local `.edgerc` by providing the path to your resource file and credentials' section header.\n   \n   ```python\n    import requests\n    from akamai.edgegrid import EdgeGridAuth, EdgeRc\n\n    edgerc = EdgeRc('~/.edgerc')\n    section = 'default'\n    baseurl = 'https://%s' % edgerc.get(section, 'host')\n\n    session = requests.Session()\n    session.auth = EdgeGridAuth.from_edgerc(edgerc, section)\n   ```\n   Or hard code them as variables.\n   \n   ```python\n    import requests\n    from akamai.edgegrid import EdgeGridAuth\n\n    session = requests.Session()\n    session.auth = EdgeGridAuth(\n        client_token='akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj',\n        client_secret='C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=',\n        access_token='akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij'\n    )\n   ```\n\n## Use\n\nTo use the library, provide the path to your `.edgerc`, your credentials section header, and the appropriate endpoint information.\n\n```python\nimport requests\nimport json\nfrom akamai.edgegrid import EdgeGridAuth, EdgeRc\nfrom urllib.parse import urljoin\n\nedgerc = EdgeRc('~/.edgerc')\nsection = 'default'\nbaseurl = 'https://%s' % edgerc.get(section, 'host')\n\nsession = requests.Session()\nsession.auth = EdgeGridAuth.from_edgerc(edgerc, section)\n\npath = '/identity-management/v3/user-profile'\nheaders = {\n  \"Accept\": \"application/json\"\n} \nquerystring = {\n  \"actions\": True,\n  \"authGrants\": True,\n  \"notifications\": True\n}  \n\nresult = session.get(urljoin(baseurl, path), headers=headers, params=querystring)\nprint(result.status_code)\nprint(json.dumps(result.json(), indent=2))\n```\n\n### Query string parameters\n\nWhen entering query parameters use the `querystring` property. Set up the parameters as name-value pairs in an object.\n\n```python\nedgerc = EdgeRc('~/.edgerc')\nsection = 'default'\nbaseurl = 'https://%s' % edgerc.get(section, 'host')\n\nsession = requests.Session()\nsession.auth = EdgeGridAuth.from_edgerc(edgerc, section)\n\npath = '/identity-management/v3/user-profile'\nquerystring = {\n  \"actions\": True,\n  \"authGrants\": True,\n  \"notifications\": True\n}  \n\nresult = session.get(urljoin(baseurl, path), params=querystring)\n```\n\n### Headers\n\nEnter request headers in the `headers` property as name-value pairs in an object.\n\n\u003e __NOTE:__ You don't need to include the `Content-Type` and `Content-Length` headers. The authentication layer adds these values.\n\n```python\nedgerc = EdgeRc('~/.edgerc')\nsection = 'default'\nbaseurl = 'https://%s' % edgerc.get(section, 'host')\n\nsession = requests.Session()\nsession.auth = EdgeGridAuth.from_edgerc(edgerc, section)\n\npath = '/identity-management/v3/user-profile'\nheaders = {\n  \"Accept\": \"application/json\"\n} \n\nresult = session.get(urljoin(baseurl, path), headers=headers)\n```\n\n### Body data\n\nProvide the request body as an object in the `payload` property.\n\n```python\nedgerc = EdgeRc('~/.edgerc')\nsection = 'default'\nbaseurl = 'https://%s' % edgerc.get(section, 'host')\n\nsession = requests.Session()\nsession.auth = EdgeGridAuth.from_edgerc(edgerc, section)\n\npath = '/identity-management/v3/user-profile/basic-info'\npayload = {\n    \"contactType\": \"Billing\",\n    \"country\": \"USA\",\n    \"firstName\": \"John\",\n    \"lastName\": \"Smith\",\n    \"preferredLanguage\": \"English\",\n    \"sessionTimeOut\": 30,\n    \"timeZone\": \"GMT\",\n    \"phone\": \"3456788765\"\n}\n\nresult = session.put(urljoin(baseurl, path), json=payload)\n```\n\nAs the `data` parameter for the `session` methods, EdgeGrid for Python\ncurrently supports the `bytes` and `requests_toolbelt.MultipartEncoder`\ntypes or a file-like object.\n\n### Debug\n\nEnable debugging to get additional information about a request.\n\nTo log requests, use the built-in request logging. Add this before making a request:\n\n```python\nimport logging\nfrom http.client import HTTPConnection\nHTTPConnection.debuglevel = 1\nlogging.basicConfig()\nlogging.getLogger().setLevel(logging.DEBUG)\nurllib_log = logging.getLogger(\"urllib3\")\nurllib_log.setLevel(logging.DEBUG)\nurllib_log.propagate = True\n```\n\nThis will print everything apart from the HTTP response body. See the [Requests library for Python](https://requests.readthedocs.io/en/latest/api/#api-changes) for the original recipe.\n\nTo log specific parts like URL, status code, headers, or body, add this:\n\n```python\nimport requests\nimport logging\nimport json\nfrom akamai.edgegrid import EdgeGridAuth, EdgeRc\nfrom urllib.parse import urljoin\n\nlogger = logging.getLogger('requests_logger')\nlogging.basicConfig(level=logging.DEBUG)\n\nedgerc = EdgeRc('~/.edgerc')\nsection = 'default'\nbaseurl = 'https://%s' % edgerc.get(section, 'host')\n\nsession = requests.Session()\nsession.auth = EdgeGridAuth.from_edgerc(edgerc, section)\n\npath = '/identity-management/v3/user-profile'\n\nresult = session.get(urljoin(baseurl, path))\nlogger.debug(f'URL: {result.url}')\nlogger.debug(f'Status Code: {result.status_code}')\nlogger.debug(f'Headers: {result.headers}')\nlogger.debug(f'Body: {result.json()}')\n```\n\n## Virtual environment\n\nA [virtual environment](https://docs.python.org/3/library/venv.html) is a tool to keep dependencies required by different projects in separate places. The `venv` module is included in Python 3 by default.\n\nSet up a virtual environment:\n\n1. Initialize your environment in a new directory.\n\n   ```\n   // Unix/macOS\n   python3 -m venv ~/Desktop/myenv\n\n   // Windows\n   py -m venv ~/Desktop/myenv\n   ```\n\n   This creates a `venv` in the specified directory as well as copies pip into it.\n\n2. Activate your environment.\n   \n   ```\n   // Unix/macOS\n   source ~/Desktop/myenv/bin/activate\n\n   // Windows\n   ~/Desktop/myenv/Scripts/activate\n   ```\n\n   Your prompt will change to show you're working in a virtual environment, for example:\n\n   ```\n   (myenv) jsmith@abc-de12fg $\n   ```\n\n3. To recreate the environment, install the required dependencies within your project.\n\n   ```\n   pip install -r dev-requirements.txt\n   ```\n\n4. Run the tests.\n\n   ```\n   // Unix/macOS\n   pytest -v\n\n   // Windows\n   py -m pytest -v\n   ```\n\n5. To deactivate your environment, run the `deactivate` command.\n\n## Reporting issues\n\nTo report an issue or make a suggestion, create a new [GitHub issue](https://github.com/akamai/AkamaiOPEN-edgegrid-python/issues).\n\n## License\n\nCopyright 2024 Akamai Technologies, Inc. All rights reserved.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n\nUnless 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakamai%2Fakamaiopen-edgegrid-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakamai%2Fakamaiopen-edgegrid-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakamai%2Fakamaiopen-edgegrid-python/lists"}