Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cli/cli-subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ planet subscriptions list
```

outputs the JSON for your first 100 subscriptions. If you'd like more you can set the `--limit`
parameter higher, or you can set it to 0 and there will be no limit.
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.

You can get nicer formatting with `--pretty` or pipe it into `jq`, just like the other Planet
CLI’s.
Expand Down
7 changes: 6 additions & 1 deletion planet/cli/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def subscriptions(ctx, base_url):
documentation
for examples.""")
@limit
@click.option('--page-size',
type=click.INT,
help='Number of subscriptions to return per page.')
@click.pass_context
@translate_exceptions
@coro
Expand All @@ -133,6 +136,7 @@ async def list_subscriptions_cmd(ctx,
sort_by,
updated,
limit,
page_size,
pretty):
"""Prints a sequence of JSON-encoded Subscription descriptions."""
async with subscriptions_client(ctx) as client:
Expand All @@ -147,7 +151,8 @@ async def list_subscriptions_cmd(ctx,
status=status,
sort_by=sort_by,
updated=updated,
limit=limit):
limit=limit,
page_size=page_size):
echo_json(sub, pretty)


Expand Down
33 changes: 18 additions & 15 deletions planet/clients/subscriptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Planet Subscriptions API Python client."""

import logging
from typing import AsyncIterator, Awaitable, Dict, Optional, Sequence, TypeVar, Union
from typing import Any, AsyncIterator, Awaitable, Dict, Optional, Sequence, TypeVar

from typing_extensions import Literal

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

async def list_subscriptions(
self,
status: Optional[Sequence[str]] = None,
limit: int = 100,
created: Optional[str] = None,
end_time: Optional[str] = None,
hosting: Optional[bool] = None,
name__contains: Optional[str] = None,
name: Optional[str] = None,
source_type: Optional[str] = None,
start_time: Optional[str] = None,
sort_by: Optional[str] = None,
updated: Optional[str] = None) -> AsyncIterator[dict]:
async def list_subscriptions(self,
status: Optional[Sequence[str]] = None,
limit: int = 100,
created: Optional[str] = None,
end_time: Optional[str] = None,
hosting: Optional[bool] = None,
name__contains: Optional[str] = None,
name: Optional[str] = None,
source_type: Optional[str] = None,
start_time: Optional[str] = None,
sort_by: Optional[str] = None,
updated: Optional[str] = None,
page_size: int = 500) -> AsyncIterator[dict]:
"""Iterate over list of account subscriptions with optional filtering.

Note:
Expand Down Expand Up @@ -112,6 +112,7 @@ async def list_subscriptions(
updated (str): filter by updated time or interval.
limit (int): limit the number of subscriptions in the
results. When set to 0, no maximum is applied.
page_size (int): number of subscriptions to return per page.
TODO: user_id

Datetime args (created, end_time, start_time, updated) can either be a
Expand All @@ -135,7 +136,7 @@ class _SubscriptionsPager(Paged):
"""Navigates pages of messages about subscriptions."""
ITEMS_KEY = 'subscriptions'

params: Dict[str, Union[str, Sequence[str], bool]] = {}
params: Dict[str, Any] = {}
if created is not None:
params['created'] = created
if end_time is not None:
Expand All @@ -157,6 +158,8 @@ class _SubscriptionsPager(Paged):
if updated is not None:
params['updated'] = updated

params['page_size'] = page_size

try:
response = await self._session.request(method='GET',
url=self._base_url,
Expand Down
7 changes: 5 additions & 2 deletions planet/sync/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def list_subscriptions(self,
source_type: Optional[str] = None,
start_time: Optional[str] = None,
sort_by: Optional[str] = None,
updated: Optional[str] = None) -> Iterator[dict]:
updated: Optional[str] = None,
page_size: int = 500) -> Iterator[dict]:
"""Iterate over list of account subscriptions with optional filtering.

Note:
Expand Down Expand Up @@ -80,6 +81,7 @@ def list_subscriptions(self,
updated (str): filter by updated time or interval.
limit (int): limit the number of subscriptions in the
results. When set to 0, no maximum is applied.
page_size (int): number of subscriptions to return per page.
TODO: user_id

Datetime args (created, end_time, start_time, updated) can either be a
Expand Down Expand Up @@ -109,7 +111,8 @@ def list_subscriptions(self,
source_type,
start_time,
sort_by,
updated)
updated,
page_size)

try:
while True:
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_subscriptions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ async def test_list_subscriptions_filtering_and_sorting():
]) == 2


@pytest.mark.parametrize("page_size, count", [(50, 100), (100, 100)])
@pytest.mark.anyio
@api_mock
async def test_list_subscriptions_page_size_success(page_size, count):
async with Session() as session:
client = SubscriptionsClient(session, base_url=TEST_URL)
assert len([
sub async for sub in client.list_subscriptions(page_size=page_size)
]) == count


@pytest.mark.anyio
@failing_api_mock
async def test_create_subscription_failure():
Expand Down
Loading