pyalex 0.13__py3-none-any.whl → 0.14__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/__init__.py +18 -0
- pyalex/_version.py +2 -2
- pyalex/api.py +76 -5
- {pyalex-0.13.dist-info → pyalex-0.14.dist-info}/METADATA +47 -10
- pyalex-0.14.dist-info/RECORD +8 -0
- {pyalex-0.13.dist-info → pyalex-0.14.dist-info}/WHEEL +1 -1
- pyalex-0.13.dist-info/RECORD +0 -8
- {pyalex-0.13.dist-info → pyalex-0.14.dist-info}/LICENSE +0 -0
- {pyalex-0.13.dist-info → pyalex-0.14.dist-info}/top_level.txt +0 -0
pyalex/__init__.py
CHANGED
|
@@ -9,6 +9,10 @@ from pyalex.api import Author
|
|
|
9
9
|
from pyalex.api import Authors
|
|
10
10
|
from pyalex.api import Concept
|
|
11
11
|
from pyalex.api import Concepts
|
|
12
|
+
from pyalex.api import Domain
|
|
13
|
+
from pyalex.api import Domains
|
|
14
|
+
from pyalex.api import Field
|
|
15
|
+
from pyalex.api import Fields
|
|
12
16
|
from pyalex.api import Funder
|
|
13
17
|
from pyalex.api import Funders
|
|
14
18
|
from pyalex.api import Institution
|
|
@@ -19,10 +23,15 @@ from pyalex.api import Publisher
|
|
|
19
23
|
from pyalex.api import Publishers
|
|
20
24
|
from pyalex.api import Source
|
|
21
25
|
from pyalex.api import Sources
|
|
26
|
+
from pyalex.api import Subfield
|
|
27
|
+
from pyalex.api import Subfields
|
|
28
|
+
from pyalex.api import Topic
|
|
29
|
+
from pyalex.api import Topics
|
|
22
30
|
from pyalex.api import Venue
|
|
23
31
|
from pyalex.api import Venues
|
|
24
32
|
from pyalex.api import Work
|
|
25
33
|
from pyalex.api import Works
|
|
34
|
+
from pyalex.api import autocomplete
|
|
26
35
|
from pyalex.api import config
|
|
27
36
|
from pyalex.api import invert_abstract
|
|
28
37
|
|
|
@@ -43,8 +52,17 @@ __all__ = [
|
|
|
43
52
|
"Institution",
|
|
44
53
|
"Concepts",
|
|
45
54
|
"Concept",
|
|
55
|
+
"Domains",
|
|
56
|
+
"Domain",
|
|
57
|
+
"Fields",
|
|
58
|
+
"Field",
|
|
59
|
+
"Subfields",
|
|
60
|
+
"Subfield",
|
|
61
|
+
"Topics",
|
|
62
|
+
"Topic",
|
|
46
63
|
"People",
|
|
47
64
|
"Journals",
|
|
65
|
+
"autocomplete",
|
|
48
66
|
"config",
|
|
49
67
|
"invert_abstract",
|
|
50
68
|
]
|
pyalex/_version.py
CHANGED
pyalex/api.py
CHANGED
|
@@ -198,7 +198,11 @@ class BaseOpenAlex:
|
|
|
198
198
|
return self.filter(openalex_id="|".join(record_list)).get()
|
|
199
199
|
|
|
200
200
|
def _full_collection_name(self):
|
|
201
|
-
|
|
201
|
+
if self.params is not None and "q" in self.params.keys():
|
|
202
|
+
base_url = config.openalex_url + "/autocomplete/"
|
|
203
|
+
return base_url + self.__class__.__name__.lower()
|
|
204
|
+
else:
|
|
205
|
+
return config.openalex_url + "/" + self.__class__.__name__.lower()
|
|
202
206
|
|
|
203
207
|
def __getattr__(self, key):
|
|
204
208
|
if key == "groupby":
|
|
@@ -286,7 +290,6 @@ class BaseOpenAlex:
|
|
|
286
290
|
self._add_params("per-page", per_page)
|
|
287
291
|
self._add_params("page", page)
|
|
288
292
|
self._add_params("cursor", cursor)
|
|
289
|
-
|
|
290
293
|
return self._get_from_url(self.url, return_meta=return_meta)
|
|
291
294
|
|
|
292
295
|
def paginate(self, method="cursor", page=1, per_page=None, cursor="*", n_max=10000):
|
|
@@ -343,6 +346,11 @@ class BaseOpenAlex:
|
|
|
343
346
|
self._add_params("select", s)
|
|
344
347
|
return self
|
|
345
348
|
|
|
349
|
+
def autocomplete(self, s, **kwargs):
|
|
350
|
+
"""autocomplete the string s, for a specific type of entity"""
|
|
351
|
+
self._add_params("q", s)
|
|
352
|
+
return self.get(**kwargs)
|
|
353
|
+
|
|
346
354
|
|
|
347
355
|
# The API
|
|
348
356
|
|
|
@@ -397,12 +405,36 @@ class Institutions(BaseOpenAlex):
|
|
|
397
405
|
resource_class = Institution
|
|
398
406
|
|
|
399
407
|
|
|
400
|
-
class
|
|
408
|
+
class Domain(OpenAlexEntity):
|
|
401
409
|
pass
|
|
402
410
|
|
|
403
411
|
|
|
404
|
-
class
|
|
405
|
-
resource_class =
|
|
412
|
+
class Domains(BaseOpenAlex):
|
|
413
|
+
resource_class = Domain
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
class Field(OpenAlexEntity):
|
|
417
|
+
pass
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
class Fields(BaseOpenAlex):
|
|
421
|
+
resource_class = Field
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
class Subfield(OpenAlexEntity):
|
|
425
|
+
pass
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
class Subfields(BaseOpenAlex):
|
|
429
|
+
resource_class = Subfield
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
class Topic(OpenAlexEntity):
|
|
433
|
+
pass
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
class Topics(BaseOpenAlex):
|
|
437
|
+
resource_class = Topic
|
|
406
438
|
|
|
407
439
|
|
|
408
440
|
class Publisher(OpenAlexEntity):
|
|
@@ -421,6 +453,21 @@ class Funders(BaseOpenAlex):
|
|
|
421
453
|
resource_class = Funder
|
|
422
454
|
|
|
423
455
|
|
|
456
|
+
class Autocomplete(OpenAlexEntity):
|
|
457
|
+
pass
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
class autocompletes(BaseOpenAlex):
|
|
461
|
+
"""Class to autocomplete without being based on the type of entity"""
|
|
462
|
+
|
|
463
|
+
resource_class = Autocomplete
|
|
464
|
+
|
|
465
|
+
def __getitem__(self, key):
|
|
466
|
+
return self._get_from_url(
|
|
467
|
+
config.openalex_url + "/autocomplete" + "?q=" + key, return_meta=False
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
|
|
424
471
|
def Venue(*args, **kwargs): # deprecated
|
|
425
472
|
# warn about deprecation
|
|
426
473
|
warnings.warn(
|
|
@@ -443,6 +490,30 @@ def Venues(*args, **kwargs): # deprecated
|
|
|
443
490
|
return Sources(*args, **kwargs)
|
|
444
491
|
|
|
445
492
|
|
|
493
|
+
class Concept(OpenAlexEntity):
|
|
494
|
+
# warn about deprecation
|
|
495
|
+
warnings.warn(
|
|
496
|
+
"Concept is deprecated by OpenAlex and replaced by topics.",
|
|
497
|
+
DeprecationWarning,
|
|
498
|
+
stacklevel=2,
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
class Concepts(BaseOpenAlex):
|
|
503
|
+
# warn about deprecation
|
|
504
|
+
warnings.warn(
|
|
505
|
+
"Concepts is deprecated by OpenAlex and replaced by topics.",
|
|
506
|
+
DeprecationWarning,
|
|
507
|
+
stacklevel=2,
|
|
508
|
+
)
|
|
509
|
+
resource_class = Concept
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def autocomplete(s):
|
|
513
|
+
"""autocomplete with any type of entity"""
|
|
514
|
+
return autocompletes()[s]
|
|
515
|
+
|
|
516
|
+
|
|
446
517
|
# aliases
|
|
447
518
|
People = Authors
|
|
448
519
|
Journals = Sources
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyalex
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14
|
|
4
4
|
Summary: Python interface to the OpenAlex database
|
|
5
5
|
Author-email: Jonathan de Bruin <jonathandebruinos@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -30,8 +30,6 @@ Requires-Dist: pytest-xdist ; 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
34
|
PyAlex is a Python library for [OpenAlex](https://openalex.org/). OpenAlex is
|
|
37
35
|
an index of hundreds of millions of interconnected scholarly papers, authors,
|
|
@@ -49,7 +47,7 @@ The following features of OpenAlex are currently supported by PyAlex:
|
|
|
49
47
|
- [x] Select fields
|
|
50
48
|
- [x] Sample
|
|
51
49
|
- [x] Pagination
|
|
52
|
-
- [
|
|
50
|
+
- [x] Autocomplete endpoint
|
|
53
51
|
- [x] N-grams
|
|
54
52
|
- [x] Authentication
|
|
55
53
|
|
|
@@ -71,10 +69,10 @@ pip install pyalex
|
|
|
71
69
|
|
|
72
70
|
## Getting started
|
|
73
71
|
|
|
74
|
-
PyAlex offers support for all [Entity Objects](https://docs.openalex.org/api-entities/entities-overview): [Works](https://docs.openalex.org/api-entities/works), [Authors](https://docs.openalex.org/api-entities/authors), [Sources](https://docs.openalex.org/api-entities/sourcese), [Institutions](https://docs.openalex.org/api-entities/institutions), [
|
|
72
|
+
PyAlex offers support for all [Entity Objects](https://docs.openalex.org/api-entities/entities-overview): [Works](https://docs.openalex.org/api-entities/works), [Authors](https://docs.openalex.org/api-entities/authors), [Sources](https://docs.openalex.org/api-entities/sourcese), [Institutions](https://docs.openalex.org/api-entities/institutions), [Topics](https://docs.openalex.org/api-entities/topics), [Publishers](https://docs.openalex.org/api-entities/publishers), and [Funders](https://docs.openalex.org/api-entities/funders).
|
|
75
73
|
|
|
76
74
|
```python
|
|
77
|
-
from pyalex import Works, Authors, Sources, Institutions,
|
|
75
|
+
from pyalex import Works, Authors, Sources, Institutions, Topics, Publishers, Funders
|
|
78
76
|
```
|
|
79
77
|
|
|
80
78
|
### The polite pool
|
|
@@ -89,9 +87,21 @@ import pyalex
|
|
|
89
87
|
pyalex.config.email = "mail@example.com"
|
|
90
88
|
```
|
|
91
89
|
|
|
90
|
+
### Max retries
|
|
91
|
+
|
|
92
|
+
By default, PyAlex will raise an error at the first failure when querying the OpenAlex API. You can set `max_retries` to a number higher than 0 to allow PyAlex to retry when an error occurs. `retry_backoff_factor` is related to the delay between two retry, and `retry_http_codes` are the HTTP error codes that should trigger a retry.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from pyalex import config
|
|
96
|
+
|
|
97
|
+
config.max_retries = 0
|
|
98
|
+
config.retry_backoff_factor = 0.1
|
|
99
|
+
config.retry_http_codes = [429, 500, 503]
|
|
100
|
+
```
|
|
101
|
+
|
|
92
102
|
### Get single entity
|
|
93
103
|
|
|
94
|
-
Get a single Work, Author, Source, Institution, Concept, Publisher or Funder from OpenAlex by the
|
|
104
|
+
Get a single Work, Author, Source, Institution, Concept, Topic, Publisher or Funder from OpenAlex by the
|
|
95
105
|
OpenAlex ID, or by DOI or ROR.
|
|
96
106
|
|
|
97
107
|
```python
|
|
@@ -113,7 +123,7 @@ Works()["W2741809807"]["open_access"]
|
|
|
113
123
|
{'is_oa': True, 'oa_status': 'gold', 'oa_url': 'https://doi.org/10.7717/peerj.4375'}
|
|
114
124
|
```
|
|
115
125
|
|
|
116
|
-
The previous works also for Authors, Venues, Institutions and
|
|
126
|
+
The previous works also for Authors, Venues, Institutions, Concepts and Topics
|
|
117
127
|
|
|
118
128
|
```python
|
|
119
129
|
Authors()["A2887243803"]
|
|
@@ -122,7 +132,7 @@ Authors()["https://orcid.org/0000-0002-4297-0502"] # same
|
|
|
122
132
|
|
|
123
133
|
#### Get random
|
|
124
134
|
|
|
125
|
-
Get a [random Work, Author, Source, Institution, Concept, Publisher or Funder](https://docs.openalex.org/how-to-use-the-api/get-single-entities/random-result).
|
|
135
|
+
Get a [random Work, Author, Source, Institution, Concept, Topic, Publisher or Funder](https://docs.openalex.org/how-to-use-the-api/get-single-entities/random-result).
|
|
126
136
|
|
|
127
137
|
```python
|
|
128
138
|
Works().random()
|
|
@@ -130,6 +140,7 @@ Authors().random()
|
|
|
130
140
|
Sources().random()
|
|
131
141
|
Institutions().random()
|
|
132
142
|
Concepts().random()
|
|
143
|
+
Topics().random()
|
|
133
144
|
Publishers().random()
|
|
134
145
|
Funders().random()
|
|
135
146
|
```
|
|
@@ -172,7 +183,7 @@ Works().count()
|
|
|
172
183
|
For lists of entities, you can return the result as well as the metadata. By default, only the results are returned.
|
|
173
184
|
|
|
174
185
|
```python
|
|
175
|
-
results, meta =
|
|
186
|
+
results, meta = Topics().get(return_meta=True)
|
|
176
187
|
```
|
|
177
188
|
|
|
178
189
|
```python
|
|
@@ -331,6 +342,32 @@ for page in pager:
|
|
|
331
342
|
```
|
|
332
343
|
|
|
333
344
|
|
|
345
|
+
### Autocomplete
|
|
346
|
+
|
|
347
|
+
OpenAlex reference: [Autocomplete entities](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/autocomplete-entities).
|
|
348
|
+
|
|
349
|
+
Autocomplete a string:
|
|
350
|
+
```python
|
|
351
|
+
from pyalex import autocomplete
|
|
352
|
+
|
|
353
|
+
autocomplete("stockholm resilience centre")
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
Autocomplete a string to get a specific type of entities:
|
|
357
|
+
```python
|
|
358
|
+
from pyalex import Institutions
|
|
359
|
+
|
|
360
|
+
Institutions().autocomplete("stockholm resilience centre")
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
You can also use the filters to autocomplete:
|
|
364
|
+
```python
|
|
365
|
+
from pyalex import Works
|
|
366
|
+
|
|
367
|
+
r = Works().filter(publication_year=2023).autocomplete("planetary boundaries")
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
|
|
334
371
|
### Get N-grams
|
|
335
372
|
|
|
336
373
|
OpenAlex reference: [Get N-grams](https://docs.openalex.org/api-entities/works/get-n-grams).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pyalex/__init__.py,sha256=EL6oh0vQdSNyvsrxFFgmDn-P_Dgev1IYpP-WiLBxjS8,1553
|
|
2
|
+
pyalex/_version.py,sha256=lmFPHiet63Bn9h104yd9q0T6i7C2c0WCbizqrpAtSuk,408
|
|
3
|
+
pyalex/api.py,sha256=whUv8TbnW968wlR8U4O-lWsaFHRgW0Ham0cznbR3Zlc,13212
|
|
4
|
+
pyalex-0.14.dist-info/LICENSE,sha256=Mhf5MImRYP06a1EPVJCpkpTstOOEfGajN3T_Fz4izMg,1074
|
|
5
|
+
pyalex-0.14.dist-info/METADATA,sha256=3bjn78df3VlosFCcseDGs5tfTUIAgCStI_uGjqHT69w,13777
|
|
6
|
+
pyalex-0.14.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
7
|
+
pyalex-0.14.dist-info/top_level.txt,sha256=D0An8hWy9e0xPhTaT6K-yuJKVeVV3bYGxZ6Y-v2WXSU,7
|
|
8
|
+
pyalex-0.14.dist-info/RECORD,,
|
pyalex-0.13.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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,,
|
|
File without changes
|
|
File without changes
|