pyalex 0.12__py3-none-any.whl → 0.13__py3-none-any.whl
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.
- pyalex/_version.py +2 -2
- pyalex/api.py +31 -11
- {pyalex-0.12.dist-info → pyalex-0.13.dist-info}/METADATA +10 -5
- pyalex-0.13.dist-info/RECORD +8 -0
- {pyalex-0.12.dist-info → pyalex-0.13.dist-info}/WHEEL +1 -1
- pyalex-0.12.dist-info/RECORD +0 -8
- {pyalex-0.12.dist-info → pyalex-0.13.dist-info}/LICENSE +0 -0
- {pyalex-0.12.dist-info → pyalex-0.13.dist-info}/top_level.txt +0 -0
pyalex/_version.py
CHANGED
pyalex/api.py
CHANGED
|
@@ -3,6 +3,7 @@ import warnings
|
|
|
3
3
|
from urllib.parse import quote_plus
|
|
4
4
|
|
|
5
5
|
import requests
|
|
6
|
+
from requests.auth import AuthBase
|
|
6
7
|
from urllib3.util import Retry
|
|
7
8
|
|
|
8
9
|
try:
|
|
@@ -22,6 +23,7 @@ class AlexConfig(dict):
|
|
|
22
23
|
config = AlexConfig(
|
|
23
24
|
email=None,
|
|
24
25
|
api_key=None,
|
|
26
|
+
user_agent="pyalex/" + __version__,
|
|
25
27
|
openalex_url="https://api.openalex.org",
|
|
26
28
|
max_retries=0,
|
|
27
29
|
retry_backoff_factor=0.1,
|
|
@@ -160,6 +162,32 @@ class Paginator:
|
|
|
160
162
|
return results
|
|
161
163
|
|
|
162
164
|
|
|
165
|
+
class OpenAlexAuth(AuthBase):
|
|
166
|
+
"""OpenAlex auth class based on requests auth
|
|
167
|
+
|
|
168
|
+
Includes the email, api_key and user-agent headers.
|
|
169
|
+
|
|
170
|
+
arguments:
|
|
171
|
+
config: an AlexConfig object
|
|
172
|
+
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
def __init__(self, config):
|
|
176
|
+
self.config = config
|
|
177
|
+
|
|
178
|
+
def __call__(self, r):
|
|
179
|
+
if self.config.api_key:
|
|
180
|
+
r.headers["Authorization"] = f"Bearer {self.config.api_key}"
|
|
181
|
+
|
|
182
|
+
if self.config.email:
|
|
183
|
+
r.headers["From"] = self.config.email
|
|
184
|
+
|
|
185
|
+
if self.config.user_agent:
|
|
186
|
+
r.headers["User-Agent"] = self.config.user_agent
|
|
187
|
+
|
|
188
|
+
return r
|
|
189
|
+
|
|
190
|
+
|
|
163
191
|
class BaseOpenAlex:
|
|
164
192
|
"""Base class for OpenAlex objects."""
|
|
165
193
|
|
|
@@ -222,13 +250,7 @@ class BaseOpenAlex:
|
|
|
222
250
|
return m["count"]
|
|
223
251
|
|
|
224
252
|
def _get_from_url(self, url, return_meta=False):
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
res = _get_requests_session().get(
|
|
228
|
-
url,
|
|
229
|
-
headers={"User-Agent": "pyalex/" + __version__, "email": config.email},
|
|
230
|
-
params=params,
|
|
231
|
-
)
|
|
253
|
+
res = _get_requests_session().get(url, auth=OpenAlexAuth(config))
|
|
232
254
|
|
|
233
255
|
# handle query errors
|
|
234
256
|
if res.status_code == 403:
|
|
@@ -334,11 +356,9 @@ class Work(OpenAlexEntity):
|
|
|
334
356
|
|
|
335
357
|
def ngrams(self, return_meta=False):
|
|
336
358
|
openalex_id = self["id"].split("/")[-1]
|
|
359
|
+
n_gram_url = f"{config.openalex_url}/works/{openalex_id}/ngrams"
|
|
337
360
|
|
|
338
|
-
res = _get_requests_session().get(
|
|
339
|
-
f"{config.openalex_url}/works/{openalex_id}/ngrams",
|
|
340
|
-
headers={"User-Agent": "pyalex/" + __version__, "email": config.email},
|
|
341
|
-
)
|
|
361
|
+
res = _get_requests_session().get(n_gram_url, auth=OpenAlexAuth(config))
|
|
342
362
|
res.raise_for_status()
|
|
343
363
|
results = res.json()
|
|
344
364
|
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyalex
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.13
|
|
4
4
|
Summary: Python interface to the OpenAlex database
|
|
5
5
|
Author-email: Jonathan de Bruin <jonathandebruinos@gmail.com>
|
|
6
6
|
License: MIT
|
|
7
7
|
Classifier: Development Status :: 5 - Production/Stable
|
|
8
8
|
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
11
9
|
Classifier: Programming Language :: Python :: 3.8
|
|
12
10
|
Classifier: Programming Language :: Python :: 3.9
|
|
13
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Python: >=3.8
|
|
16
15
|
Description-Content-Type: text/markdown
|
|
17
16
|
License-File: LICENSE
|
|
18
17
|
Requires-Dist: requests
|
|
@@ -21,6 +20,7 @@ Provides-Extra: lint
|
|
|
21
20
|
Requires-Dist: ruff ; extra == 'lint'
|
|
22
21
|
Provides-Extra: test
|
|
23
22
|
Requires-Dist: pytest ; extra == 'test'
|
|
23
|
+
Requires-Dist: pytest-xdist ; extra == 'test'
|
|
24
24
|
|
|
25
25
|
<p align="center">
|
|
26
26
|
<img alt="PyAlex - a Python wrapper for OpenAlex" src="https://github.com/J535D165/pyalex/raw/main/pyalex_repocard.svg">
|
|
@@ -30,6 +30,9 @@ Requires-Dist: pytest ; extra == 'test'
|
|
|
30
30
|
|
|
31
31
|
 [](https://zenodo.org/badge/latestdoi/557541347)
|
|
32
32
|
|
|
33
|
+
[](https://securityscorecards.dev/viewer/?uri=github.com/J535D165/pyalex)
|
|
34
|
+
|
|
35
|
+
|
|
33
36
|
PyAlex is a Python library for [OpenAlex](https://openalex.org/). OpenAlex is
|
|
34
37
|
an index of hundreds of millions of interconnected scholarly papers, authors,
|
|
35
38
|
institutions, and more. OpenAlex offers a robust, open, and free [REST API](https://docs.openalex.org/) to extract, aggregate, or search scholarly data.
|
|
@@ -60,7 +63,7 @@ We aim to cover the entire API, and we are looking for help. We are welcoming Pu
|
|
|
60
63
|
|
|
61
64
|
## Installation
|
|
62
65
|
|
|
63
|
-
PyAlex requires Python 3.
|
|
66
|
+
PyAlex requires Python 3.8 or later.
|
|
64
67
|
|
|
65
68
|
```sh
|
|
66
69
|
pip install pyalex
|
|
@@ -412,6 +415,8 @@ R users can use the excellent [OpenAlexR](https://github.com/ropensci/openalexR)
|
|
|
412
415
|
|
|
413
416
|
## Contact
|
|
414
417
|
|
|
418
|
+
> This library is a community contribution. The authors of this Python library aren't affiliated with OpenAlex.
|
|
419
|
+
|
|
415
420
|
Feel free to reach out with questions, remarks, and suggestions. The
|
|
416
421
|
[issue tracker](/issues) is a good starting point. You can also email me at
|
|
417
422
|
[jonathandebruinos@gmail.com](mailto:jonathandebruinos@gmail.com).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pyalex/__init__.py,sha256=UrEW9s9NbULtmmnYUUgfbrDujleV8XQLiMRYGdRnm9M,1137
|
|
2
|
+
pyalex/_version.py,sha256=4Ti_UJ2UR2LyAc9zW9aeUVpFeq-DXxy65V2wynOuCi0,408
|
|
3
|
+
pyalex/api.py,sha256=vefNV54OG1daTrKHSDq9Jcy4JhiYi0HSP3GsEzA47uk,11633
|
|
4
|
+
pyalex-0.13.dist-info/LICENSE,sha256=Mhf5MImRYP06a1EPVJCpkpTstOOEfGajN3T_Fz4izMg,1074
|
|
5
|
+
pyalex-0.13.dist-info/METADATA,sha256=vMMbnCUgNUaw99XlqucQZMfZsOZWrXXJOmRpPJsTdSU,12916
|
|
6
|
+
pyalex-0.13.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
|
|
7
|
+
pyalex-0.13.dist-info/top_level.txt,sha256=D0An8hWy9e0xPhTaT6K-yuJKVeVV3bYGxZ6Y-v2WXSU,7
|
|
8
|
+
pyalex-0.13.dist-info/RECORD,,
|
pyalex-0.12.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
pyalex/__init__.py,sha256=UrEW9s9NbULtmmnYUUgfbrDujleV8XQLiMRYGdRnm9M,1137
|
|
2
|
-
pyalex/_version.py,sha256=eOKjFr4-OgtTmAgooUIWvbplNekszFVZVHe7TLPOdeU,408
|
|
3
|
-
pyalex/api.py,sha256=lmbJaU3GCwi2ZNeshQV0dFXK-j83A08q1yjuVdeEKeM,11193
|
|
4
|
-
pyalex-0.12.dist-info/LICENSE,sha256=Mhf5MImRYP06a1EPVJCpkpTstOOEfGajN3T_Fz4izMg,1074
|
|
5
|
-
pyalex-0.12.dist-info/METADATA,sha256=JVSzitj9HrRO7us_49vrDWCYIVLe7QtvRNIGGk0tQQU,12632
|
|
6
|
-
pyalex-0.12.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
7
|
-
pyalex-0.12.dist-info/top_level.txt,sha256=D0An8hWy9e0xPhTaT6K-yuJKVeVV3bYGxZ6Y-v2WXSU,7
|
|
8
|
-
pyalex-0.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|