Skip to content

fastreq_async()

fastreq.client.fastreq_async async

fastreq_async(
    urls: str | list[str],
    *,
    backend: str = "auto",
    concurrency: int = 20,
    max_retries: int = 3,
    rate_limit: float | None = None,
    rate_limit_burst: int = 5,
    http2: bool = True,
    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,
    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,
    headers: dict[str, str] | None = None,
    proxy: str | None = None,
    return_type: ReturnType | str = ReturnType.JSON,
    parse_func: Callable[[Any], Any] | None = None,
    keys: list[str] | None = None
) -> Any

Async convenience function for parallel requests.

Example

import asyncio from fastreq import fastreq_async async def main(): ... results = await fastreq_async( ... urls=["https://httpbin.org/get"] * 3, ... concurrency=5, ... ) ... return results results = asyncio.run(main()) print(len(results)) 3

Parameters:

Name Type Description Default
urls str | list[str]

Single URL or list of URLs to request

required
backend str

Backend to use ("auto", "niquests", "aiohttp", or "requests")

'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
debug bool

Enable debug logging

False
verbose bool

Enable verbose output

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
headers dict[str, str] | None

Request headers

None
proxy str | None

Proxy URL

None
return_type ReturnType | str

How to parse the response (json, text, content, response, stream)

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

Custom function to parse each response

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: str = "auto",
    concurrency: int = 20,
    max_retries: int = 3,
    rate_limit: float | None = None,
    rate_limit_burst: int = 5,
    http2: bool = True,
    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,
    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,
    headers: dict[str, str] | None = None,
    proxy: str | None = None,
    return_type: ReturnType | str = ReturnType.JSON,
    parse_func: Callable[[Any], Any] | None = None,
    keys: list[str] | None = None,
) -> Any:
    """Async convenience function for parallel requests.

    Example:
        >>> import asyncio
        >>> from fastreq import fastreq_async
        >>> async def main():
        ...     results = await fastreq_async(
        ...         urls=["https://httpbin.org/get"] * 3,
        ...         concurrency=5,
        ...     )
        ...     return results
        >>> results = asyncio.run(main())
        >>> print(len(results))
        3

    Args:
        urls: Single URL or list of URLs to request
        backend: Backend to use ("auto", "niquests", "aiohttp", or "requests")
        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
        debug: Enable debug logging
        verbose: Enable verbose output
        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)
        headers: Request headers
        proxy: Proxy URL
        return_type: How to parse the response (json, text, content, response, stream)
        parse_func: Custom function to parse each response
        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,
        follow_redirects=follow_redirects,
        verify_ssl=verify_ssl,
        timeout=timeout,
        cookies=cookies,
        random_user_agent=random_user_agent,
        random_proxy=random_proxy,
        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,
            keys=keys,
        )