Skip to content
2 changes: 1 addition & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Create a search:
bbox=[-72.5,40.5,-72,41])
print(f"{mysearch.matched()} items found")

The ``items()`` generator method can be used to iterate through all resulting items.
The ``items()`` iterator method can be used to iterate through all resulting items.

.. code-block:: python

Expand Down
20 changes: 10 additions & 10 deletions pystac_client/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import lru_cache
from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional
from typing import TYPE_CHECKING, Any, Dict, Iterator, Optional

import pystac
import pystac.validation
Expand Down Expand Up @@ -154,44 +154,44 @@ def get_collection(self, collection_id: str) -> Optional[Collection]:

return None

def get_collections(self) -> Iterable[Collection]:
def get_collections(self) -> Iterator[Collection]:
"""Get Collections in this Catalog

Gets the collections from the /collections endpoint if supported,
otherwise fall back to Catalog behavior of following child links

Return:
Iterable[CollectionClient]: Iterator through Collections in Catalog/API
Iterator[Collection]: Iterator over Collections in Catalog/API
"""
if self._supports_collections() and self.get_self_href() is not None:
url = f"{self.get_self_href()}/collections"
for page in self._stac_io.get_pages(url): # type: ignore
if "collections" not in page:
raise APIError("Invalid response from /collections")
for col in page["collections"]:
collection = CollectionClient.from_dict(col, root=self)
yield collection
yield CollectionClient.from_dict(col, root=self)
else:
yield from super().get_collections()

def get_items(self) -> Iterable["Item_Type"]:
def get_items(self) -> Iterator["Item_Type"]:
"""Return all items of this catalog.

Return:
Iterable[Item]:: Generator of items whose parent is this catalog.
Iterator[Item]:: Iterator of items whose parent is this
catalog.
"""
if self._conforms_to(ConformanceClasses.ITEM_SEARCH):
search = self.search()
yield from search.items()
else:
return super().get_items()
yield from super().get_items()

def get_all_items(self) -> Iterable["Item_Type"]:
def get_all_items(self) -> Iterator["Item_Type"]:
"""Get all items from this catalog and all subcatalogs. Will traverse
any subcatalogs recursively, or use the /search endpoint if supported

Returns:
Iterable[Item]:: All items that belong to this catalog, and all
Iterator[Item]:: All items that belong to this catalog, and all
catalogs or collections connected to this catalog through
child links.
"""
Expand Down
10 changes: 5 additions & 5 deletions pystac_client/collection_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Iterable, Optional, cast
from typing import TYPE_CHECKING, Iterator, Optional, cast

import pystac

Expand All @@ -15,23 +15,23 @@ class CollectionClient(pystac.Collection):
def __repr__(self) -> str:
return "<CollectionClient id={}>".format(self.id)

def get_items(self) -> Iterable["Item_Type"]:
def get_items(self) -> Iterator["Item_Type"]:
"""Return all items in this Collection.

If the Collection contains a link of with a `rel` value of `items`,
that link will be used to iterate through items. Otherwise, the default
PySTAC behavior is assumed.

Return:
Iterable[Item]: Generator of items whose parent is this catalog.
Iterator[Item]: Iterator of items whose parent is this catalog.
"""

link = self.get_single_link("items")
root = self.get_root()
if link is not None and root is not None:
search = ItemSearch(
url=link.href, method="GET", stac_io=root._stac_io
) # type: ignore
url=link.href, method="GET", stac_io=root._stac_io # type: ignore
)
yield from search.items()
else:
yield from super().get_items()
Expand Down
2 changes: 1 addition & 1 deletion pystac_client/stac_api_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def get_pages(
endpoint, e.g., /collections, /search

Return:
Dict : JSON content from a single page
Dict[str, Any] : JSON content from a single page
"""
page = self.read_json(url, method=method, parameters=parameters)
yield page
Expand Down