Request Params¶
Summary¶
Classes
Functions
|
Convert any boolean request parameters to javascript-style boolean strings |
|
Convert any dates, datetimes, or timestamps in other formats into ISO 8601 strings. |
|
Convert any list parameters into an API-compatible (comma-delimited) string. |
Convert observation field filters from simplified format to full request params |
|
|
Some common parameter conversions needed by observation CRUD endpoints |
|
Some common parameter conversions needed by observation CRUD endpoints; same as convert_observation_params but splits out observation field values. |
|
Translate simplified format of observation field values into API-compatible format. |
|
Allow |
|
If min and/or max rank is specified in params, translate into a list of ranks |
|
If one or more resources are requested by ID, validate and update the request URL accordingly |
|
Given a date range and a time interval, split the range into a list of smaller ranges |
|
Get the subset of non-None |
|
Normalize and validate a taxonomic rank, alias, or abbreviation |
|
Normalize any taxonomic ranks in request params |
|
Perform type conversions, sanity checks, etc. |
|
Perform type conversions, sanity checks, etc. |
|
Split out common keyword args (for pyinaturalist functions) from request params (for API) |
|
Remove any dict items with empty or |
|
Verify that a multiple-choice request parameter contains valid value(s); if not, raise an error. |
|
Verify that multiple-choice request parameters contain a valid value. |
Module Contents¶
Helper functions for processing and validating request parameters. The main purpose of these functions is to support some python-specific conveniences and translate them into standard API request parameters, along with client-side request validation.
Also see pyinaturalist.converters for type conversion utilities not specific to request
params.
- pyinaturalist.request_params.convert_bool_params(params) dict[str, Any]¶
Convert any boolean request parameters to javascript-style boolean strings
- pyinaturalist.request_params.convert_datetime_params(params) dict[str, Any]¶
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
- pyinaturalist.request_params.convert_list_params(params) dict[str, Any]¶
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
- pyinaturalist.request_params.convert_observation_field_filters(params) dict[str, Any]¶
Convert observation field filters from simplified format to full request params
- pyinaturalist.request_params.convert_observation_params(params) tuple[list, list, list, dict[str, Any], dict[str, Any]]¶
Some common parameter conversions needed by observation CRUD endpoints
- pyinaturalist.request_params.convert_observation_params_v2(params) tuple[list, list, list, list, dict[str, Any], dict[str, Any]]¶
Some common parameter conversions needed by observation CRUD endpoints; same as convert_observation_params but splits out observation field values.
- pyinaturalist.request_params.convert_ofv_params(params) list[dict]¶
Translate simplified format of observation field values into API-compatible format. Also handles an already API-compatible format.
- pyinaturalist.request_params.convert_pagination_params(params) dict[str, Any]¶
Allow
count_only=Trueas a slightly more intuitive shortcut to only get a count of results
- pyinaturalist.request_params.convert_rank_range(params) dict[str, Any]¶
If min and/or max rank is specified in params, translate into a list of ranks
- pyinaturalist.request_params.convert_url_ids(url, ids, allow_str_ids) str¶
If one or more resources are requested by ID, validate and update the request URL accordingly
- Return type:
- pyinaturalist.request_params.get_interval_ranges(start, end, interval) list[tuple[date | datetime, date | datetime]]¶
Given a date range and a time interval, split the range into a list of smaller ranges
- Parameters:
- Returns:
[(start_date, end_date), ...]- Return type:
List of date ranges of size
interval, in the format
- pyinaturalist.request_params.get_valid_kwargs(func, kwargs) dict¶
Get the subset of non-None
kwargsthat are valid params forfunc- Return type:
- pyinaturalist.request_params.normalize_rank(rank) str¶
Normalize and validate a taxonomic rank, alias, or abbreviation
- Return type:
- pyinaturalist.request_params.normalize_rank_params(params) dict[str, Any]¶
Normalize any taxonomic ranks in request params
- pyinaturalist.request_params.preprocess_request_body(body) dict[str, Any] | None¶
Perform type conversions, sanity checks, etc. on JSON-formatted request body
- pyinaturalist.request_params.preprocess_request_params(params, convert_lists) dict[str, Any]¶
Perform type conversions, sanity checks, etc. on request parameters
- pyinaturalist.request_params.split_common_params(params) tuple[dict[str, Any], dict[str, Any]]¶
Split out common keyword args (for pyinaturalist functions) from request params (for API)
- pyinaturalist.request_params.strip_empty_values(values) dict¶
Remove any dict items with empty or
Nonevalues. Observation field filters are an exception (e.g.field:foo=).- Return type:
- pyinaturalist.request_params.validate_multiple_choice_param(params, key, choices) dict[str, Any]¶
Verify that a multiple-choice request parameter contains valid value(s); if not, raise an error. Used for endpoint-specific params.
- Return type:
- Returns:
Parameters with modifications (if any)
- Raises:
- pyinaturalist.request_params.validate_multiple_choice_params(params) dict[str, Any]¶
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.
- Return type:
- Returns:
Parameters with modifications (if any)
- Raises:
ValueError – Error message will contain info on all validation errors, if there are multiple