Skip to content

Commit 058472e

Browse files
authored
Add models.ListPage (#4)
1 parent 0e407f6 commit 058472e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/apify_shared/models.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import Dict, Generic, List, TypeVar
2+
3+
from .utils import ignore_docs
4+
5+
T = TypeVar('T')
6+
7+
8+
class ListPage(Generic[T]):
9+
"""A single page of items returned from a list() method."""
10+
11+
#: list: List of returned objects on this page
12+
items: List[T]
13+
#: int: Count of the returned objects on this page
14+
count: int
15+
#: int: The limit on the number of returned objects offset specified in the API call
16+
offset: int
17+
#: int: The offset of the first object specified in the API call
18+
limit: int
19+
#: int: Total number of objects matching the API call criteria
20+
total: int
21+
#: bool: Whether the listing is descending or not
22+
desc: bool
23+
24+
@ignore_docs
25+
def __init__(self, data: Dict) -> None:
26+
"""Initialize a ListPage instance from the API response data."""
27+
self.items = data['items'] if 'items' in data else []
28+
self.offset = data['offset'] if 'offset' in data else 0
29+
self.limit = data['limit'] if 'limit' in data else 0
30+
self.count = data['count'] if 'count' in data else len(self.items)
31+
self.total = data['total'] if 'total' in data else self.offset + self.count
32+
self.desc = data['desc'] if 'desc' in data else False

0 commit comments

Comments
 (0)