Skip to content

fastreq_async()

fastreq.client.fastreq_async async

fastreq_async(
    urls: str | list[str],
    *,
    backend: BackendName | str = "auto",
    concurrency: int = 20,
    max_retries: int = 3,
    rate_limit: float | None = None,
    rate_limit_burst: int = 5,
    http2: bool = True,
    impersonate: str | None = None,
    follow_redirects: bool = True,
    verify_ssl: bool = True,
    timeout: float | None = None,
    cookies: dict[str, str] | None = None,
    random_user_agent: bool = True,
    random_proxy: bool = False,
    proxies: list[str] | None = None,
    proxy_selection: ProxySelection
    | str = ProxySelection.ROUND_ROBIN,
    proxy_cooldown: float = 60.0,
    webshare_file: str | None = None,
    headers: dict[str, str] | None = None,
    debug: bool = False,
    verbose: bool = True,
    return_none_on_failure: bool = False,
    method: str = "GET",
    params: dict[str, Any] | None = None,
    data: Any = None,
    json: Any = None,
    proxy: str | None = None,
    return_type: ReturnType | str = ReturnType.JSON,
    parse_func: Callable[[Any], Any] | None = None,
    stream_callback: Callable[[bytes], Any] | None = None,
    progress: ProgressOption = None,
    progress_callback: ProgressCallback | None = None,
    keys: list[str] | None = None,
) -> Any

Async convenience function for parallel requests.

Parameters:

Name Type Description Default
urls str | list[str]

Single URL or list of URLs to request

required
backend BackendName | str

Backend to use ("auto", "niquests", "httpx")

'auto'
concurrency int

Maximum number of concurrent requests

20
max_retries int

Maximum retry attempts per request

3
rate_limit float | None

Requests per second (None for no limit)

None
rate_limit_burst int

Burst size for rate limiter

5
http2 bool

Enable HTTP/2 (if supported by backend)

True
follow_redirects bool

Follow HTTP redirects

True
verify_ssl bool

Verify SSL certificates

True
timeout float | None

Default timeout per request (seconds)

None
cookies dict[str, str] | None

Initial session cookies

None
random_user_agent bool

Rotate user agents

True
random_proxy bool

Enable proxy rotation

False
proxies list[str] | None

List of proxy URLs for rotation

None
proxy_selection ProxySelection | str

Selection strategy ("round_robin" or "random")

ROUND_ROBIN
proxy_cooldown float

Seconds before retrying a failed proxy

60.0
webshare_file str | None

Path to a Webshare proxy text file

None
headers dict[str, str] | None

Default headers applied to all requests

None
debug bool

Enable the fastreq loguru namespace (never touches global sinks)

False
verbose bool

Enable verbose output (stored; progress-bar control)

True
return_none_on_failure bool

Return None instead of raising on failure

False
method str

HTTP method (GET, POST, etc.)

'GET'
params dict[str, Any] | None

Query parameters

None
data Any

Request body data

None
json Any

JSON body (serialized automatically)

None
proxy str | None

Explicit proxy URL (overrides rotation)

None
return_type ReturnType | str

How to parse the response

JSON
parse_func Callable[[Any], Any] | None

Custom function to parse each response

None
stream_callback Callable[[bytes], Any] | None

Callback for streaming responses

None
progress ProgressOption

Optional "rich"/"tqdm" progress bar, or True to auto-select an installed optional backend.

None
progress_callback ProgressCallback | None

Optional callback receiving (completed, total).

None
keys list[str] | None

Keys for dict return (must match urls length)

None

Returns:

Type Description
Any

Single URL → single result

Any

List of URLs → list of results

Any

List of URLs with keys → dict mapping keys to results

