Skip to content

Commit 4b57b60

Browse files
authored
Merge pull request #814 from planetlabs/revert-name-change-813
Revert generator functions name change and update usage
2 parents d4c8b26 + a810448 commit 4b57b60

File tree

11 files changed

+120
-121
lines changed

11 files changed

+120
-121
lines changed

docs/get-started/upgrading.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ For more information about Session, refer to the [Python SDK User Guide](../../p
3535

3636
With the V1 client, all communication was synchronous. Asynchronous bulk support was provided with the `downloader` module. There was no built-in support for polling when an order was ready to download or tracking when an order was downloaded.
3737

38-
In V2, all `*Client` methods (for example, `DataClient().search_aiter`, `OrderClient().create_order`) are asynchronous. Any functions that call such methods must include `async` in their definition. To invoke asynchronous methods from synchronous code, you can wrap the async method calls in `asyncio.run()`. The following is an example of using async with session.
38+
In V2, all `*Client` methods (for example, `DataClient().search`, `OrderClient().create_order`) are asynchronous. Any functions that call such methods must include `async` in their definition. To invoke asynchronous methods from synchronous code, you can wrap the async method calls in `asyncio.run()`. The following is an example of using async with session.
3939

4040
```python
4141
import asyncio
@@ -49,8 +49,7 @@ async def do_search():
4949
date_filter = filters.date_range_filter('acquired', gte=datetime.fromisoformat("2022-11-18"), lte=datetime.fromisoformat("2022-11-21"))
5050
cloud_filter = filters.range_filter('cloud_cover', lte=0.1)
5151
download_filter = filters.permission_filter()
52-
search_results = await client.search(["PSScene"], filters.and_filter([date_filter, cloud_filter, download_filter]))
53-
return [item async for item in search_results]
52+
return [item async for item in client.search(["PSScene"], filters.and_filter([date_filter, cloud_filter, download_filter]))]
5453

5554
items = asyncio.run(do_search())
5655
```
@@ -74,8 +73,8 @@ planet.api.ClientV1().quick_search(filters.build_search_request(all_filters, ["P
7473
Is now
7574

7675
```python
77-
async with Session() as session:
78-
items_aiter = planet.DataClient(session).search_aiter(["PSScene"], all_filters)
76+
async with Session() as session:
77+
items = [i async for i in planet.DataClient(session).search(["PSScene"], all_filters)]
7978
```
8079

8180
## Orders API

docs/python/sdk-guide.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ from planet import collect, OrdersClient, Session
268268
async def main():
269269
async with Session() as sess:
270270
client = OrdersClient(sess)
271-
orders_aiter = client.list_orders_aiter()
272-
orders_list = collect(orders_aiter)
271+
orders_list = collect(client.list_orders())
273272

274273
asyncio.run(main())
275274

@@ -278,7 +277,7 @@ asyncio.run(main())
278277
Alternatively, these results can be converted to a list directly with
279278

280279
```python
281-
orders_list = [o async for o in client.list_orders_aiter()]
280+
orders_list = [o async for o in client.list_orders()]
282281
```
283282

284283
## Query the data catalog
@@ -341,7 +340,7 @@ the context of a `Session` with the `DataClient`:
341340
async def main():
342341
async with Session() as sess:
343342
cl = DataClient(sess)
344-
items = await cl.search(['PSScene'], sfilter)
343+
items = [i async for i in cl.search(['PSScene'], sfilter)]
345344

346345
asyncio.run(main())
347346
```

planet/cli/data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ async def search(ctx, item_types, filter, limit, name, sort, pretty):
272272
parameter will be applied to the stored quick search.
273273
"""
274274
async with data_client(ctx) as cl:
275-
items_aiter = cl.search_aiter(item_types,
276-
filter,
277-
name=name,
278-
sort=sort,
279-
limit=limit)
280-
async for item in items_aiter:
275+
276+
async for item in cl.search(item_types,
277+
filter,
278+
name=name,
279+
sort=sort,
280+
limit=limit):
281281
echo_json(item, pretty)
282282

283283

planet/cli/orders.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ async def list(ctx, state, limit, pretty):
6767
optionally pretty-printed.
6868
'''
6969
async with orders_client(ctx) as cl:
70-
orders_aiter = cl.list_orders_aiter(state=state, limit=limit)
71-
async for o in orders_aiter:
70+
async for o in cl.list_orders(state=state, limit=limit):
7271
echo_json(o, pretty)
7372

7473

planet/cli/subscriptions.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ async def list_subscriptions_cmd(ctx, status, limit, pretty):
4242
"""Prints a sequence of JSON-encoded Subscription descriptions."""
4343
async with CliSession(auth=ctx.obj['AUTH']) as session:
4444
client = SubscriptionsClient(session)
45-
subs_aiter = client.list_subscriptions_aiter(status=status,
46-
limit=limit)
47-
async for sub in subs_aiter:
45+
async for sub in client.list_subscriptions(status=status, limit=limit):
4846
echo_json(sub, pretty)
4947

5048

@@ -158,8 +156,7 @@ async def list_subscription_results_cmd(ctx,
158156
"""Gets results of a subscription and prints the API response."""
159157
async with CliSession(auth=ctx.obj['AUTH']) as session:
160158
client = SubscriptionsClient(session)
161-
results_aiter = client.get_results_aiter(subscription_id,
162-
status=status,
163-
limit=limit)
164-
async for result in results_aiter:
159+
async for result in client.get_results(subscription_id,
160+
status=status,
161+
limit=limit):
165162
echo_json(result, pretty)

planet/clients/data.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,23 @@ def _searches_url(self):
9393
def _item_url(self, item_type, item_id):
9494
return f'{self._base_url}/item-types/{item_type}/items/{item_id}'
9595

96-
async def search_aiter(self,
97-
item_types: List[str],
98-
search_filter: dict,
99-
name: Optional[str] = None,
100-
sort: Optional[str] = None,
101-
limit: int = 100) -> AsyncIterator[dict]:
96+
async def search(self,
97+
item_types: List[str],
98+
search_filter: dict,
99+
name: Optional[str] = None,
100+
sort: Optional[str] = None,
101+
limit: int = 100) -> AsyncIterator[dict]:
102102
"""Iterate over results from a quick search.
103103
104104
Quick searches are saved for a short period of time (~month). The
105105
`name` parameter of the search defaults to the id of the generated
106106
search id if `name` is not specified.
107107
108+
Note:
109+
The name of this method is based on the API's method name. This
110+
method provides iteration over results, it does not get a
111+
single result description or return a list of descriptions.
112+
108113
Parameters:
109114
item_types: The item types to include in the search.
110115
search_filter: Structured search criteria.
@@ -224,16 +229,16 @@ async def update_search(self,
224229
json=request)
225230
return response.json()
226231

227-
async def list_searches_aiter(self,
228-
sort: str = 'created desc',
229-
search_type: str = 'any',
230-
limit: int = 100) -> AsyncIterator[dict]:
232+
async def list_searches(self,
233+
sort: str = 'created desc',
234+
search_type: str = 'any',
235+
limit: int = 100) -> AsyncIterator[dict]:
231236
"""Iterate through list of searches available to the user.
232237
233-
NOTE: the term 'saved' is overloaded here. We want to list saved
234-
searches that are 'quick' or list saved searches that are 'saved'? Do
235-
we want to introduce a new term, 'stored' that encompasses 'saved' and
236-
'quick' searches?
238+
Note:
239+
The name of this method is based on the API's method name. This
240+
method provides iteration over results, it does not get a
241+
single result description or return a list of descriptions.
237242
238243
Parameters:
239244
sort: Field and direction to order results by.
@@ -295,11 +300,16 @@ async def get_search(self, search_id: str) -> dict:
295300
response = await self._session.request(method='GET', url=url)
296301
return response.json()
297302

298-
async def run_search_aiter(self,
299-
search_id: str,
300-
limit: int = 100) -> AsyncIterator[dict]:
303+
async def run_search(self,
304+
search_id: str,
305+
limit: int = 100) -> AsyncIterator[dict]:
301306
"""Iterate over results from a saved search.
302307
308+
Note:
309+
The name of this method is based on the API's method name. This
310+
method provides iteration over results, it does not get a
311+
single result description or return a list of descriptions.
312+
303313
Parameters:
304314
search_id: Stored search identifier.
305315
limit: Maximum number of results to return. When set to 0, no

planet/clients/orders.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,23 @@ async def wait(self,
463463

464464
return current_state
465465

466-
async def list_orders_aiter(self,
467-
state: Optional[str] = None,
468-
limit: int = 100) -> AsyncIterator[dict]:
466+
async def list_orders(self,
467+
state: Optional[str] = None,
468+
limit: int = 100) -> AsyncIterator[dict]:
469469
"""Iterate over the list of stored order requests.
470470
471+
Note:
472+
The name of this method is based on the API's method name. This
473+
method provides iteration over results, it does not get a
474+
single result description or return a list of descriptions.
475+
471476
Parameters:
472477
state: Filter orders to given state.
473478
limit: Maximum number of results to return. When set to 0, no
474479
maximum is applied.
475480
476-
Returns:
477-
Iterator over user orders that match the query
481+
Yields:
482+
Description of an order.
478483
479484
Raises:
480485
planet.exceptions.APIError: On API error.

planet/clients/subscriptions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ class SubscriptionsClient:
3131
def __init__(self, session: Session) -> None:
3232
self._session = session
3333

34-
async def list_subscriptions_aiter(
35-
self,
36-
status: Optional[Set[str]] = None,
37-
limit: int = 100) -> AsyncIterator[dict]:
34+
async def list_subscriptions(self,
35+
status: Optional[Set[str]] = None,
36+
limit: int = 100) -> AsyncIterator[dict]:
3837
"""Iterate over list of account subscriptions with optional filtering.
3938
4039
Note:
@@ -193,10 +192,10 @@ async def get_subscription(self, subscription_id: str) -> dict:
193192
sub = resp.json()
194193
return sub
195194

196-
async def get_results_aiter(self,
197-
subscription_id: str,
198-
status: Optional[Set[str]] = None,
199-
limit: int = 100) -> AsyncIterator[dict]:
195+
async def get_results(self,
196+
subscription_id: str,
197+
status: Optional[Set[str]] = None,
198+
limit: int = 100) -> AsyncIterator[dict]:
200199
"""Iterate over results of a Subscription.
201200
202201
Note:

0 commit comments

Comments
 (0)