Skip to content

Commit f14f50a

Browse files
authored
Merge pull request #1079 from planetlabs/DND-1610_new_orders_and_subs_params
Add filtering/sorting parameters to the subscriptions & orders list commands
2 parents e1036c7 + bb68888 commit f14f50a

File tree

12 files changed

+457
-85
lines changed

12 files changed

+457
-85
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2.12.0 (2024-12-06)
2+
- Add parameters to the subscriptions list command: --created, --start-time,
3+
--end-time, --updated, --hosting, --name, --name-contains, and --sort-by.
4+
- Add parameters to the orders list command: --source-type, --name,
5+
--name-contains, --created-on, --last-modified, --hosting, and --sort-by.
6+
17
2.11.0 (2024-10-21)
28

39
Added:

docs/cli/cli-orders.md

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ then check out our [CLI Concepts](cli-intro.md) guide.
1515

1616
## Core Workflows
1717

18-
### See Recent Orders
18+
### List Orders
1919

20-
You can use the `list` command to show your recent orders:
20+
You can use the `list` command to see details of existing orders. By default they will be sorted
21+
by most recently created.
2122

2223
```sh
2324
planet orders list
@@ -26,24 +27,10 @@ planet orders list
2627
If you’ve not placed any orders with Explorer, the CLI or the API directly, then the results
2728
of this call will be blank, so you may want to try out some of the create order commands below.
2829

29-
Sometimes that list gets too long, so you can put a limit on how many are returned:
30+
Sometimes that list gets too long, so you can put a limit on how many are returned using the
31+
`--limit` parameter.
3032

31-
```sh
32-
planet orders list --limit 5
33-
```
34-
35-
You can also filter orders by their `state`, which can be useful to just see orders in
36-
progress:
37-
38-
```sh
39-
planet orders list --state running
40-
```
41-
42-
The other options are queued, failed, success, partial and cancelled.
43-
44-
Note you can also get a nice list online as well, at https://www.planet.com/account/#/orders
45-
46-
### Recent Orders with Formatting
33+
#### Formatting
4734

4835
You can also print the list of orders more nicely:
4936

@@ -71,10 +58,13 @@ planet orders list | jq -rs '.[] | "\(.id) \(.created_on) \(.state) \(.name)"'
7158

7259
You can customize which fields you want to show by changing the values.
7360

74-
### Number of recent orders
61+
A list of your orders can also be viewed in a UI at https://www.planet.com/account/#/orders
7562

76-
You can use jq to process the output for more insight, like
77-
get a count of how many recent orders you’ve done.
63+
#### Number of existing orders
64+
65+
You can use `jq` to process the output for more insight, like get a count of how many existing
66+
orders you have. Orders are automatically deleted 90 days after completion, so this number
67+
roughly is equivalent to the number of orders created in the last 90 days.
7868

7969
```sh
8070
planet orders list | jq -s length
@@ -83,6 +73,65 @@ planet orders list | jq -s length
8373
This uses `-s` to collect the output into a single array, and `length` then tells the
8474
length of the array.
8575