Source code in fastreq/client.py
async def fastreq_async(
    urls: str | list[str],
    *,
    backend: BackendName | str = "auto",
    concurrency: int = 20,
    max_retries: int = 3,
    rate_limit: float | None = None,
    rate_limit_burst: int = 5,
    http2: bool = True,
    impersonate: str | None = None,
    follow_redirects: bool = True,
    verify_ssl: bool = True,
    timeout: float | None = None,
    cookies: dict[str, str] | None = None,
    random_user_agent: bool = True,
    random_proxy: bool = False,
    proxies: list[str] | None = None,
    proxy_selection: ProxySelection | str = ProxySelection.ROUND_ROBIN,
    proxy_cooldown: float = 60.0,
    webshare_file: str | None = None,
    headers: dict[str, str] | None = None,
    debug: bool = False,
    verbose: bool = True,
    return_none_on_failure: bool = False,
    method: str = "GET",
    params: dict[str, Any] | None = None,
    data: Any = None,
    json: Any = None,
    proxy: str | None = None,
    return_type: ReturnType | str = ReturnType.JSON,
    parse_func: Callable[[Any], Any] | None = None,
    stream_callback: Callable[[bytes], Any] | None = None,
    progress: ProgressOption = None,
    progress_callback: ProgressCallback | None = None,
    keys: list[str] | None = None,
) -> Any:
    """Async convenience function for parallel requests.

    Args:
        urls: Single URL or list of URLs to request
        backend: Backend to use ("auto", "niquests", "httpx")
        concurrency: Maximum number of concurrent requests
        max_retries: Maximum retry attempts per request
        rate_limit: Requests per second (None for no limit)
        rate_limit_burst: Burst size for rate limiter
        http2: Enable HTTP/2 (if supported by backend)
        follow_redirects: Follow HTTP redirects
        verify_ssl: Verify SSL certificates
        timeout: Default timeout per request (seconds)
        cookies: Initial session cookies
        random_user_agent: Rotate user agents
        random_proxy: Enable proxy rotation
        proxies: List of proxy URLs for rotation
        proxy_selection: Selection strategy ("round_robin" or "random")
        proxy_cooldown: Seconds before retrying a failed proxy
        webshare_file: Path to a Webshare proxy text file
        headers: Default headers applied to all requests
        debug: Enable the fastreq loguru namespace (never touches global sinks)
        verbose: Enable verbose output (stored; progress-bar control)
        return_none_on_failure: Return None instead of raising on failure
        method: HTTP method (GET, POST, etc.)
        params: Query parameters
        data: Request body data
        json: JSON body (serialized automatically)
        proxy: Explicit proxy URL (overrides rotation)
        return_type: How to parse the response
        parse_func: Custom function to parse each response
        stream_callback: Callback for streaming responses
        progress: Optional ``"rich"``/``"tqdm"`` progress bar, or ``True``
            to auto-select an installed optional backend.
        progress_callback: Optional callback receiving ``(completed, total)``.
        keys: Keys for dict return (must match urls length)

    Returns:
        Single URL → single result
        List of URLs → list of results
        List of URLs with keys → dict mapping keys to results
    """
    client = FastRequests(
        backend=backend,
        concurrency=concurrency,
        max_retries=max_retries,
        rate_limit=rate_limit,
        rate_limit_burst=rate_limit_burst,
        http2=http2,
        impersonate=impersonate,
        follow_redirects=follow_redirects,
        verify_ssl=verify_ssl,
        timeout=timeout,
        cookies=cookies,
        random_user_agent=random_user_agent,
        random_proxy=random_proxy,
        proxies=proxies,
        proxy_selection=proxy_selection,
        proxy_cooldown=proxy_cooldown,
        webshare_file=webshare_file,
        headers=headers,
        debug=debug,
        verbose=verbose,
        return_none_on_failure=return_none_on_failure,
    )
    async with client:
        return await client.request(
            urls,
            method=method,
            params=params,
            data=data,
            json=json,
            headers=headers,
            timeout=timeout,
            proxy=proxy,
            return_type=return_type,
            parse_func=parse_func,
            stream_callback=stream_callback,
            progress=progress,
            progress_callback=progress_callback,
            keys=keys,
        )