pyinaturalist.response_format module

Helper functions for formatting API responses

pyinaturalist.response_format.as_geojson_feature(result, properties=None)[source]

Convert an individual response item to a geojson Feature object, optionally with specific response properties included.

Parameters
  • result (Dict[str, Any]) – A single response item

  • properties (Optional[List[str]]) – Whitelist of specific properties to include

Return type

Dict[str, Any]

pyinaturalist.response_format.as_geojson_feature_collection(results, properties=None)[source]

Convert results from an API response into a geojson FeatureCollection object. This is currently only used for observations, but could be used for any other responses with geospatial info.

Parameters
  • results (Iterable[Dict[str, Any]]) – List of results from API response

  • properties (Optional[List[str]]) – Whitelist of specific properties to include

Return type

Dict[str, Any]

pyinaturalist.response_format.convert_float(value)[source]

Convert a value to a float, if valid; return None otherwise

Return type

Optional[float]

Parameters

value (Any) –

pyinaturalist.response_format.convert_lat_long_to_float(results)[source]

Convert coordinate pairs in response items from strings to floats, if valid

Parameters

results (List[Dict[str, Any]]) – Results from API response; expects coordinates in “latitude” and “longitude” keys

Return type

List[Dict[str, Any]]

pyinaturalist.response_format.convert_location_to_float(results)[source]

Convert coordinate pairs in response items from strings to floats, if valid.

Parameters

results (List[Dict[str, Any]]) – Results from API response; expects coordinates in the “location” key

Return type

List[Dict[str, Any]]

pyinaturalist.response_format.flatten_nested_params(observation)[source]
Extract some nested observation properties to include at the top level;

this makes it easier to specify these as properties for as_as_geojson_feature_collection().

Parameters

observation (Dict[str, Any]) – A single observation result

Return type

Dict[str, Any]

pyinaturalist.response_format.format_taxon(taxon)[source]

Format a taxon result into a single string containing taxon ID, rank, and name (including common name, if available).

Return type

str

Parameters

taxon (Dict) –