Chain calls of paginated APIs
Project description
API endpoints are often paginated, meaning that you must chain requests to get the content in full. Unpaginate provides a decorator to make that task easy:
>>> from unpaginate import unpaginate
>>> @unpaginate
... def get_cities(pagination, country):
... return requests.post(
... "https://api.example.org/cities",
... json={"country": country, "page": pagination.page},
... ).json()["items"]
Calling the decorated function allows to iterate over all items of all pages:
>>> iterator = get_cities("France") # the 'pagination' parameter is added by the decorator
>>> iterator
<generator object get_cities ...>
>>> next(iterator)
'Paris'
>>> next(iterator)
'Lyon'
>>> next(iterator)
'Marseille'
All pagination schemes are supported:
- By page index
- By offset
- Using a cursor
- Other schemes through avdanced mode
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
unpaginate-0.1.0.tar.gz
(20.1 kB
view details)
Built Distribution
File details
Details for the file unpaginate-0.1.0.tar.gz
.
File metadata
- Download URL: unpaginate-0.1.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40db65bfed0be43a3f5bddd259d58b484359db84a34322a1b946953bd5f158c |
|
MD5 | 31fc688ab1215350488870c18cfcfdde |
|
BLAKE2b-256 | 30b1e907f33a94c1f2d8ae62f2bc1d515b09432379748665dfea735fae2714eb |
File details
Details for the file unpaginate-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: unpaginate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbcaf68df41ea78a5bb569989c74464e499af234e4ba8462b7f9bec8afcec6d9 |
|
MD5 | 868605663a006ee26be8da8eca256a6a |
|
BLAKE2b-256 | 547d181e00f6abfe1361db15074fe39bbd69fe336760cf69e5defa513ccccd8c |