API Reference

This section is autogenerated from in-line code documentation. It is mostly useful as a reference for the various classes, methods, and other objects in the library, but is not intended to function as a starting point for working with pystac_client.

Client

Client is the base PySTAC-Client that inherits from Catalog. In addition to the PySTAC functionality, Client allows opening of API URLs, understanding of conformance, and support for searching and paging through results.

class pystac_client.Client(id, description, title=None, stac_extensions=None, extra_fields=None, href=None, catalog_type=CatalogType.ABSOLUTE_PUBLISHED)[source]

Bases: pystac.catalog.Catalog

A Client for interacting with the root of a STAC Catalog or API

Instances of the Client class inherit from pystac.Catalog and provide a convenient way of interacting with STAC Catalogs OR STAC APIs that conform to the STAC API spec. In addition to being a valid STAC Catalog APIs that have a "conformsTo" indicate that it supports additional functionality on top of a normal STAC Catalog, such as searching items (e.g., /search endpoint).

catalog_type

The catalog type. Defaults to CatalogType.ABSOLUTE_PUBLISHED.

description

Detailed multi-line description to fully explain the catalog.

extra_fields

Extra fields that are part of the top-level JSON properties of the Catalog.

classmethod from_file(href, stac_io=None, headers={}, parameters=None)[source]

Open a STAC Catalog/API

Returns

A Client (PySTAC Catalog) of the root Catalog for this Catalog/API

Return type

Client

get_all_items()[source]

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

catalogs or collections connected to this catalog through child links.

get_collection(collection_id)[source]

Get a single collection from this Catalog/API

Parameters

collection_id – The Collection ID to get

Returns

A STAC Collection

Return type

CollectionClient

get_collections()[source]

Get Collections in this Catalog

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

Returns

Iterator through Collections in Catalog/API

Return type

Iterable[CollectionClient]

get_items()[source]

Return all items of this catalog.

Returns

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

Returns this client’s search link.

Searches for a link with rel=”search” and either a GEOJSON or JSON media type.

Returns

The search link, or None if there is not one found.

Return type

Optional[pystac.Link]

id

Identifier for the catalog.

A list of Link objects representing all links associated with this Catalog.

classmethod open(url, headers=None, parameters=None, ignore_conformance=False)[source]

Opens a STAC Catalog or API This function will read the root catalog of a STAC Catalog or API

Parameters
  • url – The URL of a STAC Catalog. If not specified, this will use the STAC_URL environment variable.

  • headers – A dictionary of additional headers to use in all requests made to any part of this Catalog/API.

  • ignore_conformance – Ignore any advertised Conformance Classes in this Catalog/API. This means that functions will skip checking conformance, and may throw an unknown error if that feature is not supported, rather than a NotImplementedError.

Returns

A Client instance for this Catalog/API

Return type

catalog

search(**kwargs)[source]

Query the /search endpoint using the given parameters.

This method returns an ItemSearch instance, see that class’s documentation for details on how to get the number of matches and iterate over results. All keyword arguments are passed directly to the ItemSearch instance.

Warning

This method is only implemented if the API conforms to the STAC API - Item Search spec and contains a link with a "rel" type of "search" in its root catalog. If the API does not meet either of these criteria, this method will raise a NotImplementedError.

Parameters

**kwargs – Any parameter to the ItemSearch class, other than url, conformance, and stac_io which are set from this Client instance

Returns

An ItemSearch instance that can be used to iterate through Items.

Return type

search

Raises

NotImplementedError – If the API does not conform to the Item Search spec or does not have a link with a "rel" type of "search".

stac_extensions

List of extensions the Catalog implements.

title

Optional short descriptive one-line title for the catalog.

Collection Client

Client is the a PySTAC-Client that inherits from Collection. In addition to the PySTAC functionality, CollectionClient allows opening of API URLs, and iterating through items at a search endpoint, if supported.

class pystac_client.CollectionClient(id, description, extent, title=None, stac_extensions=None, href=None, extra_fields=None, catalog_type=None, license='proprietary', keywords=None, providers=None, summaries=None)[source]
assets

Map of Assets

description

Detailed multi-line description to fully explain the collection.

extent

Spatial and temporal extents that describe the bounds of all items contained within this Collection.

extra_fields

Extra fields that are part of the top-level JSON properties of the Collection.

get_items()[source]

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.

Returns

Generator of items whose parent is this catalog.

Return type

Iterable[Item]

id

Identifier for the collection.

