cirro_api_client.cirro_client
1import importlib.metadata 2import platform 3 4from attrs import define, field 5 6from cirro_api_client.cirro_auth import AuthMethod 7from cirro_api_client.v1.client import Client 8 9 10def _get_user_agent(package_name: str, client_name: str) -> str: 11 try: 12 pkg_version = importlib.metadata.version(package_name) 13 except (importlib.metadata.PackageNotFoundError, ValueError): 14 pkg_version = "Unknown" 15 python_version = platform.python_version() 16 return f"{client_name} {pkg_version} (Python {python_version})" 17 18 19# noinspection PyUnresolvedReferences 20@define 21class CirroApiClient(Client): 22 """A class for interacting with the Cirro API 23 24 Attributes: 25 auth_method: The method used to authenticate API requests 26 27 base_url: The base URL for the API, all requests are made to a relative path to this URL 28 29 cookies: A dictionary of cookies to be sent with every request 30 31 headers: A dictionary of headers to be sent with every request 32 33 timeout: The maximum amount of a time a request can take. API functions will raise 34 httpx.TimeoutException if this is exceeded. 35 36 verify_ssl: Whether to verify the SSL certificate of the API server. This should be True in production, 37 but can be set to False for testing purposes. 38 39 follow_redirects: Whether to follow redirects. Default value is False. 40 41 httpx_args: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. 42 43 raise_on_unexpected_status: Whether to raise an errors.UnexpectedStatus if the API returns a 44 status code that was not documented in the source OpenAPI document. Can also be provided as a keyword 45 argument to the constructor. 46 """ 47 48 auth_method: AuthMethod 49 raise_on_unexpected_status: bool = field(default=True, kw_only=True) 50 client_name: str = field(kw_only=True, default="Cirro API Client") 51 package_name: str = field(kw_only=True, default="cirro-api-client") 52 53 def __attrs_post_init__(self): 54 self._headers["User-Agent"] = _get_user_agent(self.package_name, self.client_name)
21@define 22class CirroApiClient(Client): 23 """A class for interacting with the Cirro API 24 25 Attributes: 26 auth_method: The method used to authenticate API requests 27 28 base_url: The base URL for the API, all requests are made to a relative path to this URL 29 30 cookies: A dictionary of cookies to be sent with every request 31 32 headers: A dictionary of headers to be sent with every request 33 34 timeout: The maximum amount of a time a request can take. API functions will raise 35 httpx.TimeoutException if this is exceeded. 36 37 verify_ssl: Whether to verify the SSL certificate of the API server. This should be True in production, 38 but can be set to False for testing purposes. 39 40 follow_redirects: Whether to follow redirects. Default value is False. 41 42 httpx_args: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. 43 44 raise_on_unexpected_status: Whether to raise an errors.UnexpectedStatus if the API returns a 45 status code that was not documented in the source OpenAPI document. Can also be provided as a keyword 46 argument to the constructor. 47 """ 48 49 auth_method: AuthMethod 50 raise_on_unexpected_status: bool = field(default=True, kw_only=True) 51 client_name: str = field(kw_only=True, default="Cirro API Client") 52 package_name: str = field(kw_only=True, default="cirro-api-client") 53 54 def __attrs_post_init__(self): 55 self._headers["User-Agent"] = _get_user_agent(self.package_name, self.client_name)
A class for interacting with the Cirro API
Attributes:
- auth_method: The method used to authenticate API requests
- base_url: The base URL for the API, all requests are made to a relative path to this URL
- cookies: A dictionary of cookies to be sent with every request
- headers: A dictionary of headers to be sent with every request
- timeout: The maximum amount of a time a request can take. API functions will raise
- httpx.TimeoutException if this is exceeded.
- verify_ssl: Whether to verify the SSL certificate of the API server. This should be True in production,
- but can be set to False for testing purposes.
- follow_redirects: Whether to follow redirects. Default value is False.
- httpx_args: A dictionary of additional arguments to be passed to the
httpx.Client
andhttpx.AsyncClient
constructor. - raise_on_unexpected_status: Whether to raise an errors.UnexpectedStatus if the API returns a status code that was not documented in the source OpenAPI document. Can also be provided as a keyword argument to the constructor.
CirroApiClient( base_url: str, auth_method: cirro_api_client.cirro_auth.AuthMethod, *, cookies: Dict[str, str] = NOTHING, headers: Dict[str, str] = NOTHING, timeout: Optional[httpx.Timeout] = None, verify_ssl: Union[str, bool, ssl.SSLContext] = True, follow_redirects: bool = False, httpx_args: Dict[str, Any] = NOTHING, raise_on_unexpected_status: bool = True, client_name: str = 'Cirro API Client', package_name: str = 'cirro-api-client')
2def __init__(self, base_url, auth_method, *, cookies=NOTHING, headers=NOTHING, timeout=attr_dict['_timeout'].default, verify_ssl=attr_dict['_verify_ssl'].default, follow_redirects=attr_dict['_follow_redirects'].default, httpx_args=NOTHING, raise_on_unexpected_status=attr_dict['raise_on_unexpected_status'].default, client_name=attr_dict['client_name'].default, package_name=attr_dict['package_name'].default): 3 self._base_url = base_url 4 if cookies is not NOTHING: 5 self._cookies = cookies 6 else: 7 self._cookies = __attr_factory__cookies() 8 if headers is not NOTHING: 9 self._headers = headers 10 else: 11 self._headers = __attr_factory__headers() 12 self._timeout = timeout 13 self._verify_ssl = verify_ssl 14 self._follow_redirects = follow_redirects 15 if httpx_args is not NOTHING: 16 self._httpx_args = httpx_args 17 else: 18 self._httpx_args = __attr_factory__httpx_args() 19 self._client = attr_dict['_client'].default 20 self._async_client = attr_dict['_async_client'].default 21 self.auth_method = auth_method 22 self.raise_on_unexpected_status = raise_on_unexpected_status 23 self.client_name = client_name 24 self.package_name = package_name 25 self.__attrs_post_init__()
Method generated by attrs for class CirroApiClient.
auth_method: cirro_api_client.cirro_auth.AuthMethod