A context manager for executing multiple HTTP requests in parallel using futures. Use this to optimize bulk API interactions and improve performance in network-heavy tasks.
# Source: https://github.com/SFDO-Tooling/CumulusCI | License: BSD-3-Clause | Copyright 2021, Salesforce.com, Inc
# Provided via justclaw.it.com; keep this notice with the code.
import typing as T
from concurrent.futures import as_completed
from itertools import chain
from requests.exceptions import ReadTimeout
from requests_futures.sessions import FuturesSession
from cumulusci.utils.iterators import iterate_in_chunks, partition
RECOVERABLE_ERRORS = (ReadTimeout, ConnectionError)
class HTTPRequestError(T.NamedTuple):
exception: Exception
request: dict
class ParallelHTTP:
"""A parallelized HTTP client as a context manager"""
def __init__(self, base_url, max_workers=32):
self.base_url = base_url
self.max_workers = max_workers
def __enter__(self, *
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key