pyinaturalist.request_params module¶
Helper functions for processing and validating request parameters
-
pyinaturalist.request_params.
check_deprecated_params
(params=None, **kwargs)[source]¶ Check for usage of request parameters that are deprecated but still supported for backwards-compatibility
- Return type
Dict
[str
,Any
]
-
pyinaturalist.request_params.
convert_bool_params
(params)[source]¶ Convert any boolean request parameters to javascript-style boolean strings
- Return type
Dict
[str
,Any
]- Parameters
params (Dict[str, Any]) –
-
pyinaturalist.request_params.
convert_datetime_params
(params)[source]¶ Convert any dates, datetimes, or timestamps in other formats into ISO 8601 strings.
API behavior note: params that take date but not time info will accept a full timestamp and just ignore the time, so it’s safe to parse both date and datetime strings into timestamps
- Raises
dateutil.parser._parser.ParserError –
- Return type
Dict
[str
,Any
]- Parameters
params (Dict[str, Any]) –
-
pyinaturalist.request_params.
convert_list
(obj)[source]¶ Convert list parameters into an API-compatible (comma-delimited) string
- Return type
str
- Parameters
obj (Any) –
-
pyinaturalist.request_params.
convert_list_params
(params)[source]¶ Convert any list parameters into an API-compatible (comma-delimited) string. Will be url-encoded by requests. For example: [‘k1’, ‘k2’, ‘k3’] -> k1%2Ck2%2Ck3
- Return type
Dict
[str
,Any
]- Parameters
params (Dict[str, Any]) –
-
pyinaturalist.request_params.
convert_observation_fields
(params)[source]¶ Translate simplified format of observation field values into API-compatible format
- Return type
Dict
[str
,Any
]- Parameters
params (Dict[str, Any]) –
-
pyinaturalist.request_params.
ensure_file_obj
(photo)[source]¶ Given a file objects or path, read it into a file-like object if it’s a path
- Return type
BinaryIO
- Parameters
photo (Union[BinaryIO, str]) –
-
pyinaturalist.request_params.
ensure_file_objs
(photos)[source]¶ Given one or more file objects and/or paths, read any paths into a file-like object
- Return type
Iterable
[BinaryIO
]- Parameters
photos (Iterable[Union[BinaryIO, str]]) –
-
pyinaturalist.request_params.
ensure_list
(values)[source]¶ If the value is a string or comma-separated list of values, convert it into a list
- Parameters
values (Any) –
-
pyinaturalist.request_params.
is_int
(value)[source]¶ Determine if a value is a valid integer
- Return type
bool
- Parameters
value (Any) –
-
pyinaturalist.request_params.
is_int_list
(values)[source]¶ Determine if a value contains one or more valid integers
- Return type
bool
- Parameters
values (Any) –
-
pyinaturalist.request_params.
is_valid_multiple_choice_option
(value, choices)[source]¶ Determine if a multiple-choice request parameter contains valid value(s).
- Return type
bool
- Parameters
value (Any) –
choices (Iterable) –
-
pyinaturalist.request_params.
preprocess_request_params
(params)[source]¶ Perform type conversions, sanity checks, etc. on request parameters
- Return type
Dict
[str
,Any
]- Parameters
params (Optional[Dict[str, Any]]) –
-
pyinaturalist.request_params.
strip_empty_params
(params)[source]¶ Remove any request parameters with empty or
None
values.- Return type
Dict
[str
,Any
]- Parameters
params (Dict[str, Any]) –
-
pyinaturalist.request_params.
translate_rank_range
(params)[source]¶ If min and/or max rank is specified in params, translate into a list of ranks
- Return type
Dict
[str
,Any
]- Parameters
params (Dict[str, Any]) –
-
pyinaturalist.request_params.
validate_ids
(ids)[source]¶ Ensure ID(s) are all valid integers, and convert to a comma-delimited string if multiple
- Raises
ValueError –
- Return type
str
- Parameters
ids (Any) –
-
pyinaturalist.request_params.
validate_multiple_choice_param
(params, key, choices)[source]¶ Verify if a multiple-choice request parameter contains valid value(s); if not, raise an error. Used for endpoint-specific params.
- Raises
ValueError –
- Parameters
params (Dict[str, Any]) –
key (str) –
choices (Iterable) –
-
pyinaturalist.request_params.
validate_multiple_choice_params
(params)[source]¶ Verify that multiple-choice request parameters contain a valid value.
Note: This does not check endpoint-specific params, i.e., those that have the same name but different values across different endpoints.
- Raises
ValueError – Error message will contain info on all validation errors, if there are multiple
- Parameters
params (Dict[str, Any]) –