CARTO Authentication object used to gather connect with the CARTO services.
Args:
mode
(str): Type of authentication: oauth, m2m.api_base_url
(str, optional): Base URL for a CARTO account.access_token
(str, optional): Token already generated with CARTO.expiration
(int, optional): Time in seconds when the token will be expired.client_id
(str, optional): Client id of a M2M application provided by CARTO.client_secret
(str, optional): Client secret of a M2M application provided by CARTO.cache_filepath
(str, optional): File path where the token is stored. Default "home()/.carto-auth/token.json".use_cache
(bool, optional): Whether the stored cached token should be used. Default True.open_browser
(bool, optional): Whether the web browser should be opened to authorize a user. Default True.
__init__(
mode,
api_base_url=None,
access_token=None,
expiration=None,
client_id=None,
client_secret=None,
cache_filepath=None,
use_cache=True,
open_browser=True
)
from_m2m(filepath, cache_filepath=None, use_cache=True)
Create a CartoAuth object using CARTO credentials file.
Args:
filepath
(str): File path of the CARTO credentials file.cache_filepath
(str, optional): File path where the token is stored. Default "home()/.carto-auth/token_m2m.json".use_cache
(bool, optional): Whether the stored cached token should be used. Default True.
Raises:
AttributeError
: If the CARTO credentials file does not contain the attributes "api_base_url", "client_id", "client_secret".ValueError
: If the CARTO credentials file does not contain any attribute value.
from_oauth(cache_filepath=None, use_cache=True, open_browser=True)
Create a CartoAuth object using OAuth with CARTO.
Args:
cache_filepath
(str, optional): File path where the token is stored. Default "home()/.carto-auth/token_oauth.json".use_cache
(bool, optional): Whether the stored cached token should be used. Default True.open_browser
(bool, optional): Whether the web browser should be opened to authorize a user. Default True.
get_access_token()
get_api_base_url()
get_carto_dw_client()
Returns a client to query directly the CARTO Data Warehouse.
It requires extra dependencies carto-auth[carto-dw] to be installed.
get_carto_dw_credentials() → tuple
Get the CARTO Data Warehouse credentials.
Returns:
tuple
: carto_dw_project, carto_dw_token.
Raises:
CredentialsError
: If the API Base URL is not provided, the response is not JSON or has invalid attributes.