Paginator
Paginator
¶
Paginator is used to flip through different pages of data that the API returns when searching.
Instead of the user manipulating the URL and parameters, this object handles all of that for them.
Using the Paginator object, the user can simply and easily flip through the results of the search. The details, that results are listed as pages are hidden from the user. The pages are automatically requested from the API as needed.
This object implements a python iterator, so for node in Paginator
works as expected.
It will loop through all results of the search, returning the nodes one by one.
Do not create paginator objects
Please note that you are not required or advised to create a paginator object, and instead the Python SDK API object will create a paginator for you, return it, and let you simply use it
Source code in src/cript/api/paginator.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
page_number: Union[int, None]
property
¶
Obtain the current page number the paginator is fetching next.
Returns:
Type | Description |
---|---|
int
|
positive number of the next page this paginator is fetching. |
None
|
if no page number is associated with the pagination |
__init__(api, url_path, page_number, query)
¶
create a paginator
- set all the variables coming into constructor
- then prepare any variable as needed e.g. strip extra spaces or url encode query
Parameters:
Name | Type | Description | Default |
---|---|---|---|
http_headers |
get already created http headers from API and just use them in paginator |
required | |
api_endpoint |
api endpoint to send the search requests to it already contains what node the user is looking for |
required | |
current_page_number |
page number to start from. Keep track of current page for user to flip back and forth between pages of data |
required | |
query |
str
|
the value the user is searching for |
required |
Returns:
Type | Description |
---|---|
None
|
instantiate a paginator |
Source code in src/cript/api/paginator.py
limit_page_fetches(max_num_pages)
¶
Limit pagination to a maximum number of pages.
This can be used for very large searches with the paginator, so the search can be split into smaller portions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_num_pages |
Union[int, None]
|
positive integer with maximum number of page fetches. or None, indicating unlimited number of page fetches are permitted. |
required |
Source code in src/cript/api/paginator.py
skip_pages(skip_pages)
¶
Skip pages in the pagination.
Warning this function is advanced usage and may not produce the results you expect.
In particular, every search is different, even if we search for the same values there is
no guarantee that the results are in the same order. (And results can change if data is
added or removed from CRIPT.) So if you break up your search with limit_page_fetches
and
skip_pages
there is no guarantee that it is the same as one continuous search.
If the paginator associated search does not accept pages, there is no effect.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skip_pages |
int
|
Number of pages that the paginator skips now before fetching the next page. The parameter is added to the internal state, so repeated calls skip more pages. |
required |
Returns:
Type | Description |
---|---|
int
|
The number this paginator is skipping. Internal skip count. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the total number of skipped pages is negative. |