76+
#### Filtering
77+
78+
The `list` command supports filtering on a variety of fields:
79+
* `--state`: Filter by order state. Options include `queued`, `failed`, `success`, `partial` and `cancelled`.
80+
* `--source-type`: Filter by source type. Options include `scenes`, `basemaps`, or `all`. The default is `all`.
81+
* `--name`: Filter by name.
82+
* `--name-contains`: Only return orders with a name that contains the provided string.
83+
* `--created-on`: Filter on the order creation time or an interval of creation times.
84+
* `--last-modified`: Filter on the order's last modified time or an interval of last modified times.
85+
* `--hosting`: Filter on orders containing a hosting location (e.g. SentinelHub). Accepted values are `true` or `false`.
86+
87+
Datetime args (`--created-on` and `--last-modified`) 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.
88+
* A date-time: `2018-02-12T23:20:50Z`
89+
* A closed interval: `2018-02-12T00:00:00Z/2018-03-18T12:31:12Z`
90+
* Open intervals: `2018-02-12T00:00:00Z/..` or `../2018-03-18T12:31:12Z`
91+
92+
To list orders in progress:
93+
```sh
94+
planet orders list --state running
95+
```
96+
97+
To list orders with the `scenes` source type:
98+
```sh
99+
planet orders list --source-type scenes
100+
```
101+
102+
To list orders that were created in 2024:
103+
```sh
104+
planet orders list --created-on 2024-01-01T00:00:00Z/2025-01-01T00:00:00Z
105+
```
106+
107+
To list orders with a hosting location:
108+
```sh
109+
planet orders list --hosting true
110+
```
111+
112+
To list orders with the name `my location xyz`:
113+
```sh
114+
planet orders list --name "my location xyz"
115+
```
116+
117+
To list orders with a name containing `xyz`:
118+
```sh
119+
planet orders list --name-contains xyz
120+
```
121+
122+
#### Sorting
123+
124+
The `list` command also supports sorting the orders on one or more fields: `name`, `created_on`, `state`, and `last_modified`. The sort direction can be specified by appending ` ASC` or ` DESC` to the field name (default is ascending).
125+
126+
When multiple fields are specified, the sort order is applied in the order the fields are listed.
127+
128+
Sorting examples:
129+
* `--sort-by name`: sorts orders by name alphabetically.
130+
* `--sort-by "created_on DESC"`: sorts orders by most recently created.
131+
* `--sort-by "last_modified DESC"`: sorts subscriptions by most recently modified.
132+
* `--sort-by "state ASC"`: sorts orders by state alphabetically.
133+
* `--sort-by "name,last_modified DESC"`: sorts subscriptions by name first, and most recently modified second.
134+
86135
### Info on an Order
87136

88137
For a bit more information about an order, including the location of any downloads, use

