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 hashes)
Built Distribution
Close
Hashes for unpaginate-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbcaf68df41ea78a5bb569989c74464e499af234e4ba8462b7f9bec8afcec6d9 |
|
MD5 | 868605663a006ee26be8da8eca256a6a |
|
BLAKE2b-256 | 547d181e00f6abfe1361db15074fe39bbd69fe336760cf69e5defa513ccccd8c |