Skip to content

requester

AsyncRequester

Python
1
AsyncRequester(endpoint: str, headers: dict[str, str] | None = None, auth: Auth | None = None)

Class for making requests to some API asynchronously. Usually this gets subclassed. Attributes: endpoint (str): The base URL for the API. headers (dict): Headers to send with every request. auth (Auth): Authentication credentials. _http_client (httpx.AsyncClient): The HTTP client used to make requests.

Source code in marketplace_apis/common/requester.py
Python
66
67
68
69
70
71
72
73
74
75
76
def __init__(
    self,
    endpoint: str,
    headers: dict[str, str] | None = None,
    auth: Auth | None = None,
):
    self.headers = headers if headers else {}
    self.endpoint = endpoint
    self._auth = auth
    self.headers["User-Agent"] = f"MarketplaceApis/{__version__}"
    self._http_client: httpx.AsyncClient | None = None

get async

Python
1
get(path: str, params: dict[str, str] | None = None, decode: bool = True) -> tuple[Response, dict | bytes]

Make get request to some path with url params :param path: url where make request to :param params: url params as dict what would be used to make request :param decode: whenever to decode response as json :return: Response object, dict with decoded content or None :rtype: tuple[Response, dict | bytes]

Source code in marketplace_apis/common/requester.py
Python
107
108
109
110
111
112
113
114
115
116
117
118
async def get(
    self, path: str, params: dict[str, str] | None = None, decode: bool = True
) -> tuple[httpx.Response, dict | bytes]:
    """
    Make get request to some path with url params
    :param path: url where make request to
    :param params: url params as dict what would be used to make request
    :param decode: whenever to decode response as json
    :return: Response object, dict with decoded content or None
    :rtype: tuple[Response, dict | bytes]
    """
    return await self._make_request("get", path, params, decode=decode)

post async

Python
1
post(path: str, data: dict[str, Any] | None = None, params: dict[str, str] | None = None, decode: bool = True) -> tuple[Response, dict | bytes]

Make post request to some path with url params :param path: url where make request to :param data: post body :param params: url params as dict what would be used to make request :param decode: whenever to decode response as json :return: Response object, dict with decoded content or None :rtype: tuple[Response, dict | bytes]

Source code in marketplace_apis/common/requester.py
Python
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
async def post(
    self,
    path: str,
    data: dict[str, Any] | None = None,
    params: dict[str, str] | None = None,
    decode: bool = True,
) -> tuple[httpx.Response, dict | bytes]:
    """
    Make post request to some path with url params
    :param path: url where make request to
    :param data: post body
    :param params: url params as dict what would be used to make request
    :param decode: whenever to decode response as json
    :return: Response object, dict with decoded content or None
    :rtype: tuple[Response, dict | bytes]
    """
    return await self._make_request("post", path, params, data, decode=decode)