Skip to content

Commit 38d1145

Browse files
hotfix: support all subscriptions api results endpoint query parameters (#1209)
* update subs get_results* methods with missing query params * update cli docs * tests * fix hallucination * update docstring w/ rfc3339
1 parent 0f18793 commit 38d1145

File tree

5 files changed

+349
-59
lines changed

5 files changed

+349
-59
lines changed

docs/cli/cli-subscriptions.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,51 @@ planet subscriptions results SUBSCRIPTION_ID
228228
By default this displays the first 100 results. As with other commands, you can use the `--limit` param to
229229
set a higher limit, or set it to 0 to see all results (this can be quite large with subscriptions results).
230230

231-
You can also filter by status:
231+
#### Filtering Results
232+
233+
The `results` command supports filtering on several fields:
234+
235+
* `--status`: Filter on the status of results. Status options include `created`, `queued`, `processing`, `failed`, and `success`. Multiple status args are allowed.
236+
* `--created`: Filter results by creation time or an interval of creation times.
237+
* `--updated`: Filter results by update time or an interval of update times.
238+
* `--completed`: Filter results by completion time or an interval of completion times.
239+
* `--item-datetime`: Filter results by item datetime or an interval of item datetimes.
240+
241+
Datetime args (`--created`, `--updated`, `--completed`, and `--item-datetime`) can either be a date-time or an interval, open or closed. Date and time expressions adhere to RFC 3339. Open intervals are expressed using double-dots.
242+
243+
* A date-time: `2018-02-12T23:20:50Z`
244+
* A closed interval: `2018-02-12T00:00:00Z/2018-03-18T12:31:12Z`
245+
* Open intervals: `2018-02-12T00:00:00Z/..` or `../2018-03-18T12:31:12Z`
246+
247+
Examples:
248+
249+
To see results that are currently processing:
232250

233251
```sh
234252
planet subscriptions results SUBSCRIPTION_ID --status processing
235253
```
236254

255+
To see successful results completed in the last week:
256+
257+
```sh
258+
planet subscriptions results SUBSCRIPTION_ID --status success \
259+
--completed 2026-03-17T00:00:00Z/..
260+
```
261+
262+
To see results created in a specific time range:
263+
264+
```sh
265+
planet subscriptions results SUBSCRIPTION_ID \
266+
--created 2024-01-01T00:00:00Z/2024-02-01T00:00:00Z
267+
```
268+
269+
To see results for imagery captured after a specific date:
270+
271+
```sh
272+
planet subscriptions results SUBSCRIPTION_ID \
273+
--item-datetime 2024-01-01T00:00:00Z/..
274+
```
275+
237276
See the Subscriptions API documentation for the [official list of available statuses](https://docs.planet.com/develop/apis/subscriptions/#states--status-descriptions).
238277

239278
#### Results as comma-separated values (CSV)

planet/cli/subscriptions.py

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ def subscriptions(ctx, base_url):
5454
@pretty
5555
@click.option(
5656
'--created',
57-
help="""Filter subscriptions by creation time or interval. See documentation
58-
for examples.""")
59-
@click.option(
60-
'--end-time',
61-
help="""Filter subscriptions by end time or interval. See documentation
62-
for examples.""")
57+
help="""Filter subscriptions by creation time or interval (RFC 3339).
58+
See documentation for examples.""")
59+
@click.option('--end-time',
60+
help="""Filter subscriptions by end time or interval (RFC 3339).
61+
See documentation for examples.""")
6362
@click.option(
6463
'--hosting',
6564
type=click.BOOL,
@@ -76,8 +75,8 @@ def subscriptions(ctx, base_url):
7675
available types. Default is all.""")
7776
@click.option(
7877
'--start-time',
79-
help="""Filter subscriptions by start time or interval. See documentation
80-
for examples.""")
78+
help="""Filter subscriptions by start time or interval (RFC 3339).
79+
See documentation for examples.""")
8180
@click.option(
8281
'--status',
8382
type=click.Choice([
@@ -102,10 +101,10 @@ def subscriptions(ctx, base_url):
102101
Supported fields: [name, created, updated, start_time, end_time].
103102
104103
Example: 'name ASC,created DESC'""")
105-
@click.option('--updated',
106-
help="""Filter subscriptions by update time or interval. See
107-
documentation
108-
for examples.""")
104+
@click.option(
105+
'--updated',
106+
help="""Filter subscriptions by update time or interval (RFC 3339). See
107+
documentation for examples.""")
109108
@click.option(
110109
'--destination-ref',
111110
help="Filter subscriptions created with the provided destination reference."
@@ -437,11 +436,19 @@ async def get_subscription_cmd(ctx, subscription_id, pretty):
437436
default=False,
438437
help="Get subscription results as comma-separated fields. When "
439438
"this flag is included, --limit is ignored")
439+
@click.option('--created',
440+
help="""Filter results by creation time or interval (RFC 3339).
441+
See documentation for examples.""")
442+
@click.option('--updated',
443+
help="""Filter results by update time or interval (RFC 3339).
444+
See documentation for examples.""")
445+
@click.option('--completed',
446+
help="""Filter results by completion time or interval (RFC 3339).
447+
See documentation for examples.""")
448+
@click.option('--item-datetime',
449+
help="""Filter results by item datetime or interval (RFC 3339).
450+
See documentation for examples.""")
440451
@limit
441-
# TODO: the following 3 options.
442-
# –created: timestamp instant or range.
443-
# –updated: timestamp instant or range.
444-
# –completed: timestamp instant or range.
445452
@click.pass_context
446453
@translate_exceptions
447454
@coro
@@ -450,6 +457,10 @@ async def list_subscription_results_cmd(ctx,
450457
pretty,
451458
status,
452459
csv_flag,
460+
created,
461+
updated,
462+
completed,
463+
item_datetime,
453464
limit):
454465
"""Print the results of a subscription to stdout.
455466
@@ -473,13 +484,23 @@ async def list_subscription_results_cmd(ctx,
473484
"""
474485
async with subscriptions_client(ctx) as client:
475486
if csv_flag:
476-
async for result in client.get_results_csv(subscription_id,
477-
status=status):
487+
async for result in client.get_results_csv(
488+
subscription_id,
489+
status=status,
490+
created=created,
491+
updated=updated,
492+
completed=completed,
493+
item_datetime=item_datetime):
478494
click.echo(result)
479495
else:
480-
async for result in client.get_results(subscription_id,
481-
status=status,
482-
limit=limit):
496+
async for result in client.get_results(
497+
subscription_id,
498+
status=status,
499+
limit=limit,
500+
created=created,
501+
updated=updated,
502+
completed=completed,
503+
item_datetime=item_datetime):
483504
echo_json(result, pretty)
484505

485506

planet/clients/subscriptions.py

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -514,15 +514,19 @@ async def get_subscription(self, subscription_id: str) -> dict:
514514
sub = resp.json()
515515
return sub
516516

517-
async def get_results(self,
518-
subscription_id: str,
519-
status: Optional[Sequence[Literal[
520-
"created",
521-
"queued",
522-
"processing",
523-
"failed",
524-
"success"]]] = None,
525-
limit: int = 100) -> AsyncIterator[dict]:
517+
async def get_results(
518+
self,
519+
subscription_id: str,
520+
status: Optional[Sequence[Literal["created",
521+
"queued",
522+
"processing",
523+
"failed",
524+
"success"]]] = None,
525+
limit: int = 100,
526+
created: Optional[str] = None,
527+
updated: Optional[str] = None,
528+
completed: Optional[str] = None,
529+
item_datetime: Optional[str] = None) -> AsyncIterator[dict]:
526530
"""Iterate over results of a Subscription.
527531
528532
Notes:
@@ -536,6 +540,19 @@ async def get_results(self,
536540
filter out results with status not in this set.
537541
limit (int): limit the number of subscriptions in the
538542
results. When set to 0, no maximum is applied.
543+
created (str): filter by created time or interval.
544+
updated (str): filter by updated time or interval.
545+
completed (str): filter by completed time or interval.
546+
item_datetime (str): filter by item datetime or interval.
547+
548+
Datetime args (created, updated, completed, item_datetime) can either be a
549+
date-time or an interval, open or closed. Date and time expressions adhere
550+
to RFC 3339. Open intervals are expressed using double-dots.
551+
552+
Examples:
553+
* A date-time: "2018-02-12T23:20:50Z"
554+
* A closed interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"
555+
* Open intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z"
539556
540557
Yields:
541558
dict: description of a subscription results.
@@ -545,13 +562,22 @@ async def get_results(self,
545562
ClientError: on a client error.
546563
"""
547564

548-
# TODO from old doc string, which breaks strict document checking:
549-
# Add Parameters created, updated, completed, user_id
550565
class _ResultsPager(Paged):
551566
"""Navigates pages of messages about subscription results."""
552567
ITEMS_KEY = 'results'
553568

554-
params = {'status': [val for val in status or {}]}
569+
params: Dict[str, Any] = {}
570+
if status is not None:
571+
params['status'] = [val for val in status]
572+
if created is not None:
573+
params['created'] = created
574+
if updated is not None:
575+
params['updated'] = updated
576+
if completed is not None:
577+
params['completed'] = completed
578+
if item_datetime is not None:
579+
params['item_datetime'] = item_datetime
580+
555581
url = f'{self._base_url}/{subscription_id}/results'
556582

557583
try:
@@ -570,20 +596,36 @@ class _ResultsPager(Paged):
570596
raise
571597

572598
async def get_results_csv(
573-
self,
574-
subscription_id: str,
575-
status: Optional[Sequence[Literal["created",
576-
"queued",
577-
"processing",
578-
"failed",
579-
"success"]]] = None
580-
) -> AsyncIterator[str]:
599+
self,
600+
subscription_id: str,
601+
status: Optional[Sequence[Literal["created",
602+
"queued",
603+
"processing",
604+
"failed",
605+
"success"]]] = None,
606+
created: Optional[str] = None,
607+
updated: Optional[str] = None,
608+
completed: Optional[str] = None,
609+
item_datetime: Optional[str] = None) -> AsyncIterator[str]:
581610
"""Iterate over rows of results CSV for a Subscription.
582611
583612
Parameters:
584613
subscription_id (str): id of a subscription.
585614
status (Set[str]): pass result with status in this set,
586615
filter out results with status not in this set.
616+
created (str): filter by created time or interval.
617+
updated (str): filter by updated time or interval.
618+
completed (str): filter by completed time or interval.
619+
item_datetime (str): filter by item datetime or interval.
620+
621+
Datetime args (created, updated, completed, item_datetime) can either be a
622+
date-time or an interval, open or closed. Date and time expressions adhere
623+
to RFC 3339. Open intervals are expressed using double-dots.
624+
625+
Examples:
626+
* A date-time: "2018-02-12T23:20:50Z"
627+
* A closed interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"
628+
* Open intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z"
587629
588630
Yields:
589631
str: a row from a CSV file.
@@ -592,10 +634,18 @@ async def get_results_csv(
592634
APIError: on an API server error.
593635
ClientError: on a client error.
594636
"""
595-
# TODO from old doc string, which breaks strict document checking:
596-
# Add Parameters created, updated, completed, user_id
597637
url = f'{self._base_url}/{subscription_id}/results'
598-
params = {'status': [val for val in status or {}], 'format': 'csv'}
638+
params: Dict[str, Any] = {'format': 'csv'}
639+
if status is not None:
640+
params['status'] = [val for val in status]
641+
if created is not None:
642+
params['created'] = created
643+
if updated is not None:
644+
params['updated'] = updated
645+
if completed is not None:
646+
params['completed'] = completed
647+
if item_datetime is not None:
648+
params['item_datetime'] = item_datetime
599649

600650
# Note: retries are not implemented yet. This project has
601651
# retry logic for HTTP requests, but does not handle errors

0 commit comments

Comments
 (0)