pyinaturalist.request_params¶
Summary¶
|
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. |
|
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 |
|
Get a list of date ranges between |
|
Determine if a value contains one or more valid integers |
|
Translate some |
|
Perform type conversions, sanity checks, etc. |
|
Perform type conversions, sanity checks, etc. |
|
Ensure ID(s) are all valid integers, and convert to a comma-delimited string if multiple |
|
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. |
Details¶
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 request parameters, along with request validation that makes debugging easier.
- pyinaturalist.request_params.convert_bool_params(params)¶
Convert any boolean request parameters to javascript-style boolean strings
- pyinaturalist.request_params.convert_datetime_params(params)¶
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)¶
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_fields(params)¶
Translate simplified format of observation field values into API-compatible format
- pyinaturalist.request_params.convert_pagination_params(params)¶
Allow
count_only=True
as a slightly more intuitive shortcut to only get a count of results
- pyinaturalist.request_params.convert_rank_range(params)¶
If min and/or max rank is specified in params, translate into a list of ranks
- pyinaturalist.request_params.get_interval_ranges(start_date, end_date, interval='monthly')¶
Get a list of date ranges between
start_date
andend_date
with the specified interval .. rubric:: Example>>> # Get date ranges representing months of a year >>> get_interval_ranges(datetime(2020, 1, 1), datetime(2020, 12, 31), 'monthly')
- pyinaturalist.request_params.is_int_list(values)¶
Determine if a value contains one or more valid integers
- Return type
- pyinaturalist.request_params.prepare_request(url, access_token=None, user_agent=None, ids=None, params=None, headers=None, json=None)¶
Translate some
pyinaturalist
-specific params into standard params and headers, and other request param preprocessing. This is made non-requests
-specific so it could potentially be reused foraiohttp
requests.
- pyinaturalist.request_params.preprocess_request_body(body)¶
Perform type conversions, sanity checks, etc. on JSON-formatted request body
- pyinaturalist.request_params.preprocess_request_params(params)¶
Perform type conversions, sanity checks, etc. on request parameters
- pyinaturalist.request_params.validate_ids(ids)¶
Ensure ID(s) are all valid integers, and convert to a comma-delimited string if multiple
- Raises
- Return type
- pyinaturalist.request_params.validate_multiple_choice_param(params, key, choices)¶
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)¶
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