示例#1
0
    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 = session = requests.session()
        session.auth = (session_auth_key, '')

        civis_version = civis.__version__
        session_agent = session.headers.get('User-Agent', '')
        user_agent = "civis-python/{} {}".format(civis_version, session_agent)
        session.headers.update({"User-Agent": user_agent.strip()})

        max_retries = AggressiveRetry(retry_total,
                                      backoff_factor=.75,
                                      status_forcelist=RETRY_CODES)
        adapter = HTTPAdapter(max_retries=max_retries)

        session.mount("https://", adapter)

        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(session, return_type))
示例#2
0
    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))
示例#3
0
    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))
示例#4
0
    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))