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
|
|
Any
|
|
Any
|
|
Source code in fastreq/client.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | |