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_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) type[BaseModel]

Attempt to determine the model class corresponding to an API result

Return type:

type[BaseModel]

pyinaturalist.formatters.enable_logging(level, external_level)

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) list[BaseModel]

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_table(values) Table | str

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:

Table | str

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

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 (Taxon | LifeList | list[Taxon]) – A single taxon with children, a LifeList, or a list of taxa