Taxon

class pyinaturalist.models.Taxon(id, uuid, ancestry, ancestor_ids, complete_rank, complete_species_count, ...) None

Bases: BaseModel

An iNaturalist taxon, based on the schema of GET /taxa.

Can be constructed from either a full or partial JSON record. Examples of partial records include nested ancestors, children, and results from get_taxa_autocomplete().

Attributes

Methods

__init__(id, uuid, ancestry, ancestor_ids, complete_rank, complete_species_count, ...) None

Method generated by attrs for class Taxon.

classmethod copy(obj) BaseModel

Copy a model object. This is defined as a classmethod to easily initialize a subclass from a parent class instance. For copying an instance to the same type, copy.deepcopy() can be used.

Return type:

BaseModel

flatten(hide_root) list[Taxon]

Return this taxon and all its descendants as a flat list. Taxon.indent_level is set to indicate the tree depth of each taxon.

Parameters:

hide_root (bool) – Exclude the current taxon from the list if it was automatically inserted by make_tree()

Return type:

list[Taxon]

classmethod from_json(value, **kwargs) T

Initialize a single model object from an API response or response result.

Omits any invalid fields and None values, so default factories are used instead (e.g. for empty dicts and lists).

Return type:

TypeVar(T, bound= BaseModel)

classmethod from_json_file(value) list[T]

Initialize a collection of model objects from a JSON string, file path, or file-like object

Return type:

list[TypeVar(T, bound= BaseModel)]

classmethod from_json_list(value, **kwargs) list[T]

Initialize a collection of model objects from an API response or response results

Return type:

list[TypeVar(T, bound= BaseModel)]

classmethod from_sorted_json_list(value, **kwargs) list[Taxon]

Sort Taxon objects by rank then by name

Return type:

list[Taxon]

to_dict(keys, recurse) dict[str, Any]

Convert this object back to dict format

Parameters:
  • keys (list[str] | None) – Only keep the specified keys (attribute names)

  • recurse (bool) – Recurse into nested model objects

Return type:

dict[str, Any]