Formatters#

Summary#

Classes

Functions

detect_type(value)

Attempt to determine the model class corresponding to an API result

enable_logging([level, external_level])

Configure logging to standard output with prettier tracebacks, formatting, and terminal colors (if supported).

ensure_model_list(values)

If the given values are raw JSON responses, attempt to detect their type and convert to model objects

format_request(request[, dry_run])

Format HTTP request info

format_response(response)

Format HTTP response info, including whether it came from the cache

format_table(values)

Format model objects as a table.

format_tree(taxon, **kwargs)

Format a taxon and its descendants as a tree

pprint(values)

Pretty-print any model object or list into a condensed summary.

pprint_tree(taxa, **kwargs)

Pretty-print a taxon and its descendants as a tree.

Module Contents#

Utilities for formatting API responses and model objects, for convenience/readability when exploring data. Not used directly by API functions.

These functions will accept any of the following:

  • A JSON response

  • A list of response objects

  • A single response object

pyinaturalist.formatters.detect_type(value)#

Attempt to determine the model class corresponding to an API result

Return type:

Type[BaseModel]

pyinaturalist.formatters.enable_logging(level='INFO', external_level='WARNING')#

Configure logging to standard output with prettier tracebacks, formatting, and terminal colors (if supported).

If you prefer, logging can be configured with the stdlib logging module instead; this just provides some convenient defaults.

Parameters:
  • level (str) – Logging level to use for pyinaturalist

  • external_level (str) – Logging level to use for other libraries

pyinaturalist.formatters.ensure_model_list(values)#

If the given values are raw JSON responses, attempt to detect their type and convert to model objects

Return type:

List[BaseModel]

pyinaturalist.formatters.format_request(request, dry_run=False)#

Format HTTP request info

Return type:

str

pyinaturalist.formatters.format_response(response)#

Format HTTP response info, including whether it came from the cache

Return type:

str

pyinaturalist.formatters.format_table(values)#

Format model objects as a table.

If the model doesn’t have a table format defined, return a basic list of stringified objects.

Return type:

Union[Table, str]

pyinaturalist.formatters.format_tree(taxon, **kwargs)#

Format a taxon and its descendants as a tree

Return type:

Tree

pyinaturalist.formatters.pprint(values)#

Pretty-print any model object or list into a condensed summary.

Experimental: May also be used on most raw JSON API responses

pyinaturalist.formatters.pprint_tree(taxa, **kwargs)#

Pretty-print a taxon and its descendants as a tree.

Parameters:

taxa (Union[Taxon, LifeList, List[Taxon]]) – A single taxon with children, a LifeList, or a list of taxa