GlobalConfig¶
fastreq.config.GlobalConfig
dataclass
¶
Global configuration for parallel requests.
Can be loaded from environment variables or created programmatically.
Example
from fastreq.config import GlobalConfig config = GlobalConfig( ... backend="niquests", ... default_concurrency=10, ... ) config.save_to_env(".env")
Environment variables
PARALLEL_BACKEND: Backend to use ("auto", "niquests", "aiohttp", "requests") PARALLEL_CONCURRENCY: Default concurrency limit PARALLEL_MAX_RETRIES: Default max retries PARALLEL_RATE_LIMIT: Rate limit (requests per second) PARALLEL_RATE_LIMIT_BURST: Rate limit burst size PARALLEL_HTTP2: Enable HTTP/2 (true/false) PARALLEL_RANDOM_USER_AGENT: Rotate user agents (true/false) PARALLEL_RANDOM_PROXY: Enable proxy rotation (true/false) PARALLEL_PROXY_ENABLED: Enable proxies (true/false) PARALLEL_FREE_PROXIES: Enable free proxy fetching (true/false)
Attributes:
| Name | Type | Description |
|---|---|---|
backend |
str
|
Default backend selection |
default_concurrency |
int
|
Default concurrency limit |
default_max_retries |
int
|
Default maximum retry attempts |
rate_limit |
float | None
|
Rate limit in requests per second (None for no limit) |
rate_limit_burst |
int
|
Burst size for rate limiter |
http2_enabled |
bool
|
Enable HTTP/2 support |
random_user_agent |
bool
|
Enable user agent rotation |
random_proxy |
bool
|
Enable proxy rotation |
proxy_enabled |
bool
|
Enable proxy usage |
free_proxies_enabled |
bool
|
Enable free proxy fetching |
Source code in fastreq/config.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
to_env ¶
Convert config to environment variable dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Prefix for environment variable names |
'PARALLEL_'
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary of environment variable name to value |
Source code in fastreq/config.py
save_to_env ¶
Save configuration to an environment file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Path to save the .env file |
required |
prefix
|
str
|
Prefix for environment variable names |
'PARALLEL_'
|
Example
config = GlobalConfig(backend="niquests") config.save_to_env(".env")