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    user_agent: str = field(init=False, default=None)
53
54    def __attrs_post_init__(self):
55        self.user_agent = _get_user_agent(self.package_name, self.client_name)
56        self._headers["User-Agent"] = self.user_agent
@define
class CirroApiClient(cirro_api_client.v1.client.Client):
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    user_agent: str = field(init=False, default=None)
54
55    def __attrs_post_init__(self):
56        self.user_agent = _get_user_agent(self.package_name, self.client_name)
57        self._headers["User-Agent"] = self.user_agent

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 and httpx.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')
36def __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):
37    self._base_url = base_url
38    if cookies is not NOTHING:
39        self._cookies = cookies
40    else:
41        self._cookies = __attr_factory__cookies()
42    if headers is not NOTHING:
43        self._headers = headers
44    else:
45        self._headers = __attr_factory__headers()
46    self._timeout = timeout
47    self._verify_ssl = verify_ssl
48    self._follow_redirects = follow_redirects
49    if httpx_args is not NOTHING:
50        self._httpx_args = httpx_args
51    else:
52        self._httpx_args = __attr_factory__httpx_args()
53    self._client = attr_dict['_client'].default
54    self._async_client = attr_dict['_async_client'].default
55    self.auth_method = auth_method
56    self.raise_on_unexpected_status = raise_on_unexpected_status
57    self.client_name = client_name
58    self.package_name = package_name
59    self.user_agent = attr_dict['user_agent'].default
60    self.__attrs_post_init__()

Method generated by attrs for class CirroApiClient.

raise_on_unexpected_status: bool
client_name: str
package_name: str
user_agent: str