def __init__(self, api_key=None, return_type='snake', retry_total=6, api_version="1.0", resources="all", local_api_spec=None): if return_type not in ['snake', 'raw', 'pandas']: raise ValueError("Return type must be one of 'snake', 'raw', " "'pandas'") self._feature_flags = () session_auth_key = get_api_key(api_key) self._session_kwargs = {'api_key': session_auth_key, 'max_retries': retry_total} self.last_response = None # Catch deprecation warnings from generate_classes_maybe_cached and # the functions it calls until the `resources` argument is removed. with warnings.catch_warnings(): warnings.filterwarnings( "ignore", category=FutureWarning, module='civis') classes = generate_classes_maybe_cached(local_api_spec, session_auth_key, api_version, resources) for class_name, cls in classes.items(): setattr(self, class_name, cls(self._session_kwargs, client=self, return_type=return_type))
def __init__(self, api_key=None, return_type='snake', retry_total=6, api_version="1.0", resources="all", local_api_spec=None): if retry_total != 6: warnings.warn( "Setting the retry_total parameter no longer has any effect, " "as retries are now handled automatically.", FutureWarning ) if return_type not in _RETURN_TYPES: raise ValueError( f"Return type must be one of {set(_RETURN_TYPES)}: " f"{return_type}" ) self._feature_flags = () session_auth_key = get_api_key(api_key) self._session_kwargs = {'api_key': session_auth_key} self.last_response = None # Catch deprecation warnings from generate_classes_maybe_cached and # the functions it calls until the `resources` argument is removed. with warnings.catch_warnings(): warnings.filterwarnings( "ignore", category=FutureWarning, module='civis') classes = generate_classes_maybe_cached(local_api_spec, session_auth_key, api_version, resources) for class_name, cls in classes.items(): setattr(self, class_name, cls(self._session_kwargs, client=self, return_type=return_type))
def cache_api_spec(cache=CACHED_SPEC_PATH, api_key=None, api_version="1.0"): """Cache a local copy of the Civis Data Science API spec Parameters ---------- cache : str, optional File in which to store the cache of the API spec api_key : str, optional Your API key obtained from the Civis Platform. If not given, the client will use the :envvar:`CIVIS_API_KEY` environment variable. api_version : string, optional The version of endpoints to call. May instantiate multiple client objects with different versions. Currently only "1.0" is supported. """ api_key = get_api_key(api_key) spec = get_api_spec(api_key, api_version=api_version) with open(cache, "wt") as _fout: json.dump(spec, _fout)
def __init__(self, api_key=None, return_type='snake', retry_total=6, api_version="1.0", resources="base", local_api_spec=None): if return_type not in ['snake', 'raw', 'pandas']: raise ValueError("Return type must be one of 'snake', 'raw', " "'pandas'") self._feature_flags = () session_auth_key = get_api_key(api_key) self._session_kwargs = { 'api_key': session_auth_key, 'max_retries': retry_total } classes = generate_classes_maybe_cached(local_api_spec, session_auth_key, api_version, resources) for class_name, cls in classes.items(): setattr(self, class_name, cls(self._session_kwargs, return_type))