Skip to content

Commit 3c71b9a

Browse files
authored
Refactor pagination and add support for offset pagination (#31)
1 parent d769962 commit 3c71b9a

File tree

4 files changed

+251
-220
lines changed

4 files changed

+251
-220
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,14 @@ Works().filter(institutions={"country_code": "fr|gb"}).get()
260260

261261
#### Paging
262262

263-
OpenAlex offers two methods for paging: [basic paging](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/paging#basic-paging) and [cursor paging](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/paging#cursor-paging). Both methods are supported by
264-
PyAlex, although cursor paging seems to be easier to implement and less error-prone.
263+
OpenAlex offers two methods for paging: [basic (offset) paging](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/paging#basic-paging) and [cursor paging](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/paging#cursor-paging). Both methods are supported by PyAlex.
265264

266-
##### Basic paging
267-
268-
See limitations of [basic paging](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/paging#basic-paging) in the OpenAlex documentation.
269-
It's relatively easy to implement basic paging with PyAlex, however it is
270-
advised to use the built-in pager based on cursor paging.
271-
272-
##### Cursor paging
265+
##### Cursor paging (default)
273266

274-
Use `paginate()` for paging results. Each page is a list of records, with a
275-
maximum of `per_page` (default 25). By default, `paginate`s argument `n_max`
276-
is set to 10000. Use `None` to retrieve all results.
267+
Use the method `paginate()` to paginate results. Each returned page is a list
268+
of records, with a maximum of `per_page` (default 25). By default,
269+
`paginate`s argument `n_max` is set to 10000. Use `None` to retrieve all
270+
results.
277271

278272
```python
279273
from pyalex import Authors
@@ -296,6 +290,19 @@ for record in chain(*query.paginate(per_page=200)):
296290
print(record["id"])
297291
```
298292

293+
##### Basic paging
294+
295+
See limitations of [basic paging](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/paging#basic-paging) in the OpenAlex documentation.
296+
297+
```python
298+
from pyalex import Authors
299+
300+
pager = Authors().search_filter(display_name="einstein").paginate(method="page", per_page=200)
301+
302+
for page in pager:
303+
print(len(page))
304+
```
305+
299306

300307
### Get N-grams
301308

0 commit comments

Comments
 (0)