GlobalConfig¶
fastreq.config.GlobalConfig
dataclass
¶
Global configuration for fastreq.
Can be loaded from environment variables or created programmatically.
Environment variables (prefix FASTREQ_): FASTREQ_BACKEND: Backend to use ("auto", "niquests", "httpx", "curl_cffi") FASTREQ_IMPERSONATE: Browser impersonation target for curl_cffi backend FASTREQ_CONCURRENCY: Default concurrency limit FASTREQ_MAX_RETRIES: Default max retries FASTREQ_RATE_LIMIT: Rate limit (requests per second) FASTREQ_RATE_LIMIT_BURST: Rate limit burst size FASTREQ_HTTP2: Enable HTTP/2 (true/false) FASTREQ_RANDOM_USER_AGENT: Rotate user agents (true/false) FASTREQ_RANDOM_PROXY: Enable proxy rotation (true/false) FASTREQ_PROXIES: Comma-separated proxy URLs
Attributes:
| Name | Type | Description |
|---|---|---|
backend |
str
|
Default backend selection |
impersonate |
str | None
|
Browser impersonation target for the curl_cffi backend |
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 |
proxies |
str | None
|
Comma-separated proxy URLs |
Source code in fastreq/config.py
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 124 125 126 | |
load_from_env
classmethod
¶
Load configuration from environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Environment variable prefix (default FASTREQ_) |
'FASTREQ_'
|
Returns:
| Type | Description |
|---|---|
GlobalConfig
|
GlobalConfig instance |
Source code in fastreq/config.py
to_env ¶
Convert config to environment variable dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Prefix for environment variable names |
'FASTREQ_'
|
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 |
'FASTREQ_'
|