pyinaturalist.auth module¶
- pyinaturalist.auth.get_access_token(username=None, password=None, app_id=None, app_secret=None, user_agent=None)[source]¶
Get an access token using the user’s iNaturalist username and password. You still need an iNaturalist app to do this.
API reference: https://www.inaturalist.org/pages/api+reference#auth
See Authentication for additional options for storing credentials.
Examples
With direct keyword arguments:
>>> from pyinaturalist.auth import get_access_token >>> access_token = get_access_token( >>> username='my_username', >>> password='my_password', >>> app_id='33f27dc63bdf27f4ca6cd95dd9dcd5df', >>> app_secret='bbce628be722bfe2abd5fc566ba83de4', >>> )
With environment variables or keyring configured:
>>> access_token = get_access_token()
If you would like to run custom requests for endpoints not yet implemented in pyinaturalist, you can authenticate these requests by putting the token in your HTTP headers as follows:
>>> import requests >>> requests.get( >>> 'https://www.inaturalist.org/observations/1234', >>> headers={'Authorization': f'Bearer {access_token}'}, >>> )
- Parameters
username (
Optional
[str
]) – iNaturalist usernamepassword (
Optional
[str
]) – iNaturalist passwordapp_id (
Optional
[str
]) – iNaturalist application IDapp_secret (
Optional
[str
]) – iNaturalist application secretuser_agent (
Optional
[str
]) – a user-agent string that will be passed to iNaturalist.
- Raises
- Return type
str
- pyinaturalist.auth.get_keyring_credentials()[source]¶
Attempt to get iNaturalist credentials from the system keyring
- Return type
Dict
[str
,Optional
[str
]]- Returns
OAuth-compatible credentials dict
- pyinaturalist.auth.set_keyring_credentials(username, password, app_id, app_secret)[source]¶
Store iNaturalist credentials in the system keyring for future use.
- Parameters
username (
str
) – iNaturalist usernamepassword (
str
) – iNaturalist passwordapp_id (
str
) – iNaturalist application IDapp_secret (
str
) – iNaturalist application secret