pyinaturalist.api_requests¶
Summary¶
|
Wrapper around |
|
Translate an environment variable to a boolean value, accounting for minor variations (case, None vs. |
|
Wrapper around |
Get a rate limiter object, if pyrate-limiter is installed |
|
Get a Session object that will be reused across requests to take advantage of connection pooling. |
|
|
A wrapper to determine if dry-run (aka test mode) has been enabled via either a constant or an environment variable. |
|
Log all relevant information about an HTTP request |
|
Wrapper around |
|
Wrapper around |
|
Add delays in between requests to stay within the rate limits. |
|
Wrapper around |
Details¶
Some common functions for HTTP requests used by all API modules
- pyinaturalist.api_requests.delete(url, **kwargs)¶
Wrapper around
requests.delete()
that supports dry-run mode and rate-limiting- Return type
- pyinaturalist.api_requests.env_to_bool(environment_variable)¶
Translate an environment variable to a boolean value, accounting for minor variations (case, None vs. False, etc.)
- Return type
- pyinaturalist.api_requests.get(url, **kwargs)¶
Wrapper around
requests.get()
that supports dry-run mode and rate-limiting- Return type
- pyinaturalist.api_requests.get_limiter()¶
Get a rate limiter object, if pyrate-limiter is installed
- pyinaturalist.api_requests.get_session()¶
Get a Session object that will be reused across requests to take advantage of connection pooling. This is especially relevant for large paginated requests. If used in a multi-threaded context (for example, a
ThreadPoolExecutor
), a separate session is used for each thread.- Return type
- pyinaturalist.api_requests.is_dry_run_enabled(method)¶
A wrapper to determine if dry-run (aka test mode) has been enabled via either a constant or an environment variable. Dry-run mode may be enabled for either write requests, or all requests.
- Return type
- pyinaturalist.api_requests.log_request(*args, **kwargs)¶
Log all relevant information about an HTTP request
- pyinaturalist.api_requests.post(url, **kwargs)¶
Wrapper around
requests.post()
that supports dry-run mode and rate-limiting- Return type
- pyinaturalist.api_requests.put(url, **kwargs)¶
Wrapper around
requests.put()
that supports dry-run mode and rate-limiting- Return type
- pyinaturalist.api_requests.ratelimit(bucket='pyinaturalist/0.14.0')¶
Add delays in between requests to stay within the rate limits. If pyrate-limiter is not installed, this will quietly do nothing.
- pyinaturalist.api_requests.request(method, url, access_token=None, user_agent=None, ids=None, headers=None, json=None, session=None, raise_for_status=True, timeout=5, **params)¶
Wrapper around
requests.request()
that supports dry-run mode and rate-limiting, and adds appropriate headers.- Parameters
method (
str
) – HTTP methodurl (
str
) – Request URLaccess_token (
Optional
[str
]) – access_token: the access token, as returned byget_access_token()
user_agent (
Optional
[str
]) – A custom user-agent string to provide to the iNaturalist APIids (
Union
[int
,Iterable
[int
],None
]) – One or more integer IDs used as REST resource(s) to requestsession (
Optional
[Session
]) – Existing Session object to use instead of creating a new onetimeout (
float
) – Time (in seconds) to wait for a response from the server; if exceeded, arequests.exceptions.Timeout
will be raised.params (
Dict
[str
,Any
]) – All other keyword arguments are interpreted as request parameters
- Return type
- Returns
API response