Skip to content

Commit 4374ec8

Browse files
Orders API Client Support For Multiple Fallback Bundle(s) (#1106)
* better support for fallback bundles * fix type error * lint and fix types * support none case in check_bundles * add tests * remove mock_bundles arg * try updating conftest * another update to conftest * update docs * address feedback
1 parent 3781d4c commit 4374ec8

File tree

8 files changed

+191
-63
lines changed

8 files changed

+191
-63
lines changed

docs/cli/cli-orders.md

+48-36
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ title: CLI for Orders API Tutorial
55
## Introduction
66

77
The `planet orders` command enables interaction with the [Orders API](https://developers.planet.com/apis/orders/),
8-
which lets you activate and download Planet data products in bulk, and apply various
9-
'tools' to your processes. This tutorial takes you through all the main capabilities
10-
of the CLI for creating and downloading orders. It depends on several more advanced
11-
command-line concepts, but this tutorial should let you get a sense of what you can do,
12-
with enough examples that you should be able to adapt the commands for what you want to do.
8+
which lets you activate and download Planet data products in bulk, and apply various
9+
'tools' to your processes. This tutorial takes you through all the main capabilities
10+
of the CLI for creating and downloading orders. It depends on several more advanced
11+
command-line concepts, but this tutorial should let you get a sense of what you can do,
12+
with enough examples that you should be able to adapt the commands for what you want to do.
1313
If you’re interested in deeper understanding what is going on
1414
then check out our [CLI Concepts](cli-intro.md) guide.
1515

@@ -41,15 +41,15 @@ planet orders list --pretty
4141
The `--pretty` flag is built into most Planet CLI commands, and it formats the JSON to be
4242
more readable.
4343

44-
You can also use `jq`, a powerful command-line JSON-processing tool, that is mentioned in
44+
You can also use `jq`, a powerful command-line JSON-processing tool, that is mentioned in
4545
the [CLI introduction]((cli-intro.md#jq).
4646

4747
```sh
4848
planet orders list | jq
4949
```
5050

51-
Piping any output through jq will format it nicely and do syntax highlighting. You can
52-
also `jq` to just show select information, which can be useful for getting a quick sense
51+
Piping any output through jq will format it nicely and do syntax highlighting. You can
52+
also `jq` to just show select information, which can be useful for getting a quick sense
5353
of the state of the state of things and pull out id’s for other operations:
5454

5555
```sh
@@ -146,10 +146,10 @@ planet orders get 782b414e-4e34-4f31-86f4-5b757bd062d7
146146
To create an order you need a name, a [bundle](https://developers.planet.com/apis/orders/product-bundles-reference/),
147147
one or more id’s, and an [item type](https://developers.planet.com/docs/apis/data/items-assets/#item-types):
148148

149-
First lets get the ID of an item you have download access to, using the Data API:
149+
First lets get the ID of an item you have download access to, using the Data API:
150150

151151
```sh
152-
planet data filter | planet data search PSScene --limit 1 --filter - | jq -r .id
152+
planet data filter | planet data search PSScene --limit 1 --filter - | jq -r .id
153153
```
154154

155155
If you don't have access to PlanetScope data then replace PSScene with SkySatCollect.
@@ -198,6 +198,18 @@ planet orders request \
198198
}
199199
```
200200

201+
#### Fallback bundles
202+
Orders API will deliver [fallback bundles](https://developers.planet.com/apis/orders/scenes/#order-type-and-fallback-bundles) if the first choice product bundle fails for any reason. You can specify one or more fallback bundles by using the `--fallback-bundle` option which accepts a comma separated string of fallback bundles:
203+
204+
```sh
205+
planet orders request \
206+
--item-type PSScene \
207+
--bundle analytic_8b_udm2 \
208+
--fallback-bundle 'analytic_udm2,analytic_3b_udm2' \
209+
--name 'My First Order' \
210+
'20250130_035211_69_2516'
211+
```
212+
201213
#### Zip archives of bundles and orders
202214

203215
You can request that all files of a bundle be zipped together by using the `--archive-type` option. The only type of archive currently available is "zip".
@@ -270,14 +282,14 @@ planet orders request \
270282
> request-1.json
271283
```
272284

273-
Note that `\` just tells the command-line to treat the next line as the same one. It’s used here so it’s
285+
Note that `\` just tells the command-line to treat the next line as the same one. It’s used here so it’s
274286
easier to read, but you can still copy and paste the full line into your command-line and it should work.
275287

276288
This saves the above JSON in a file called `request-1.json`
277289

278290
### Create an Order
279291

280-
From there you can create the order with the request you just saved:
292+
From there you can create the order with the request you just saved:
281293

282294
```sh
283295
planet orders create request-1.json
@@ -343,7 +355,7 @@ planet orders request --item-type PSScene --bundle analytic_sr_udm2 --name 'Two
343355
20220605_124027_64_242b,20220605_124025_34_242b | planet orders create -
344356
```
345357

346-
The Planet CLI is designed to work well with piping, as it aims at small commands that can be
358+
The Planet CLI is designed to work well with piping, as it aims at small commands that can be
347359
combined in powerful ways, so you’ll see it used in a number of the examples.
348360

349361
### Download an order
@@ -360,22 +372,22 @@ way see the next example.
360372

361373
### Wait then download an order
362374

363-
The `wait` command is a small, dedicated command that polls the server to
375+
The `wait` command is a small, dedicated command that polls the server to
364376
see if an order is ready for downloading, showing the status. It’s not
365377
so useful by itself, but can be combined with the `download` command to
366378
only start the download once the order is ready:
367379

368380
```sh
369381
planet orders wait 65df4eb0-e416-4243-a4d2-38afcf382c30 \
370-
&& planet orders download 65df4eb0-e416-4243-a4d2-38afcf382c30
382+
&& planet orders download 65df4eb0-e416-4243-a4d2-38afcf382c30
371383
```
372384

373385
This uses the logical AND operator (`&&`) to say "don't run the second command
374386
until the first is done".
375387

376388
### Save order ID
377389

378-
You can also use a unix variable to store the order id of your most recently placed order,
390+
You can also use a unix variable to store the order id of your most recently placed order,
379391
and then use that for the wait and download commands:
380392

381393
```sh
@@ -425,7 +437,7 @@ planet orders download \
425437

426438
### Verify checksum
427439

428-
The `--checksum` command will do an extra step to make sure the file you got
440+
The `--checksum` command will do an extra step to make sure the file you got
429441
wasn't corrupted along the way (during download, etc). It checks that the bytes
430442
downloaded are the same as the ones on the server. By default it doesn't show
431443
anything if the checksums match.
@@ -434,8 +446,8 @@ anything if the checksums match.
434446
planet orders download 782b414e-4e34-4f31-86f4-5b757bd062d7 --checksum MD5
435447
```
436448

437-
This command isn't often necessary in single download commands, but is quite
438-
useful if you are downloading thousands of files with a script, as the likelihood
449+
This command isn't often necessary in single download commands, but is quite
450+
useful if you are downloading thousands of files with a script, as the likelihood
439451
of at least one being corrupted in creases
440452

441453
## Tools with orders
@@ -490,10 +502,10 @@ Example: `geometry.geojson`
490502
}
491503
```
492504

493-
We’ll work with a geojson that is already saved. You should download the
505+
We’ll work with a geojson that is already saved. You should download the
494506
[geometry](https://raw.githubusercontent.com/planetlabs/planet-client-python/main/docs/cli/request-json/geometry.geojson)
495507
(and you can see it [on github](https://github.com/planetlabs/planet-client-python/blob/main/docs/cli/request-json/geometry.geojson)
496-
or it is also stored in the repo in the [request-json/](request-json/) directory.
508+
or it is also stored in the repo in the [request-json/](request-json/) directory.
497509

498510
You can move that geometry to your current directory and use the following command, or
499511
tweak the geometry.geojson to refer to where you downloaded it.
@@ -511,8 +523,8 @@ planet orders request \
511523
### Additional Tools
512524

513525
Since clip is so heavily used it has its own dedicated command in the CLI. All
514-
the other tools use the `--tools` option, that points to a file. The file should
515-
contain JSON that follows the format for a toolchain, the "tools" section of an order.
526+
the other tools use the `--tools` option, that points to a file. The file should
527+
contain JSON that follows the format for a toolchain, the "tools" section of an order.
516528
The toolchain options and format are given in
517529
[Creating Toolchains](https://developers.planet.com/apis/orders/tools/#creating-toolchains).
518530

@@ -543,9 +555,9 @@ Example: `tools.json`
543555
```
544556

545557
!!!note Note
546-
Future of the versions of the CLI will likely add `tools` convenience methods,
547-
so composite, harmonize and other tools work like `--clip`. You can follow issue
548-
[#601](https://github.com/planetlabs/planet-client-python/issues/601):
558+
Future of the versions of the CLI will likely add `tools` convenience methods,
559+
so composite, harmonize and other tools work like `--clip`. You can follow issue
560+
[#601](https://github.com/planetlabs/planet-client-python/issues/601):
549561
comment there if you'd like to see it prioritized
550562

551563
### Compositing
@@ -561,7 +573,7 @@ planet orders request \
561573
| planet orders create -
562574
```
563575

564-
And then you can composite them together, using the 'tools' json. You can
576+
And then you can composite them together, using the 'tools' json. You can
565577
use this, just save it into a file called [tools-composite.json](https://raw.githubusercontent.com/planetlabs/planet-client-python/main/docs/cli/request-json/tools-composite.json).
566578

567579
```json
@@ -573,7 +585,7 @@ use this, just save it into a file called [tools-composite.json](https://raw.git
573585
]
574586
```
575587

576-
Once you’ve got it saved you call the `--tools` flag to refer to the JSON file, and you
588+
Once you’ve got it saved you call the `--tools` flag to refer to the JSON file, and you
577589
can pipe that to `orders create`.
578590

579591
```sh
@@ -587,12 +599,12 @@ planet orders request \
587599
| planet orders create -
588600
```
589601

590-
Note that we add the `--no-stac` option as [STAC Metadata](#stac-metadata) is not yet supported by the composite
602+
Note that we add the `--no-stac` option as [STAC Metadata](#stac-metadata) is not yet supported by the composite
591603
operation, but STAC metadata is requested by default with the CLI.
592604

593605
### Output as COG
594606

595-
If you'd like to ensure the above order is a Cloud-Optimized Geotiff then you can request it
607+
If you'd like to ensure the above order is a Cloud-Optimized Geotiff then you can request it
596608
as COG in the file format tool.
597609

598610
```json
@@ -616,7 +628,7 @@ planet orders request \
616628
--tools tools-cog.json
617629
```
618630

619-
As shown above you can also pipe that output directly in to `orders create`.
631+
As shown above you can also pipe that output directly in to `orders create`.
620632

621633
### Clip & Composite
622634

@@ -713,7 +725,7 @@ planet orders request --item-type PSScene --bundle analytic_sr_udm2 --name 'Harm
713725
### STAC Metadata
714726

715727
A relatively recent addition to Planet’s orders delivery is the inclusion of [SpatioTemporal Asset Catalog](https://stacspec.org/en)
716-
(STAC) metadata in Orders. STAC metadata provides a more standard set of JSON fields that work with
728+
(STAC) metadata in Orders. STAC metadata provides a more standard set of JSON fields that work with
717729
many GIS and geospatial [STAC-enabled tools](https://stacindex.org/ecosystem). The CLI `orders request` command currently requests
718730
STAC metadata by default, as the STAC files are small and often more useful than the default JSON metadata.
719731
You can easily turn off STAC output request with the `--no-stac` command:
@@ -727,7 +739,7 @@ planet orders request \
727739
20220605_124027_64_242b
728740
```
729741

730-
Currently this needs to be done for any 'composite' operation, as STAC output from composites is not yet
742+
Currently this needs to be done for any 'composite' operation, as STAC output from composites is not yet
731743
supported (but is coming). You can explicitly add `--stac`, but it is the default, so does not need to
732744
be included. For more information about Planet’s STAC output see the [Orders API documentation](https://developers.planet.com/apis/orders/delivery/#stac-metadata).
733745

@@ -772,7 +784,7 @@ request. So the following call is a quick way to exactly redo a previous order r
772784
planet orders get <order-id> | planet orders create -
773785
```
774786

775-
Realistically you'd more likely want to get a previous order and then change it in some way (new id’s, different
787+
Realistically you'd more likely want to get a previous order and then change it in some way (new id’s, different
776788
tools, etc.). You can remove the 'extra' JSON fields that report on status if you'd like, but the Orders
777789
API will just ignore them if they are included in a request.
778790

@@ -832,7 +844,7 @@ planet orders list --limit 1
832844
Extract the ID:
833845

834846
```sh
835-
planet orders list --limit 1 | jq -r .id
847+
planet orders list --limit 1 | jq -r .id
836848
```
837849

838850
Use that ID to wait and download when it’s ready:
@@ -870,7 +882,7 @@ planet orders request \
870882
| planet orders create -
871883
```
872884

873-
Or get the 5 latest cloud free images in an area and create an order that clips to that area, using
885+
Or get the 5 latest cloud free images in an area and create an order that clips to that area, using
874886
[geometry.geojson](data/geometry.geojson) from above:
875887

876888
```sh

docs/python/async-sdk-guide.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This guide walks you through the steps:
1414

1515
## Install the Planet Python SDK
1616

17-
Use a package manager (such as `pip`) to install the Planet Python SDK:
17+
Use a package manager (such as `pip`) to install the Planet Python SDK:
1818

1919
```sh
2020
pip install planet
@@ -55,7 +55,7 @@ auth.store()
5555
The default authentication behavior of the `Session` can be modified by specifying
5656
`Auth` explicitly using the methods `Auth.from_file()` and `Auth.from_env()`.
5757
While `Auth.from_key()` and `Auth.from_login` can be used, it is recommended
58-
that those functions be used in authentication initialization. Authentication
58+
that those functions be used in authentication initialization. Authentication
5959
information should be stored using `Auth.store()`.
6060

6161
You can customize the manner of retrieval and location to read from when retrieving the authorization information. The file and environment variable read from can be customized in the respective functions. For example, authentication can be read from a custom
@@ -175,8 +175,9 @@ def create_request():
175175
name='oregon_order',
176176
products=[
177177
planet.order_request.product(item_ids=oregon_items,
178-
product_bundle='analytic_udm2',
179-
item_type='PSScene')
178+
product_bundle='analytic_8b_udm2',
179+
item_type='PSScene'
180+
fallback_bundle='analytic_udm2,analytic_3b_udm2')
180181
],
181182
tools=[planet.order_request.clip_tool(aoi=oregon_aoi)])
182183

@@ -193,7 +194,7 @@ This would be equivalent to a manually created JSON object with the following de
193194
"Item_ids":["20200909_182525_1014",
194195
"20200909_182524_1014"],
195196
"item_type":"PSScene",
196-
"product_bundle":"analytic_sr_udm2"
197+
"product_bundle":"analytic_8b_udm2,analytic_udm2,analytic_3b_udm2"
197198
}
198199
],
199200
"tools": [
@@ -431,7 +432,7 @@ waiting for the asset to be active, downloading the asset, and, optionally,
431432
validating the downloaded file.
432433

433434
With wait and download, it is often desired to track progress as these
434-
processes can take a long time. Therefore, in this example, we use a simple
435+
processes can take a long time. Therefore, in this example, we use a simple
435436
print command to report wait status. `download_asset` has reporting built in.
436437

437438
```python
@@ -444,7 +445,7 @@ async def download_and_validate():
444445
item_id = '20221003_002705_38_2461'
445446
asset_type_id = 'ortho_analytic_4b'
446447
asset = await cl.get_asset(item_type_id, item_id, asset_type_id)
447-
448+
448449
# activate asset
449450
await cl.activate_asset(asset)
450451

@@ -466,7 +467,7 @@ Collections and Features/items that you create in in the SDK will be visible in
466467

467468
#### Creating a collection
468469

469-
You can use the Python SDK to create Features API collections.
470+
You can use the Python SDK to create Features API collections.
470471

471472
```python
472473
async with Session() as sess:

docs/python/sdk-guide.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ title: Python SDK User Guide
44

55
This guide is for Planet SDK for Python users who want to use Python code to search, order, customize, and deliver Planet imagery and data. If you’re new to Python, you may want to choose the no-code option of using the [command-line interface (CLI)](../../cli/cli-guide). But if you’ve successfully followed the instructions to [get started](../../get-started/quick-start-guide) and you’re ready to try your hand at Python coding, this guide should be all you need to use this SDK to get Planet data.
66

7-
!!!note
7+
!!!note
88
Looking for the asyncio-based SDK? See the [Planet Async SDK guide](./async-sdk-guide.md).
99

1010
## Usage
1111

1212
### Install the Planet Python SDK
1313

14-
Use a package manager (such as `pip`) to install the Planet Python SDK:
14+
Use a package manager (such as `pip`) to install the Planet Python SDK:
1515

1616
```sh
1717
pip install planet
@@ -152,7 +152,7 @@ waiting for the asset to be active, downloading the asset, and, optionally,
152152
validating the downloaded file.
153153

154154
With wait and download, it is often desired to track progress as these
155-
processes can take a long time. Therefore, in this example, we use a simple
155+
processes can take a long time. Therefore, in this example, we use a simple
156156
print command to report wait status. `download_asset` has reporting built in.
157157

158158
!!!note
@@ -204,8 +204,9 @@ def main():
204204
products=[
205205
order_request.product(
206206
item_ids=image_ids,
207-
product_bundle='analytic_udm2',
208-
item_type='psscene')
207+
product_bundle='analytic_8b_udm2',
208+
item_type='PSScene',
209+
fallback_bundle='analytic_udm2,analytic_3b_udm2')
209210
]
210211
)
211212

@@ -272,7 +273,7 @@ Collections and Features/items that you create in in the SDK will be visible in
272273

273274
#### Creating a collection
274275

275-
You can use the Python SDK to create feature collections in the Features API.
276+
You can use the Python SDK to create feature collections in the Features API.
276277

277278
```python
278279
new_collection = pl.features.create_collection(title="my collection", description="a new collection")

0 commit comments

Comments
 (0)