docs/cli/cli-subscriptions.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ To create a new subscription with the CLI, use the `create` command and the json
117117
planet subscriptions create my-subscription.json
118118
```
119119

120-
!!!note "Note"
121-
The above command assumes that you’ve saved the subscriptions JSON as `my-subscription.json` and that you’ve replaced the delivery information with your own bucket and credentials.
120+
**Note:** The above command assumes that you’ve saved the subscriptions JSON as `my-subscription.json` and that you’ve replaced the delivery information with your own bucket and credentials.
122121

123122
### List Subscriptions
124123

@@ -134,23 +133,62 @@ parameter higher, or you can set it to 0 and there will be no limit.
134133
You can get nicer formatting with `--pretty` or pipe it into `jq`, just like the other Planet
135134
CLI’s.
136135

137-
The `list` command supports filtering by the status of the subscription:
138-
136+
#### Filtering
137+
138+
The `list` command supports filtering on a variety of fields:
139+
* `--created`: Filter on the subscription creation time or an interval of creation times.
140+
* `--end-time`: Filter on the subscription end time or an interval of end times.
141+
* `--hosting`: Filter on subscriptions containing a hosting location (e.g. SentinelHub). Accepted values are `true` or `false`.
142+
* `--name-contains`: Filter on subscriptions with a name that contains the provided string.
143+
* `--name`: Filter on subscriptions with a specific name
144+
* `--source-type`: Filter by the source type of the subscription. For the full list of available source types, see [Subscription Source Types](https://developers.planet.com/docs/subscriptions/source/#subscription-source-types). Multiple source type args are allowed.
145+
* `--start-time`: Filter on the subscription start time or an interval of start times.
146+
* `--status`: Filter on the status of the subscription. Status options include `running`, `cancelled`, `preparing`, `pending`, `completed`, `suspended`, and `failed`. Multiple status args are allowed.
147+
* `--updated`: Filter on the subscription update time or an interval of updated times.
148+
149+
Datetime args (`--created`, `end-time`, `--start-time`, and `--updated`) 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.
150+
* A date-time: `2018-02-12T23:20:50Z`
151+
* A closed interval: `2018-02-12T00:00:00Z/2018-03-18T12:31:12Z`
152+
* Open intervals: `2018-02-12T00:00:00Z/..` or `../2018-03-18T12:31:12Z`
153+
154+
To list currently active subscriptions:
139155
```sh
140156
planet subscriptions list --status running
141157
```
142158

143-
gives you just the currently active subscriptions. The other available statuses are:
144-
`cancelled`, `preparing`, `pending`, `completed`, `suspended`, and `failed`.
159+
To list subscriptions with the `catalog` source type:
160+
```sh
161+
planet subscriptions list --source-type catalog
162+
```
145163

146-
The `list` command also supports filtering by the source type of the subscription:
164+
To list subscriptions that were created in 2024:
165+
```sh
166+
planet subscriptions list --created 2024-01-01T00:00:00Z/2025-01-01T00:00:00Z
167+
```
147168

169+
To list subscriptions with an end time after Jan 1, 2025:
148170
```sh
149-
planet subscriptions list --source-type catalog
171+
planet subscriptions list --end-time 2025-01-01T00:00:00Z/..
150172
```
151173

152-
only gives you subscriptions with the `catalog` source type. For the full list of available source types,
153-
see [Subscription Source Types](https://developers.planet.com/docs/subscriptions/source/#subscription-source-types).
174+
To list subscriptions with a hosting location:
175+
```sh
176+
planet subscriptions list --hosting true
177+
```
178+
179+
#### Sorting
180+
181+
The `list` command also supports sorting the subscriptions on one or more fields: `name`, `created`, `updated`, `start_time`, and `end_time`. The sort direction can be specified by appending ` ASC` or ` DESC` to the field name (default is ascending).
182+
183+
When multiple fields are specified, the sort order is applied in the order the fields are listed.
184+
185+
Sorting examples:
186+
* `--sort-by name`: sorts subscriptions by name alphabetically.
187+
* `--sort-by "created DESC"`: sorts subscriptions by most recently created.
188+
* `--sort-by "updated DESC"`: sorts subscriptions by most recently updated.
189+
* `--sort-by "start_time ASC"`: sorts subscriptions by start time (earliest to latest)
190+
* `--sort-by "end_time DESC"`: sorts subscriptions by end time (latest to earliest)
191+
* `--sort-by "name,start_time DESC"`: sorts subscriptions by name ascending first, and start time descending second.
154192

155193
### Get Subscription
156194

planet/cli/orders.py

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,72 @@ def orders(ctx, base_url):
5454
@translate_exceptions
5555
@coro
5656
@click.option('--state',
57-
help='Filter orders to given state.',
57+
help='Filter by state.',
5858
type=click.Choice(planet.clients.orders.ORDER_STATE_SEQUENCE,
5959
case_sensitive=False))
60+
@click.option(
61+
'--source-type',
62+
default="all",
63+
help="""Filter by source type. See documentation for all available types.
64+
Default is all.""")
65+
@click.option('--name', help="filter by name")
66+
@click.option(
67+
'--name-contains',
68+
help="only return orders with a name that contains the provided string.")
69+
@click.option(
70+
'--created-on',
71+
help="Filter by creation time or interval. See documentation for examples."
72+
)
73+
@click.option(
74+
'--last-modified',
75+
help="Filter by creation time or interval. See documentation for examples."
76+
)
77+
@click.option(
78+
'--hosting',
79+
type=click.BOOL,
80+
help="Filter by presence of hosting block (e.g. SentinelHub hosting).")
81+
@click.option(
82+
'--sort-by',
83+
help="""fields to sort orders by. Multiple fields can be specified,
84+
separated by commas. The sort direction can be specified by appending
85+
' ASC' or ' DESC' to the field name. The default sort direction is
86+
ascending. When multiple fields are specified, the sort order is applied
87+
in the order the fields are listed.
88+
89+
Supported fields: [name, created_on, state, last_modified].
90+
91+
Example: 'name ASC,created_on DESC'""")
6092
@limit
6193
@pretty
62-
async def list(ctx, state, limit, pretty):
94+
async def list(ctx,
95+
state,
96+
source_type,
97+
name,
98+
name_contains,
99+
created_on,
100+
last_modified,
101+
hosting,
102+
sort_by,
103+
limit,
104+
pretty):
63105
"""List orders
64106
65107
This command prints a sequence of the returned order descriptions,
66108
optionally pretty-printed.
67109
68-
Order descriptions are sorted by creation date with the last created order
110+
By default, order descriptions are sorted by creation date with the last created order
69111
returned first.
70112
"""
71113
async with orders_client(ctx) as cl:
72-
async for o in cl.list_orders(state=state, limit=limit):
114+
async for o in cl.list_orders(state=state,
115+
source_type=source_type,
116+
name=name,
117+
name__contains=name_contains,
118+
created_on=created_on,
119+
last_modified=last_modified,
120+
hosting=hosting,
121+
sort_by=sort_by,
122+
limit=limit):
73123
echo_json(o, pretty)
74124

75125

planet/cli/subscriptions.py

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,32 @@ def subscriptions(ctx, base_url):
6464
# command function as "list_subscriptions".
6565
@subscriptions.command(name="list") # type: ignore
6666
@pretty
67+
@click.option(
68+
'--created',
69+
help="""Filter subscriptions by creation time or interval. See documentation
70+
for examples.""")
71+
@click.option(
72+
'--end-time',
73+
help="""Filter subscriptions by end time or interval. See documentation
74+
for examples.""")
75+
@click.option(
76+
'--hosting',
77+
type=click.BOOL,
78+
help="""Filter subscriptions by presence of hosting block (e.g. SentinelHub
79+
hosting).""")
80+
@click.option(
81+
'--name-contains',
82+
help="""only return subscriptions with a name that contains the provided
83+
string.""")
84+
@click.option('--name', help="filter by name")
85+
@click.option(
86+
'--source-type',
87+
help="""Filter subscriptions by source type. See documentation for all
88+
available types. Default is all.""")
89+
@click.option(
90+
'--start-time',
91+
help="""Filter subscriptions by start time or interval. See documentation
92+
for examples.""")
6793
@click.option(
6894
'--status',
6995
type=click.Choice([
@@ -76,23 +102,52 @@ def subscriptions(ctx, base_url):
76102
"failed"
77103
]),
78104
multiple=True,
79-
default=None,
80105
help="Select subscriptions in one or more states. Default is all.")
81-
@click.option(
82-
'--source-type',
83-
default=None,
84-
help="Filter subscriptions by source type. See documentation for all "
85-
"available types. Default is all.")
106+
@click.option('--sort-by',
107+
help="""fields to sort subscriptions by. Multiple fields can be
108+
specified, separated by commas. The sort direction can be specified by
109+
appending ' ASC' or ' DESC' to the field name. The default sort
110+
direction is ascending. When multiple fields are specified, the sort
111+
order is applied in the order the fields are listed.
112+
113+
Supported fields: [name, created, updated, start_time, end_time].
114+
115+
Example: 'name ASC,created DESC'""")
116+
@click.option('--updated',
117+
help="""Filter subscriptions by update time or interval. See
118+
documentation
119+
for examples.""")
86120
@limit
87121
@click.pass_context
88122
@translate_exceptions
89123
@coro
90-
async def list_subscriptions_cmd(ctx, status, source_type, limit, pretty):
124+
async def list_subscriptions_cmd(ctx,
125+
created,
126+
end_time,
127+
hosting,
128+
name_contains,
129+
name,
130+
source_type,
131+
start_time,
132+
status,
133+
sort_by,
134+
updated,
135+
limit,
136+
pretty):
91137
"""Prints a sequence of JSON-encoded Subscription descriptions."""
92138
async with subscriptions_client(ctx) as client:
93-
async for sub in client.list_subscriptions(status=status,
94-
source_type=source_type,
95-
limit=limit):
139+
async for sub in client.list_subscriptions(
140+
created=created,
141+
end_time=end_time,
142+
hosting=hosting,
143+
name__contains=name_contains,
144+
name=name,
145+
source_type=source_type,
146+
start_time=start_time,
147+
status=status,
148+
sort_by=sort_by,
149+
updated=updated,
150+
limit=limit):
96151
echo_json(sub, pretty)
97152

98153

0 commit comments

Comments
 (0)