BaseModelCollection¶
- class pyinaturalist.models.BaseModelCollection(id=None, uuid=None)¶
Bases:
BaseModel
,UserList
,Generic
[T
]Base class for data model collections. These will behave the same as lists but enable some additional operations on contained items.
Attributes
Name
Type
Description
id
Unique record ID
uuid
Unversally unique record ID
data
id_map (
property
)A mapping of objects by unique identifier
Methods
- __init__(id=None, uuid=None)¶
Method generated by attrs for class BaseModelCollection.
- append(item)¶
S.append(value) – append value to the end of the sequence
- clear() None -- remove all items from S ¶
- classmethod copy(obj)¶
Copy a model collection
- count(value) integer -- return number of occurrences of value ¶
- deduplicate()¶
Remove any duplicates from this collection based on ID
- extend(other)¶
S.extend(iterable) – extend sequence by appending elements from the iterable
- classmethod from_json(value, **kwargs)¶
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
(TC
, bound= BaseModelCollection)
- classmethod from_json_file(value)¶
Initialize a collection of model objects from a JSON string, file path, or file-like object
- classmethod from_json_list(value, **kwargs)¶
For model collections, initializing from a list should return an instance of
cls
instead of a builtinlist
- Return type:
TypeVar
(TC
, bound= BaseModelCollection)
- get_count(id, count_field='count')¶
Get a count associated with the given ID. Returns 0 if the collection type is not countable or the ID doesn’t exist.
- Return type:
- index(value[, start[, stop]]) integer -- return first index of value. ¶
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- insert(i, item)¶
S.insert(index, value) – insert value before index
- pop([index]) item -- remove and return item at index (default last). ¶
Raise IndexError if list is empty or index is out of range.
- remove(item)¶
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- reverse()¶
S.reverse() – reverse IN PLACE
- sort(*args, **kwds)¶