edgegrid-python 1.3.1__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/LICENSE +1 -1
- edgegrid_python-2.0.0/PKG-INFO +304 -0
- edgegrid_python-2.0.0/README.md +282 -0
- edgegrid_python-2.0.0/akamai/__init__.py +2 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/akamai/edgegrid/__init__.py +3 -18
- edgegrid_python-2.0.0/akamai/edgegrid/edgegrid.py +323 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/akamai/edgegrid/edgerc.py +5 -28
- edgegrid_python-2.0.0/akamai/edgegrid/test/conftest.py +44 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/akamai/edgegrid/test/edgerc_that_doesnt_parse +1 -1
- edgegrid_python-2.0.0/akamai/edgegrid/test/test_edgegrid.py +390 -0
- edgegrid_python-2.0.0/akamai/edgegrid/test/testdata.json +18 -0
- edgegrid_python-2.0.0/edgegrid_python.egg-info/PKG-INFO +304 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/edgegrid_python.egg-info/SOURCES.txt +1 -0
- edgegrid_python-2.0.0/edgegrid_python.egg-info/requires.txt +11 -0
- edgegrid_python-2.0.0/requirements.txt +38 -0
- edgegrid_python-2.0.0/setup.py +34 -0
- edgegrid-python-1.3.1/PKG-INFO +0 -15
- edgegrid-python-1.3.1/README.md +0 -148
- edgegrid-python-1.3.1/akamai/__init__.py +0 -1
- edgegrid-python-1.3.1/akamai/edgegrid/edgegrid.py +0 -300
- edgegrid-python-1.3.1/akamai/edgegrid/test/test_edgegrid.py +0 -409
- edgegrid-python-1.3.1/akamai/edgegrid/test/testdata.json +0 -197
- edgegrid-python-1.3.1/edgegrid_python.egg-info/PKG-INFO +0 -15
- edgegrid-python-1.3.1/edgegrid_python.egg-info/requires.txt +0 -6
- edgegrid-python-1.3.1/requirements.txt +0 -6
- edgegrid-python-1.3.1/setup.py +0 -29
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/MANIFEST.in +0 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/akamai/edgegrid/test/__init__.py +0 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/akamai/edgegrid/test/sample_edgerc +0 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/edgegrid_python.egg-info/dependency_links.txt +0 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/edgegrid_python.egg-info/namespace_packages.txt +0 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/edgegrid_python.egg-info/top_level.txt +0 -0
- {edgegrid-python-1.3.1 → edgegrid_python-2.0.0}/setup.cfg +0 -0
|
@@ -176,7 +176,7 @@ recommend that a file or class name and description of purpose be included on
|
|
|
176
176
|
the same "printed page" as the copyright notice for easier identification within
|
|
177
177
|
third-party archives.
|
|
178
178
|
|
|
179
|
-
Copyright
|
|
179
|
+
Copyright 2024 Akamai Technologies, Inc. All rights reserved.
|
|
180
180
|
|
|
181
181
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
182
|
you may not use this file except in compliance with the License.
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: edgegrid-python
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: {OPEN} client authentication protocol for python-requests
|
|
5
|
+
Home-page: https://github.com/akamai/AkamaiOPEN-edgegrid-python
|
|
6
|
+
License: Apache 2.0
|
|
7
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: requests>=2.24.0
|
|
13
|
+
Requires-Dist: requests_toolbelt>=0.9.1
|
|
14
|
+
Requires-Dist: pyOpenSSL>=19.1.0
|
|
15
|
+
Requires-Dist: ndg-httpsclient>=0.5.1
|
|
16
|
+
Requires-Dist: pyasn1>=0.4.8
|
|
17
|
+
Requires-Dist: urllib3>=1.25.10
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pylint>=2.7.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest>=6.1.0; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-cov>=2.12.1; extra == "dev"
|
|
22
|
+
|
|
23
|
+
# EdgeGrid for Python
|
|
24
|
+
|
|
25
|
+
This 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.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
To 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/).
|
|
30
|
+
|
|
31
|
+
> __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.
|
|
32
|
+
|
|
33
|
+
Then, install the `edgegrid-python` authentication handler from sources by running this command from the project root directory:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
pip install .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Alternatively, you can install it from PyPI (Python Package Index) by running:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
pip install edgegrid-python
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Authentication
|
|
46
|
+
|
|
47
|
+
We provide authentication credentials through an API client. Requests to the API are signed with a timestamp and are executed immediately.
|
|
48
|
+
|
|
49
|
+
1. [Create authentication credentials](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials).
|
|
50
|
+
|
|
51
|
+
2. 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.
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
[default]
|
|
55
|
+
client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=
|
|
56
|
+
host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net
|
|
57
|
+
access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij
|
|
58
|
+
client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
3. Use your local `.edgerc` by providing the path to your resource file and credentials' section header.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import requests
|
|
65
|
+
from akamai.edgegrid import EdgeGridAuth, EdgeRc
|
|
66
|
+
|
|
67
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
68
|
+
section = 'default'
|
|
69
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
70
|
+
|
|
71
|
+
session = requests.Session()
|
|
72
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
73
|
+
```
|
|
74
|
+
Or hard code them as variables.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import requests
|
|
78
|
+
from akamai.edgegrid import EdgeGridAuth
|
|
79
|
+
|
|
80
|
+
session = requests.Session()
|
|
81
|
+
session.auth = EdgeGridAuth(
|
|
82
|
+
client_token='akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj',
|
|
83
|
+
client_secret='C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=',
|
|
84
|
+
access_token='akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij'
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Use
|
|
89
|
+
|
|
90
|
+
To use the library, provide the path to your `.edgerc`, your credentials section header, and the appropriate endpoint information.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import requests
|
|
94
|
+
import json
|
|
95
|
+
from akamai.edgegrid import EdgeGridAuth, EdgeRc
|
|
96
|
+
from urllib.parse import urljoin
|
|
97
|
+
|
|
98
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
99
|
+
section = 'default'
|
|
100
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
101
|
+
|
|
102
|
+
session = requests.Session()
|
|
103
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
104
|
+
|
|
105
|
+
path = '/identity-management/v3/user-profile'
|
|
106
|
+
headers = {
|
|
107
|
+
"Accept": "application/json"
|
|
108
|
+
}
|
|
109
|
+
querystring = {
|
|
110
|
+
"actions": True,
|
|
111
|
+
"authGrants": True,
|
|
112
|
+
"notifications": True
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
result = session.get(urljoin(baseurl, path), headers=headers, params=querystring)
|
|
116
|
+
print(result.status_code)
|
|
117
|
+
print(json.dumps(result.json(), indent=2))
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Query string parameters
|
|
121
|
+
|
|
122
|
+
When entering query parameters use the `querystring` property. Set up the parameters as name-value pairs in an object.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
126
|
+
section = 'default'
|
|
127
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
128
|
+
|
|
129
|
+
session = requests.Session()
|
|
130
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
131
|
+
|
|
132
|
+
path = '/identity-management/v3/user-profile'
|
|
133
|
+
querystring = {
|
|
134
|
+
"actions": True,
|
|
135
|
+
"authGrants": True,
|
|
136
|
+
"notifications": True
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
result = session.get(urljoin(baseurl, path), params=querystring)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Headers
|
|
143
|
+
|
|
144
|
+
Enter request headers in the `headers` property as name-value pairs in an object.
|
|
145
|
+
|
|
146
|
+
> __NOTE:__ You don't need to include the `Content-Type` and `Content-Length` headers. The authentication layer adds these values.
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
150
|
+
section = 'default'
|
|
151
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
152
|
+
|
|
153
|
+
session = requests.Session()
|
|
154
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
155
|
+
|
|
156
|
+
path = '/identity-management/v3/user-profile'
|
|
157
|
+
headers = {
|
|
158
|
+
"Accept": "application/json"
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
result = session.get(urljoin(baseurl, path), headers=headers)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Body data
|
|
165
|
+
|
|
166
|
+
Provide the request body as an object in the `payload` property.
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
170
|
+
section = 'default'
|
|
171
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
172
|
+
|
|
173
|
+
session = requests.Session()
|
|
174
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
175
|
+
|
|
176
|
+
path = '/identity-management/v3/user-profile/basic-info'
|
|
177
|
+
payload = {
|
|
178
|
+
"contactType": "Billing",
|
|
179
|
+
"country": "USA",
|
|
180
|
+
"firstName": "John",
|
|
181
|
+
"lastName": "Smith",
|
|
182
|
+
"preferredLanguage": "English",
|
|
183
|
+
"sessionTimeOut": 30,
|
|
184
|
+
"timeZone": "GMT",
|
|
185
|
+
"phone": "3456788765"
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
result = session.put(urljoin(baseurl, path), json=payload)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
As the `data` parameter for the `session` methods, EdgeGrid for Python
|
|
192
|
+
currently supports the `bytes` and `requests_toolbelt.MultipartEncoder`
|
|
193
|
+
types or a file-like object.
|
|
194
|
+
|
|
195
|
+
### Debug
|
|
196
|
+
|
|
197
|
+
Enable debugging to get additional information about a request.
|
|
198
|
+
|
|
199
|
+
To log requests, use the built-in request logging. Add this before making a request:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
import logging
|
|
203
|
+
from http.client import HTTPConnection
|
|
204
|
+
HTTPConnection.debuglevel = 1
|
|
205
|
+
logging.basicConfig()
|
|
206
|
+
logging.getLogger().setLevel(logging.DEBUG)
|
|
207
|
+
urllib_log = logging.getLogger("urllib3")
|
|
208
|
+
urllib_log.setLevel(logging.DEBUG)
|
|
209
|
+
urllib_log.propagate = True
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
This 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.
|
|
213
|
+
|
|
214
|
+
To log specific parts like URL, status code, headers, or body, add this:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
import requests
|
|
218
|
+
import logging
|
|
219
|
+
import json
|
|
220
|
+
from akamai.edgegrid import EdgeGridAuth, EdgeRc
|
|
221
|
+
from urllib.parse import urljoin
|
|
222
|
+
|
|
223
|
+
logger = logging.getLogger('requests_logger')
|
|
224
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
225
|
+
|
|
226
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
227
|
+
section = 'default'
|
|
228
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
229
|
+
|
|
230
|
+
session = requests.Session()
|
|
231
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
232
|
+
|
|
233
|
+
path = '/identity-management/v3/user-profile'
|
|
234
|
+
|
|
235
|
+
result = session.get(urljoin(baseurl, path))
|
|
236
|
+
logger.debug(f'URL: {result.url}')
|
|
237
|
+
logger.debug(f'Status Code: {result.status_code}')
|
|
238
|
+
logger.debug(f'Headers: {result.headers}')
|
|
239
|
+
logger.debug(f'Body: {result.json()}')
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Virtual environment
|
|
243
|
+
|
|
244
|
+
A [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.
|
|
245
|
+
|
|
246
|
+
Set up a virtual environment:
|
|
247
|
+
|
|
248
|
+
1. Initialize your environment in a new directory.
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
// Unix/macOS
|
|
252
|
+
python3 -m venv ~/Desktop/myenv
|
|
253
|
+
|
|
254
|
+
// Windows
|
|
255
|
+
py -m venv ~/Desktop/myenv
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
This creates a `venv` in the specified directory as well as copies pip into it.
|
|
259
|
+
|
|
260
|
+
2. Activate your environment.
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
// Unix/macOS
|
|
264
|
+
source ~/Desktop/myenv/bin/activate
|
|
265
|
+
|
|
266
|
+
// Windows
|
|
267
|
+
~/Desktop/myenv/Scripts/activate
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Your prompt will change to show you're working in a virtual environment, for example:
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
(myenv) jsmith@abc-de12fg $
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
3. To recreate the environment, install the required dependencies within your project.
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
pip install -r dev-requirements.txt
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
4. Run the tests.
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
// Unix/macOS
|
|
286
|
+
pytest -v
|
|
287
|
+
|
|
288
|
+
// Windows
|
|
289
|
+
py -m pytest -v
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
5. To deactivate your environment, run the `deactivate` command.
|
|
293
|
+
|
|
294
|
+
## Reporting issues
|
|
295
|
+
|
|
296
|
+
To report an issue or make a suggestion, create a new [GitHub issue](https://github.com/akamai/AkamaiOPEN-edgegrid-python/issues).
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
|
|
300
|
+
Copyright 2024 Akamai Technologies, Inc. All rights reserved.
|
|
301
|
+
|
|
302
|
+
Licensed 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.
|
|
303
|
+
|
|
304
|
+
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.
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# EdgeGrid for Python
|
|
2
|
+
|
|
3
|
+
This 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.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
To 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/).
|
|
8
|
+
|
|
9
|
+
> __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.
|
|
10
|
+
|
|
11
|
+
Then, install the `edgegrid-python` authentication handler from sources by running this command from the project root directory:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
pip install .
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Alternatively, you can install it from PyPI (Python Package Index) by running:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
pip install edgegrid-python
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Authentication
|
|
24
|
+
|
|
25
|
+
We provide authentication credentials through an API client. Requests to the API are signed with a timestamp and are executed immediately.
|
|
26
|
+
|
|
27
|
+
1. [Create authentication credentials](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials).
|
|
28
|
+
|
|
29
|
+
2. 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.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
[default]
|
|
33
|
+
client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=
|
|
34
|
+
host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net
|
|
35
|
+
access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij
|
|
36
|
+
client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
3. Use your local `.edgerc` by providing the path to your resource file and credentials' section header.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import requests
|
|
43
|
+
from akamai.edgegrid import EdgeGridAuth, EdgeRc
|
|
44
|
+
|
|
45
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
46
|
+
section = 'default'
|
|
47
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
48
|
+
|
|
49
|
+
session = requests.Session()
|
|
50
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
51
|
+
```
|
|
52
|
+
Or hard code them as variables.
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import requests
|
|
56
|
+
from akamai.edgegrid import EdgeGridAuth
|
|
57
|
+
|
|
58
|
+
session = requests.Session()
|
|
59
|
+
session.auth = EdgeGridAuth(
|
|
60
|
+
client_token='akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj',
|
|
61
|
+
client_secret='C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=',
|
|
62
|
+
access_token='akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij'
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Use
|
|
67
|
+
|
|
68
|
+
To use the library, provide the path to your `.edgerc`, your credentials section header, and the appropriate endpoint information.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import requests
|
|
72
|
+
import json
|
|
73
|
+
from akamai.edgegrid import EdgeGridAuth, EdgeRc
|
|
74
|
+
from urllib.parse import urljoin
|
|
75
|
+
|
|
76
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
77
|
+
section = 'default'
|
|
78
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
79
|
+
|
|
80
|
+
session = requests.Session()
|
|
81
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
82
|
+
|
|
83
|
+
path = '/identity-management/v3/user-profile'
|
|
84
|
+
headers = {
|
|
85
|
+
"Accept": "application/json"
|
|
86
|
+
}
|
|
87
|
+
querystring = {
|
|
88
|
+
"actions": True,
|
|
89
|
+
"authGrants": True,
|
|
90
|
+
"notifications": True
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
result = session.get(urljoin(baseurl, path), headers=headers, params=querystring)
|
|
94
|
+
print(result.status_code)
|
|
95
|
+
print(json.dumps(result.json(), indent=2))
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Query string parameters
|
|
99
|
+
|
|
100
|
+
When entering query parameters use the `querystring` property. Set up the parameters as name-value pairs in an object.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
104
|
+
section = 'default'
|
|
105
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
106
|
+
|
|
107
|
+
session = requests.Session()
|
|
108
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
109
|
+
|
|
110
|
+
path = '/identity-management/v3/user-profile'
|
|
111
|
+
querystring = {
|
|
112
|
+
"actions": True,
|
|
113
|
+
"authGrants": True,
|
|
114
|
+
"notifications": True
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
result = session.get(urljoin(baseurl, path), params=querystring)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Headers
|
|
121
|
+
|
|
122
|
+
Enter request headers in the `headers` property as name-value pairs in an object.
|
|
123
|
+
|
|
124
|
+
> __NOTE:__ You don't need to include the `Content-Type` and `Content-Length` headers. The authentication layer adds these values.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
128
|
+
section = 'default'
|
|
129
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
130
|
+
|
|
131
|
+
session = requests.Session()
|
|
132
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
133
|
+
|
|
134
|
+
path = '/identity-management/v3/user-profile'
|
|
135
|
+
headers = {
|
|
136
|
+
"Accept": "application/json"
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
result = session.get(urljoin(baseurl, path), headers=headers)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Body data
|
|
143
|
+
|
|
144
|
+
Provide the request body as an object in the `payload` property.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
148
|
+
section = 'default'
|
|
149
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
150
|
+
|
|
151
|
+
session = requests.Session()
|
|
152
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
153
|
+
|
|
154
|
+
path = '/identity-management/v3/user-profile/basic-info'
|
|
155
|
+
payload = {
|
|
156
|
+
"contactType": "Billing",
|
|
157
|
+
"country": "USA",
|
|
158
|
+
"firstName": "John",
|
|
159
|
+
"lastName": "Smith",
|
|
160
|
+
"preferredLanguage": "English",
|
|
161
|
+
"sessionTimeOut": 30,
|
|
162
|
+
"timeZone": "GMT",
|
|
163
|
+
"phone": "3456788765"
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
result = session.put(urljoin(baseurl, path), json=payload)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
As the `data` parameter for the `session` methods, EdgeGrid for Python
|
|
170
|
+
currently supports the `bytes` and `requests_toolbelt.MultipartEncoder`
|
|
171
|
+
types or a file-like object.
|
|
172
|
+
|
|
173
|
+
### Debug
|
|
174
|
+
|
|
175
|
+
Enable debugging to get additional information about a request.
|
|
176
|
+
|
|
177
|
+
To log requests, use the built-in request logging. Add this before making a request:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
import logging
|
|
181
|
+
from http.client import HTTPConnection
|
|
182
|
+
HTTPConnection.debuglevel = 1
|
|
183
|
+
logging.basicConfig()
|
|
184
|
+
logging.getLogger().setLevel(logging.DEBUG)
|
|
185
|
+
urllib_log = logging.getLogger("urllib3")
|
|
186
|
+
urllib_log.setLevel(logging.DEBUG)
|
|
187
|
+
urllib_log.propagate = True
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
This 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.
|
|
191
|
+
|
|
192
|
+
To log specific parts like URL, status code, headers, or body, add this:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
import requests
|
|
196
|
+
import logging
|
|
197
|
+
import json
|
|
198
|
+
from akamai.edgegrid import EdgeGridAuth, EdgeRc
|
|
199
|
+
from urllib.parse import urljoin
|
|
200
|
+
|
|
201
|
+
logger = logging.getLogger('requests_logger')
|
|
202
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
203
|
+
|
|
204
|
+
edgerc = EdgeRc('~/.edgerc')
|
|
205
|
+
section = 'default'
|
|
206
|
+
baseurl = 'https://%s' % edgerc.get(section, 'host')
|
|
207
|
+
|
|
208
|
+
session = requests.Session()
|
|
209
|
+
session.auth = EdgeGridAuth.from_edgerc(edgerc, section)
|
|
210
|
+
|
|
211
|
+
path = '/identity-management/v3/user-profile'
|
|
212
|
+
|
|
213
|
+
result = session.get(urljoin(baseurl, path))
|
|
214
|
+
logger.debug(f'URL: {result.url}')
|
|
215
|
+
logger.debug(f'Status Code: {result.status_code}')
|
|
216
|
+
logger.debug(f'Headers: {result.headers}')
|
|
217
|
+
logger.debug(f'Body: {result.json()}')
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Virtual environment
|
|
221
|
+
|
|
222
|
+
A [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.
|
|
223
|
+
|
|
224
|
+
Set up a virtual environment:
|
|
225
|
+
|
|
226
|
+
1. Initialize your environment in a new directory.
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
// Unix/macOS
|
|
230
|
+
python3 -m venv ~/Desktop/myenv
|
|
231
|
+
|
|
232
|
+
// Windows
|
|
233
|
+
py -m venv ~/Desktop/myenv
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
This creates a `venv` in the specified directory as well as copies pip into it.
|
|
237
|
+
|
|
238
|
+
2. Activate your environment.
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
// Unix/macOS
|
|
242
|
+
source ~/Desktop/myenv/bin/activate
|
|
243
|
+
|
|
244
|
+
// Windows
|
|
245
|
+
~/Desktop/myenv/Scripts/activate
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Your prompt will change to show you're working in a virtual environment, for example:
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
(myenv) jsmith@abc-de12fg $
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
3. To recreate the environment, install the required dependencies within your project.
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
pip install -r dev-requirements.txt
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
4. Run the tests.
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
// Unix/macOS
|
|
264
|
+
pytest -v
|
|
265
|
+
|
|
266
|
+
// Windows
|
|
267
|
+
py -m pytest -v
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
5. To deactivate your environment, run the `deactivate` command.
|
|
271
|
+
|
|
272
|
+
## Reporting issues
|
|
273
|
+
|
|
274
|
+
To report an issue or make a suggestion, create a new [GitHub issue](https://github.com/akamai/AkamaiOPEN-edgegrid-python/issues).
|
|
275
|
+
|
|
276
|
+
## License
|
|
277
|
+
|
|
278
|
+
Copyright 2024 Akamai Technologies, Inc. All rights reserved.
|
|
279
|
+
|
|
280
|
+
Licensed 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.
|
|
281
|
+
|
|
282
|
+
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.
|
|
@@ -32,25 +32,10 @@ usage:
|
|
|
32
32
|
|
|
33
33
|
from .edgegrid import EdgeGridAuth
|
|
34
34
|
from .edgerc import EdgeRc
|
|
35
|
+
|
|
35
36
|
__all__ = ['EdgeGridAuth', 'EdgeRc']
|
|
36
37
|
|
|
37
38
|
__title__ = 'edgegrid-python'
|
|
38
|
-
__version__ = '
|
|
39
|
-
__author__ = 'Jonathan Landis <jlandis@akamai.com>'
|
|
40
|
-
__maintainer__ = 'Akamai Developer Experience team <dl-devexp-eng@akamai.com>'
|
|
39
|
+
__version__ = '2.0.0'
|
|
41
40
|
__license__ = 'Apache 2.0'
|
|
42
|
-
__copyright__ = 'Copyright
|
|
43
|
-
|
|
44
|
-
# Copyright 2021 Akamai Technologies, Inc. All Rights Reserved
|
|
45
|
-
#
|
|
46
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
47
|
-
# you may not use this file except in compliance with the License.
|
|
48
|
-
# You may obtain a copy of the License at
|
|
49
|
-
#
|
|
50
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
51
|
-
#
|
|
52
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
53
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
54
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
55
|
-
# See the License for the specific language governing permissions and
|
|
56
|
-
# limitations under the License.
|
|
41
|
+
__copyright__ = 'Copyright 2024 Akamai Technologies'
|