Converters¶
Summary¶
Classes
Functions
|
Convert coordinate pairs in response items from strings to floats, if valid |
|
Convert locations for both standard and community-contributed places to floats |
|
Replace all date/time info with datetime objects, where possible |
|
Replace generic created/updated info that's returned by multiple endpoints. |
|
Convert histogram keys (bin labels) to the appropriate type depending on interval |
|
Convert a date, datetime, or timestamps to a string in ISO 8601 format. |
|
Convert a coordinate pair as a dict, list, or string into a pair of floats, if valid |
|
Convert a coordinate pair dict within a response to floats, if valid |
|
Convert a coordinate pairs in a response item from strings to floats, if valid |
|
Replace observation date/time info with datetime objects |
|
Load data into a file-like object, if it isn't already. |
|
Convert an object, response, or (optionally) comma-separated string into a list |
|
Simplify a 'dimensions' dict into a |
|
Convert a file size in bytes into a human-readable format |
|
Format a Creative Commons license code |
|
Get the histogram interval from the result keys. |
|
Split a pipe-(or other token)-delimited string |
|
Parse a date string into a date, if valid; return |
|
Parse a date/time string into a datetime, if valid; return |
|
Convert a value to a float, if valid; return |
|
Convert a pair of coordinate values to floats, if both are valid; return |
|
Convert a value to a int, if valid; return |
|
Convert a value to either an int or a float, if valid; return |
Module Contents¶
Type conversion utilities used for both requests and responses
- pyinaturalist.converters.convert_all_coordinates(results) List[Dict[str, Any]]¶
Convert coordinate pairs in response items from strings to floats, if valid
- pyinaturalist.converters.convert_all_place_coordinates(response) Dict[str, Any]¶
Convert locations for both standard and community-contributed places to floats
- pyinaturalist.converters.convert_all_timestamps(results) List[Dict[str, Any]]¶
Replace all date/time info with datetime objects, where possible
- pyinaturalist.converters.convert_generic_timestamps(result) Dict[str, Any]¶
Replace generic created/updated info that’s returned by multiple endpoints. Note: Compared to observation timestamps, these are generally more reliable. These seem to be consistently in ISO 8601 format.
- pyinaturalist.converters.convert_histogram(result) Dict[date | datetime | int, int]¶
Convert histogram keys (bin labels) to the appropriate type depending on interval
- pyinaturalist.converters.convert_isoformat(value) str¶
Convert a date, datetime, or timestamps to a string in ISO 8601 format. If it’s a datetime and doesn’t already have tzinfo, set it to the system’s local timezone.
- Raises:
dateutil.parser._parser.ParserError –
- Return type:
- pyinaturalist.converters.convert_lat_long(obj) Tuple[float, float] | None¶
Convert a coordinate pair as a dict, list, or string into a pair of floats, if valid
- pyinaturalist.converters.convert_lat_long_dict(result) Dict[str, Any]¶
Convert a coordinate pair dict within a response to floats, if valid
- pyinaturalist.converters.convert_lat_long_list(result)¶
Convert a coordinate pairs in a response item from strings to floats, if valid
- pyinaturalist.converters.convert_observation_timestamps(result) Dict[str, Any]¶
Replace observation date/time info with datetime objects
- pyinaturalist.converters.ensure_file_obj(value, session=None) IO¶
Load data into a file-like object, if it isn’t already. Accepts local file paths and URLs.
- Return type:
- pyinaturalist.converters.ensure_list(value, split_str_list=False, delimiter=',') MutableSequence[Any]¶
Convert an object, response, or (optionally) comma-separated string into a list
- Return type:
- pyinaturalist.converters.format_dimensions(dimensions) Tuple[int, int]¶
Simplify a ‘dimensions’ dict into a
(width, height)tuple
- pyinaturalist.converters.format_file_size(n_bytes) str¶
Convert a file size in bytes into a human-readable format
- Return type:
- pyinaturalist.converters.get_histogram_interval(result) str¶
Get the histogram interval from the result keys.
The key containing histogram data will be the name of the interval requested example:
{'month_of_year': {'1': 5, ...}}- Return type:
- pyinaturalist.converters.safe_split(value, delimiter='|') List[str]¶
Split a pipe-(or other token)-delimited string
- pyinaturalist.converters.try_date(timestamp, **kwargs) date | None¶
Parse a date string into a date, if valid; return
Noneotherwise
- pyinaturalist.converters.try_datetime(timestamp, **kwargs) datetime | None¶
Parse a date/time string into a datetime, if valid; return
Noneotherwise
- pyinaturalist.converters.try_float(value) float | None¶
Convert a value to a float, if valid; return
Noneotherwise
- pyinaturalist.converters.try_float_pair(*values) Tuple[float, float] | None¶
Convert a pair of coordinate values to floats, if both are valid; return
Noneotherwise