keywords

Optional list of keywords describing the collection.

A list of Link objects representing all links associated with this Collection.

providers

Optional list of providers of this Collection.

stac_extensions

List of extensions the Collection implements.

summaries

A map of property summaries, either a set of values or statistics such as a range.

title

Optional short descriptive one-line title for the collection.

STAC API IO

The StacApiIO class inherits from the Collection class and allows for reading over http, such as with REST APIs.

class pystac_client.stac_api_io.StacApiIO(headers=None, conformance=None, parameters=None)[source]

Bases: pystac.stac_io.DefaultStacIO

assert_conforms_to(conformance_class)[source]

Raises a NotImplementedError if the API does not publish the given conformance class. This method only checks against the "conformsTo" property from the API landing page and does not make any additional calls to a /conformance endpoint even if the API provides such an endpoint.

Parameters

conformance_class – The ConformanceClasses key to check conformance against.

conforms_to(conformance_class)[source]

Whether the API conforms to the given standard. This method only checks against the "conformsTo" property from the API landing page and does not make any additional calls to a /conformance endpoint even if the API provides such an endpoint.

Parameters

key – The ConformanceClasses key to check conformance against.

Returns

Indicates if the API conforms to the given spec or URI.

Return type

bool

get_pages(url, method='GET', parameters={})[source]

Iterator that yields dictionaries for each page at a STAC paging endpoint, e.g., /collections, /search

Returns

JSON content from a single page

Return type

Dict

read_text(source, *args, parameters={}, **kwargs)[source]

Read text from the given URI.

Overwrites the default method for reading text from a URL or file to allow urllib.request.Request instances as input. This method also raises any urllib.error.HTTPError exceptions rather than catching them to allow us to handle different response status codes as needed.

request(href, method='GET', headers={}, parameters={})[source]

Makes a request to an http endpoint

Parameters
  • href (str) – The request URL

  • method (Optional[str], optional) – The http method to use, ‘GET’ or ‘POST’. Defaults to ‘GET’.

  • headers (Optional[dict], optional) – Additional headers to include in request. Defaults to {}.

  • parameters (Optional[dict], optional) – parameters to send with request. Defaults to {}.

Raises

APIError – raised if the server returns an error response

Returns

The decoded response from the endpoint

Return type

str

set_conformance(conformance)[source]

Sets (or clears) the conformances for this StacIO.

stac_object_from_dict(d, href=None, root=None, preserve_dict=True)[source]

Deserializes a STACObject sub-class instance from a dictionary.

Parameters
  • d – The dictionary to deserialize

  • href – Optional href to associate with the STAC object

  • root – Optional root Catalog to associate with the STAC object.

  • preserve_dict – If False, the dict parameter d may be modified during this method call. Otherwise the dict is not mutated. Defaults to True, which results results in a deepcopy of the parameter. Set to False when possible to avoid the performance hit of a deepcopy.

write_text_to_href(href, *args, **kwargs)[source]

Writes text to file using UTF-8 encoding.

This implementation uses open() and therefore can only write to the local file system.

Parameters
  • href – The path to which the file will be written.

  • txt – The string content to write to the file.

Conformance

class pystac_client.conformance.ConformanceClasses(value)[source]

Bases: enum.Enum

Enumeration class for Conformance Classes

COLLECTIONS = 'http://www\\.opengis\\.net/spec/ogcapi\\-features\\-1/1\\.0/conf/oas30'
CONTEXT = 'https://api\\.stacspec\\.org/v1\\.0\\.(.*)/item\\-search\\#context'
CORE = 'https://api\\.stacspec\\.org/v1\\.0\\.(.*)/core'
FIELDS = 'https://api\\.stacspec\\.org/v1\\.0\\.(.*)/item\\-search\\#fields'
FILTER = 'https://api\\.stacspec\\.org/v1\\.0\\.(.*)/item\\-search\\#filter'
QUERY = 'https://api\\.stacspec\\.org/v1\\.0\\.(.*)/item\\-search\\#query'
SORT = 'https://api\\.stacspec\\.org/v1\\.0\\.(.*)/item\\-search\\#sort'
stac_prefix = 'https://api\\.stacspec\\.org/v1\\.0\\.'

Exceptions

exception pystac_client.exceptions.APIError[source]

Bases: Exception

Raised when unexpected server error.

exception pystac_client.exceptions.ParametersError[source]

Bases: Exception

Raised when invalid parameters are used in a query