Skip to content

Commit 57add4c

Browse files
Merge pull request #1096 from planetlabs/adrian/page-size
Add page_size arg to list_subscriptions()
2 parents 91a2593 + 25e820b commit 57add4c

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

docs/cli/cli-subscriptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ planet subscriptions list
128128
```
129129

130130
outputs the JSON for your first 100 subscriptions. If you'd like more you can set the `--limit`
131-
parameter higher, or you can set it to 0 and there will be no limit.
131+
parameter higher, or you can set it to 0 and there will be no limit. By default the `list` command will request Subscriptions API with a page size of 500 subscriptions, and can be set lower or higher with the `--page-size` parameter.
132132

133133
You can get nicer formatting with `--pretty` or pipe it into `jq`, just like the other Planet
134134
CLI’s.

planet/cli/subscriptions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ def subscriptions(ctx, base_url):
118118
documentation
119119
for examples.""")
120120
@limit
121+
@click.option('--page-size',
122+
type=click.INT,
123+
help='Number of subscriptions to return per page.')
121124
@click.pass_context
122125
@translate_exceptions
123126
@coro
@@ -133,6 +136,7 @@ async def list_subscriptions_cmd(ctx,
133136
sort_by,
134137
updated,
135138
limit,
139+
page_size,
136140
pretty):
137141
"""Prints a sequence of JSON-encoded Subscription descriptions."""
138142
async with subscriptions_client(ctx) as client:
@@ -147,7 +151,8 @@ async def list_subscriptions_cmd(ctx,
147151
status=status,
148152
sort_by=sort_by,
149153
updated=updated,
150-
limit=limit):
154+
limit=limit,
155+
page_size=page_size):
151156
echo_json(sub, pretty)
152157

153158

planet/clients/subscriptions.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Planet Subscriptions API Python client."""
22

33
import logging
4-
from typing import AsyncIterator, Awaitable, Dict, Optional, Sequence, TypeVar, Union
4+
from typing import Any, AsyncIterator, Awaitable, Dict, Optional, Sequence, TypeVar
55

66
from typing_extensions import Literal
77

@@ -65,19 +65,19 @@ def _call_sync(self, f: Awaitable[T]) -> T:
6565
"""block on an async function call, using the call_sync method of the session"""
6666
return self._session._call_sync(f)
6767

68-
async def list_subscriptions(
69-
self,
70-
status: Optional[Sequence[str]] = None,
71-
limit: int = 100,
72-
created: Optional[str] = None,
73-
end_time: Optional[str] = None,
74-
hosting: Optional[bool] = None,
75-
name__contains: Optional[str] = None,
76-
name: Optional[str] = None,
77-
source_type: Optional[str] = None,
78-
start_time: Optional[str] = None,
79-
sort_by: Optional[str] = None,
80-
updated: Optional[str] = None) -> AsyncIterator[dict]:
68+
async def list_subscriptions(self,
69+
status: Optional[Sequence[str]] = None,
70+
limit: int = 100,
71+
created: Optional[str] = None,
72+
end_time: Optional[str] = None,
73+
hosting: Optional[bool] = None,
74+
name__contains: Optional[str] = None,
75+
name: Optional[str] = None,
76+
source_type: Optional[str] = None,
77+
start_time: Optional[str] = None,
78+
sort_by: Optional[str] = None,
79+
updated: Optional[str] = None,
80+
page_size: int = 500) -> AsyncIterator[dict]:
8181
"""Iterate over list of account subscriptions with optional filtering.
8282
8383
Note:
@@ -112,6 +112,7 @@ async def list_subscriptions(
112112
updated (str): filter by updated time or interval.
113113
limit (int): limit the number of subscriptions in the
114114
results. When set to 0, no maximum is applied.
115+
page_size (int): number of subscriptions to return per page.
115116
TODO: user_id
116117
117118
Datetime args (created, end_time, start_time, updated) can either be a
@@ -135,7 +136,7 @@ class _SubscriptionsPager(Paged):
135136
"""Navigates pages of messages about subscriptions."""
136137
ITEMS_KEY = 'subscriptions'
137138

138-
params: Dict[str, Union[str, Sequence[str], bool]] = {}
139+
params: Dict[str, Any] = {}
139140
if created is not None:
140141
params['created'] = created
141142
if end_time is not None:
@@ -157,6 +158,8 @@ class _SubscriptionsPager(Paged):
157158
if updated is not None:
158159
params['updated'] = updated
159160

161+
params['page_size'] = page_size
162+
160163
try:
161164
response = await self._session.request(method='GET',
162165
url=self._base_url,

planet/sync/subscriptions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def list_subscriptions(self,
4545
source_type: Optional[str] = None,
4646
start_time: Optional[str] = None,
4747
sort_by: Optional[str] = None,
48-
updated: Optional[str] = None) -> Iterator[dict]:
48+
updated: Optional[str] = None,
49+
page_size: int = 500) -> Iterator[dict]:
4950
"""Iterate over list of account subscriptions with optional filtering.
5051
5152
Note:
@@ -80,6 +81,7 @@ def list_subscriptions(self,
8081
updated (str): filter by updated time or interval.
8182
limit (int): limit the number of subscriptions in the
8283
results. When set to 0, no maximum is applied.
84+
page_size (int): number of subscriptions to return per page.
8385
TODO: user_id
8486
8587
Datetime args (created, end_time, start_time, updated) can either be a
@@ -109,7 +111,8 @@ def list_subscriptions(self,
109111
source_type,
110112
start_time,
111113
sort_by,
112-
updated)
114+
updated,
115+
page_size)
113116

114117
try:
115118
while True:

tests/integration/test_subscriptions_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ async def test_list_subscriptions_filtering_and_sorting():
267267
]) == 2
268268

269269

270+
@pytest.mark.parametrize("page_size, count", [(50, 100), (100, 100)])
271+
@pytest.mark.anyio
272+
@api_mock
273+
async def test_list_subscriptions_page_size_success(page_size, count):
274+
async with Session() as session:
275+
client = SubscriptionsClient(session, base_url=TEST_URL)
276+
assert len([
277+
sub async for sub in client.list_subscriptions(page_size=page_size)
278+
]) == count
279+
280+
270281
@pytest.mark.anyio
271282
@failing_api_mock
272283
async def test_create_subscription_failure():

0 commit comments

Comments
 (0)