make_tree

pyinaturalist.models.make_tree(taxa, include_ranks=None, sort_key=None, root_id=None)

Organize a list of taxa into a taxonomic tree, defined by children and ancestors attributes. Expects exactly one root taxon.

Parameters:
  • taxa (Iterable[Taxon]) – Taxon objects to organize

  • sort_key (Optional[Callable[[Taxon], Any]]) – Key function for sorting children; defaults to rank and name

  • include_ranks (Optional[List[str]]) – If provided, only include taxa with these ranks; otherwise, include all ranks

  • root_id (Optional[int]) – ID of the root taxon; if provided, only that taxon and its descendants will be included. Otherwise, the root taxon is determined automatically.

Return type:

Taxon

Returns:

Root taxon of the tree