tilebox-grpc 0.34.0__tar.gz → 0.36.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tilebox-grpc
3
- Version: 0.34.0
3
+ Version: 0.36.0
4
4
  Summary: GRPC / Protocol Buffers functions for Tilebox
5
5
  Project-URL: Homepage, https://tilebox.com
6
6
  Project-URL: Documentation, https://docs.tilebox.com/
@@ -0,0 +1,29 @@
1
+ from collections.abc import AsyncIterator, Awaitable, Callable
2
+
3
+ from _tilebox.grpc.pagination import AnyResultPage, Pagination
4
+
5
+
6
+ async def paginated_request(
7
+ paging_request: Callable[[Pagination], Awaitable[AnyResultPage]],
8
+ initial_page: Pagination,
9
+ ) -> AsyncIterator[AnyResultPage]:
10
+ """Make a paginated request to a gRPC service endpoint.
11
+
12
+ The endpoint is expected to return a next_page field, which is used for subsequent requests. Once no such
13
+ next_page field is returned, the request is completed.
14
+
15
+ Args:
16
+ paging_request: A function that takes a page as input and returns a Datapoints object
17
+ Often this will be a functools.partial object that wraps a gRPC service endpoint
18
+ and only leaves the page argument remaining
19
+ initial_page: The initial page to request
20
+
21
+ Yields:
22
+ Datapoints: The individual pages of the response
23
+ """
24
+ response = await paging_request(initial_page)
25
+ yield response
26
+
27
+ while response.next_page.starting_after is not None:
28
+ response = await paging_request(response.next_page)
29
+ yield response
@@ -0,0 +1,42 @@
1
+ from collections.abc import Callable, Iterator
2
+ from typing import Protocol, TypeVar
3
+ from uuid import UUID
4
+
5
+
6
+ class Pagination(Protocol):
7
+ limit: int | None
8
+ starting_after: UUID | None
9
+
10
+
11
+ class ResultPage(Protocol):
12
+ @property
13
+ def next_page(self) -> Pagination: ...
14
+
15
+
16
+ AnyResultPage = TypeVar("AnyResultPage", bound=ResultPage)
17
+
18
+
19
+ def paginated_request(
20
+ paging_request: Callable[[Pagination], AnyResultPage],
21
+ initial_page: Pagination,
22
+ ) -> Iterator[AnyResultPage]:
23
+ """Make a paginated request to a gRPC service endpoint.
24
+
25
+ The endpoint is expected to return a next_page field, which is used for subsequent requests. Once no such
26
+ next_page field is returned, the request is completed.
27
+
28
+ Args:
29
+ paging_request: A function that takes a page as input and returns a Datapoints object
30
+ Often this will be a functools.partial object that wraps a gRPC service endpoint
31
+ and only leaves the page argument remaining
32
+ initial_page: The initial page to request
33
+
34
+ Yields:
35
+ Datapoints: The individual pages of the response
36
+ """
37
+ response = paging_request(initial_page)
38
+ yield response
39
+
40
+ while response.next_page.starting_after is not None:
41
+ response = paging_request(response.next_page)
42
+ yield response
File without changes
File without changes