Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code snippets for all APIs #939

Draft
wants to merge 46 commits into
base: maint-2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8731065
Skelleton readme and file.
kevinlacaille Apr 25, 2023
fc7455c
Added a few more snippets.
kevinlacaille Apr 25, 2023
88cf85f
Added a few more snippets.
kevinlacaille Apr 25, 2023
21953fd
Added all the snippets.
kevinlacaille Apr 25, 2023
5d57005
Added an order example, though may be not needed.
kevinlacaille Apr 25, 2023
9dbcaca
Removed unused lib.
kevinlacaille Apr 25, 2023
a33d17f
Created skeleton for data API snippets.
kevinlacaille Apr 25, 2023
69c717f
Added about half the snippets for data.
kevinlacaille Apr 25, 2023
0a6eb42
Added all the snippets and a search filter example.
kevinlacaille Apr 26, 2023
e89e8e2
Changed print to callback and return
kevinlacaille Apr 26, 2023
c83e2fe
Return nothing for wait.
kevinlacaille Apr 26, 2023
bbdc717
Added all snippets. TO DO: create request.
kevinlacaille Apr 26, 2023
34a2a61
Added docstring to order request example.
kevinlacaille Apr 26, 2023
74c9ab9
Added docstring to search filter creation.
kevinlacaille Apr 26, 2023
8595f24
Added a create request function.
kevinlacaille Apr 26, 2023
3688ebe
Added keywords.
kevinlacaille Apr 26, 2023
d719f21
Added keywords.
kevinlacaille Apr 26, 2023
f6c24cd
Updated comment.
kevinlacaille Apr 26, 2023
ff1526a
linting
kevinlacaille Apr 26, 2023
a81d00b
linting
kevinlacaille Apr 26, 2023
fdb21da
new structure for sdk docs, based on cli
cholmes Apr 27, 2023
70269e9
new structure for sdk docs, based on cli
cholmes Apr 27, 2023
00191ba
fleshed out subscriptions docs for SDK
cholmes Apr 27, 2023
74e9459
Added pymdownx.snippets as a MD ext.
kevinlacaille May 1, 2023
4a1f78d
Updated docs requirements.
kevinlacaille May 1, 2023
6ba91c4
Merge branch 'code_snippets_orders_api-540' of github.com:planetlabs/…
kevinlacaille May 1, 2023
45c132b
Removed and added to a new branch, for docs, snippets-docs-936.
kevinlacaille May 1, 2023
84a9c1f
Removed and added to a new branch, for docs, snippets-docs-936.
kevinlacaille May 1, 2023
d18bdc1
Removed and added to a new branch, for docs, snippets-docs-936.
kevinlacaille May 1, 2023
b80cd53
Removed unneeded readme
kevinlacaille May 1, 2023
5ea5fb8
Renamed file for testing.
kevinlacaille May 3, 2023
f177894
Updated search test and added tests for create search and update search.
kevinlacaille May 4, 2023
ababdab
Added a few more tests, some work and some dont
kevinlacaille May 5, 2023
a8d5d49
Added download snippets.
kevinlacaille May 5, 2023
d8e7046
Renamed file for testing.
kevinlacaille May 9, 2023
3e769b0
Removed unused pytest fixture.
kevinlacaille May 9, 2023
307cd99
Added a bunch of orders snippets with clever tricks to get order ids.…
kevinlacaille May 10, 2023
a06abfc
Remove downloaded files.
kevinlacaille May 10, 2023
a0eb085
Download asset added.
kevinlacaille May 10, 2023
92bc2eb
Added all passing Orders tests.
kevinlacaille May 11, 2023
e718771
Fixed all broken tests.
kevinlacaille May 11, 2023
cd0cae9
Fixed unused test
kevinlacaille May 11, 2023
cfbf44d
test
kevinlacaille May 11, 2023
008bb55
linting
kevinlacaille May 11, 2023
84b3ede
Have tests create their own search id; limit to 2 items.
kevinlacaille Jul 10, 2023
a38c0c1
Added succesful order to download. Temp. solution.
kevinlacaille Jul 11, 2023
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
116 changes: 116 additions & 0 deletions tests/snippets/subscriptions_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Copyright 2023 Planet Labs PBC.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Example of creating and downloading multiple orders.

This is an example of submitting two orders, waiting for them to complete, and
downloading them. The orders each clip a set of images to a specific area of
interest (AOI), so they cannot be combined into one order.

[Planet Explorer](https://www.planet.com/explorer/) was used to define
the AOIs and get the image ids.
"""
import planet
from datetime import datetime
from planet.subscription_request import (build_request,
catalog_source,
amazon_s3,
harmonize_tool)


def create_request():
'''Create a subscription request.'''

# Area of interest for the subscription
geom = {
"coordinates":
[[[139.5648193359375,
35.42374884923695], [140.1031494140625, 35.42374884923695],
[140.1031494140625,
35.77102915686019], [139.5648193359375, 35.77102915686019],
[139.5648193359375, 35.42374884923695]]],
"type":
"Polygon"
}
source = catalog_source(item_types=["PSScene"],
asset_types=["ortho_analytic_4b"],
geometry=geom,
start_time=datetime(2021, 3, 1))
delivery = amazon_s3(aws_access_key_id="ACCESS-KEY-ID",
aws_secret_access_key="SECRET_ACCESS_KEY",
bucket="test_bucket",
aws_region="us-east-1")
tools = harmonize_tool(target_sensor="Sentinel-2")

# Build your subscriptions request
subscription_request = build_request(name='test_subscription',
source=source,
delivery=delivery,
tools=tools)
return subscription_request


# list_subscriptions
async def list_subscriptions(status, limit):
'''Code snippet for list_subscriptions.'''
async with planet.Session() as sess:
client = sess.client('subscriptions')
async for sub in client.list_subscriptions(status=status, limit=limit):
return sub


# create_subscription
async def create_subscription(request):
'''Code snippet for create_subscription.'''
async with planet.Session() as sess:
client = sess.client('subscriptions')
sub = await client.create_subscription(request=request)
return sub


# cancel_subscription
async def cancel_subscription(subscription_id):
'''Code snippet for cancel_subscription.'''
async with planet.Session() as sess:
client = sess.client('subscriptions')
_ = await client.cancel_subscription(subscription_id=subscription_id)


# update_subscription
async def update_subscription(subscription_id, request):
'''Code snippet for update_subscription.'''
async with planet.Session() as sess:
client = sess.client('subscriptions')
sub = await client.update_subscription(subscription_id=subscription_id,
request=request)
return sub


# get_subscription
async def get_subscription(subscription_id):
'''Code snippet for get_subscription.'''
async with planet.Session() as sess:
client = sess.client('subscriptions')
sub = await client.get_subscription(subscription_id=subscription_id)
return sub


# get_results
async def get_results(subscription_id, status, limit):
'''Code snippet for get_results.'''
async with planet.Session() as sess:
client = sess.client('subscriptions')
async for result in client.get_results(subscription_id=subscription_id,
status=status,
limit=limit):
return result
Loading