API Reference
unparallel
unparallel.RequestError
dataclass
A dataclass wrapping an exception that was raised during a web request.
Besides the exception itself, this contains the URL, method, and (optional) payload of the failed request.
ATTRIBUTE | DESCRIPTION |
---|---|
url |
The target URL of the request.
TYPE:
|
method |
The HTTP method.
TYPE:
|
payload |
The payload/body of the request.
TYPE:
|
exception |
(Exception): The exception that was raised.
TYPE:
|
Source code in unparallel/unparallel.py
unparallel.up
async
up(urls, method='GET', base_url=None, headers=None, payloads=None, response_fn=DEFAULT_JSON_FN, flatten_result=False, max_connections=100, timeout=10, max_retries_on_timeout=3, raise_for_status=True, limits=None, timeouts=None, client=None, progress=True, semaphore_value=USE_MAX_CONNECTIONS)
Creates async web requests to the specified URL(s) using asyncio
and httpx
.
PARAMETER | DESCRIPTION |
---|---|
urls |
A list of URLs as the targets for the requests.
If only one URL but multiple payloads are supplied, that URL is used for
all requests.
If a
TYPE:
|
method |
HTTP method to use - one of
TYPE:
|
base_url |
The base URL of the target API/service. Defaults to
TYPE:
|
headers |
A dictionary of headers to use.
Defaults to
TYPE:
|
payloads |
A list of JSON payloads (dictionaries) e.g.
for HTTP post requests. Used together with
TYPE:
|
response_fn |
The function (callback)
to apply on every response of the HTTP requests. This can be an existing
function of
TYPE:
|
flatten_result |
If True and the response per request is a list,
flatten that list of lists. This is useful when using paging.
Defaults to
TYPE:
|
max_connections |
The total number of simultaneous TCP
connections. Defaults to
TYPE:
|
timeout |
The timeout for requests in seconds. Defaults to 10.
This is passed into
TYPE:
|
max_retries_on_timeout |
The maximum number retries if the requests fails
due to a timeout (
TYPE:
|
raise_for_status |
If True,
TYPE:
|
limits |
The limits configuration for
TYPE:
|
timeouts |
The timeout configuration for
TYPE:
|
client |
An instance of
TYPE:
|
progress |
If set to
TYPE:
|
semaphore_value |
(Union[int, UseMaxConnections, None]): The value for the
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the HTTP method is not valid. |
ValueError
|
If the number of URLs provided does not match the number of payloads (except if there is only one URL). |
RETURNS | DESCRIPTION |
---|---|
List[Any]
|
List[Any]: A list of the response data per request in the same order as the |
List[Any]
|
input (URLs/payloads). |
Source code in unparallel/unparallel.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|