wreq
The main wreq module contains core classes and types used throughout the library.
wreq.Client
A client for making HTTP requests.
Source code in python/wreq/wreq.py
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 | |
cookie_jar
instance-attribute
__init__
__init__(*, emulation=..., user_agent=..., headers=..., orig_headers=..., referer=..., redirect=..., raise_for_status=..., cookie_store=..., cookie_provider=..., timeout=..., connect_timeout=..., read_timeout=..., tcp_keepalive=..., tcp_keepalive_interval=..., tcp_keepalive_retries=..., tcp_user_timeout=..., tcp_nodelay=..., tcp_reuse_address=..., pool_idle_timeout=..., pool_max_idle_per_host=..., pool_max_size=..., http1_only=..., http2_only=..., https_only=..., http1_options=..., http2_options=..., tls_verify=..., tls_verify_hostname=..., tls_identity=..., tls_keylog=..., tls_info=..., tls_min_version=..., tls_max_version=..., tls_options=..., no_proxy=..., proxies=..., local_address=..., local_addresses=..., interface=..., dns_options=..., gzip=..., brotli=..., deflate=..., zstd=...)
Creates a new Client instance.
Examples:
import asyncio
import wreq
async def main():
client = wreq.Client(
user_agent="Mozilla/5.0",
timeout=10,
)
response = await client.get('https://httpbin.io/get')
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
Emulation config. |
...
|
user_agent
|
str
|
Sets the |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
Sets the default headers for every request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
Sets the original headers for every request. |
...
|
referer
|
bool
|
Enable or disable automatic setting of the |
...
|
redirect
|
Policy
|
Set a |
...
|
raise_for_status
|
bool
|
Enable or disable automatic raising of exceptions for HTTP status codes. |
...
|
cookie_store
|
bool
|
Enable a persistent cookie store for the client. |
...
|
cookie_provider
|
Jar
|
Set the persistent cookie store for the client. Cookies received in responses will be passed to this store, and additional requests will query this store for cookies. By default, no cookie store is used. |
...
|
timeout
|
timedelta
|
Enables a request timeout. The timeout is applied from when the request starts connecting until the response body has finished. Default is no timeout. |
...
|
connect_timeout
|
timedelta
|
Set a timeout for only the connect phase of a |
...
|
read_timeout
|
timedelta
|
Set a timeout for only the read phase of a |
...
|
tcp_keepalive
|
timedelta
|
Set that all sockets have Default is 15 seconds. |
...
|
tcp_keepalive_interval
|
timedelta
|
Set that all sockets have Default is 15 seconds. |
...
|
tcp_keepalive_retries
|
int
|
Set that all sockets have Default is 3 retries. |
...
|
tcp_user_timeout
|
timedelta
|
Set that all sockets have This option controls how long transmitted data may remain unacknowledged before the connection is force-closed. Default is 30 seconds. |
...
|
tcp_nodelay
|
bool
|
Set whether sockets have Default is |
...
|
tcp_reuse_address
|
bool
|
Enable SO_REUSEADDR. |
...
|
pool_idle_timeout
|
timedelta
|
Set an optional timeout for idle sockets being kept-alive. |
...
|
pool_max_idle_per_host
|
int
|
Sets the maximum idle connection per host allowed in the pool. |
...
|
pool_max_size
|
int
|
Sets the maximum number of connections in the pool. |
...
|
http1_only
|
bool
|
Only use HTTP/1. |
...
|
http2_only
|
bool
|
Only use HTTP/2. |
...
|
https_only
|
bool
|
Restrict the Client to be used with HTTPS only requests. |
...
|
http1_options
|
Http1Options
|
Sets the HTTP/1 options for the client. |
...
|
http2_options
|
Http2Options
|
Sets the HTTP/2 options for the client. |
...
|
tls_verify
|
bool | Path | CertStore
|
Sets whether to verify TLS certificates. |
...
|
tls_verify_hostname
|
bool
|
Configures the use of hostname verification when connecting. |
...
|
tls_identity
|
Identity
|
Represents a private key and X509 cert as a client certificate. |
...
|
tls_keylog
|
KeyLog
|
Key logging policy (environment or file). |
...
|
tls_info
|
bool
|
Add TLS information as |
...
|
tls_min_version
|
TlsVersion
|
Minimum TLS version. |
...
|
tls_max_version
|
TlsVersion
|
Maximum TLS version. |
...
|
tls_options
|
TlsOptions
|
Sets the TLS options. |
...
|
no_proxy
|
bool
|
Clear all This also disables the automatic usage of the "system" proxy. |
...
|
proxies
|
Sequence[Proxy]
|
The proxies to use for requests. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
dns_options
|
ResolverOptions
|
|
...
|
gzip
|
bool
|
Enable auto gzip decompression by checking the |
...
|
brotli
|
bool
|
Enable auto brotli decompression by checking the |
...
|
deflate
|
bool
|
Enable auto deflate decompression by checking the |
...
|
zstd
|
bool
|
Enable auto zstd decompression by checking the |
...
|
Source code in python/wreq/wreq.py
close
Closes the client and any associated resources.
After calling this method, the client should not be used to make further requests.
Examples:
import asyncio
import wreq
async def main():
client = wreq.Client()
response = await client.get('https://httpbin.io/get')
print(await response.text())
client.close()
asyncio.run(main())
Source code in python/wreq/wreq.py
request
async
request(method, url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given method and URL.
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.request(Method.GET, "https://httpbin.io/anything")
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
websocket
async
websocket(url, *, emulation=..., proxy=..., local_address=..., local_addresses=..., interface=..., headers=..., orig_headers=..., default_headers=..., cookies=..., protocols=..., version=..., auth=..., bearer_auth=..., basic_auth=..., query=..., read_buffer_size=..., write_buffer_size=..., max_write_buffer_size=..., max_message_size=..., max_frame_size=..., accept_unmasked_frames=...)
Sends a WebSocket request.
Examples
import wreq
import asyncio
async def main():
client = wreq.Client()
ws = await client.websocket("wss://echo.websocket.org")
await ws.send(wreq.Message.from_text("Hello, WebSocket!"))
message = await ws.recv()
print("Received:", message.data)
await ws.close()
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind to an interface by SO_BINDTODEVICE. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
protocols
|
Sequence[str]
|
The protocols to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
read_buffer_size
|
int
|
Read buffer capacity. This buffer is eagerly allocated and used for receiving messages. For high read load scenarios a larger buffer, e.g. 128 KiB, improves performance. For scenarios where you expect a lot of connections and don't need high read load performance a smaller buffer, e.g. 4 KiB, would be appropriate to lower total memory usage. The default value is 128 KiB. |
...
|
write_buffer_size
|
int
|
The target minimum size of the write buffer to reach before writing the data to the underlying stream. The default value is 128 KiB. If set to 0 each message will be eagerly written to the underlying stream. It is often more optimal to allow them to buffer a little, hence the default value. Note: flush() will always fully write the buffer regardless. |
...
|
max_write_buffer_size
|
int
|
The max size of the write buffer in bytes. Setting this can provide backpressure in the case the write buffer is filling up due to write errors. The default value is unlimited. Note: The write buffer only builds up past write_buffer_size when writes to the underlying stream are failing. So the write buffer can not fill up if you are not observing write errors even if not flushing. Note: Should always be at least write_buffer_size + 1 message and probably a little more depending on error handling strategy. |
...
|
max_message_size
|
int
|
The maximum size of an incoming message. None means no size limit. The default value is 64 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user. |
...
|
max_frame_size
|
int
|
The maximum size of a single incoming message frame. None means no size limit. The limit is for frame payload NOT including the frame header. The default value is 16 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user. |
...
|
accept_unmasked_frames
|
bool
|
When set to True, the server will accept and handle unmasked frames from the client. According to RFC 6455, the server must close the connection to the client in such cases, however it seems like there are some popular libraries that are sending unmasked frames, ignoring the RFC. By default this option is set to False, i.e. according to RFC6455. |
...
|
Source code in python/wreq/wreq.py
trace
async
trace(url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given URL
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.trace("https://httpbin.io/anything")
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
options
async
options(url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given URL
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.options("https://httpbin.io/anything")
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
patch
async
patch(url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given URL
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.patch("https://httpbin.io/anything", json={"key": "value"})
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
delete
async
delete(url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given URL
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.delete("https://httpbin.io/anything")
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
put
async
put(url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given URL
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.put("https://httpbin.io/anything", json={"key": "value"})
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
post
async
post(url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given URL
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.post("https://httpbin.io/anything", json={"key": "value"})
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
head
async
head(url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given URL
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.head("https://httpbin.io/anything")
print(response.status)
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
get
async
get(url, *, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Sends a request with the given URL
Examples
import wreq
import asyncio
from wreq import Method
async def main():
client = wreq.Client()
response = await client.get("https://httpbin.io/anything")
print(await response.text())
asyncio.run(main())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
Source code in python/wreq/wreq.py
wreq.Response
A response from a request.
Examples
import asyncio
import wreq
async def main():
response = await wreq.get("https://www.rust-lang.org")
print("Status Code: ", response.status)
print("Version: ", response.version)
print("Response URL: ", response.url)
print("Headers: ", response.headers)
print("Content-Length: ", response.content_length)
print("Encoding: ", response.encoding)
print("Remote Address: ", response.remote_addr)
text_content = await response.text()
print("Text: ", text_content)
if __name__ == "__main__":
asyncio.run(main())
Source code in python/wreq/wreq.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
raise_for_status
stream
text
async
json
async
bytes
async
close
async
Close the response.
This method closes the network connection regardless of whether connection pooling is
enabled or not. It is recommended to use async context managers (async with statement)
to properly manage response lifecycle instead of calling this method manually.
Source code in python/wreq/wreq.py
HTTP Types
wreq.Method
wreq.Version
wreq.StatusCode
HTTP status code.
Source code in python/wreq/wreq.py
as_int
is_informational
is_success
is_redirection
is_client_error
is_server_error
__richcmp__
Source code in python/wreq/wreq.py
Request Types
wreq.Request
typed-dict
Bases: TypedDict
Source code in python/wreq/wreq.py
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 | |
__init__
__init__(*, emulation=..., headers=..., orig_headers=..., default_headers=..., cookies=..., proxy=..., local_address=..., local_addresses=..., interface=..., timeout=..., read_timeout=..., version=..., redirect=..., cookie_provider=..., gzip=..., brotli=..., deflate=..., zstd=..., auth=..., bearer_auth=..., basic_auth=..., query=..., form=..., json=..., body=..., multipart=...)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
timeout
|
timedelta
|
The timeout to use for the request. |
...
|
read_timeout
|
timedelta
|
The read timeout to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
redirect
|
Policy
|
The redirect policy. |
...
|
cookie_provider
|
Jar
|
Set cookie provider for the request. |
...
|
gzip
|
bool
|
Sets gzip as an accepted encoding. |
...
|
brotli
|
bool
|
Sets brotli as an accepted encoding. |
...
|
deflate
|
bool
|
Sets deflate as an accepted encoding. |
...
|
zstd
|
bool
|
Sets zstd as an accepted encoding. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
form
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The form parameters to use for the request. |
...
|
json
|
Any
|
The JSON body to use for the request. |
...
|
body
|
str | bytes | Sequence[Tuple[str, str]] | Tuple[str, str | int | float | bool] | Mapping[str, str | int | float | bool] | Any | Generator[bytes, str, None] | AsyncGenerator[bytes, str]
|
The body to use for the request. |
...
|
multipart
|
Multipart
|
The multipart form to use for the request. |
...
|
wreq.Multipart
A multipart form for a request.
Source code in python/wreq/wreq.py
wreq.Part
A part of a multipart form.
Source code in python/wreq/wreq.py
__init__
Creates a new part.
Arguments
name- The name of the part.value- The value of the part, either text, bytes, a file path, or a async or sync stream.filename- The filename of the part.mime- The MIME type of the part.length- The length of the part when value is a stream (e.g., for file uploads).headers- The custom headers for the part.
Source code in python/wreq/wreq.py
WebSocket
wreq.WebSocket
A WebSocket response.
Source code in python/wreq/wreq.py
recv
async
send
async
send_all
async
wreq.WebSocketRequest
typed-dict
Bases: TypedDict
Source code in python/wreq/wreq.py
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 | |
__init__
__init__(*, emulation=..., proxy=..., local_address=..., local_addresses=..., interface=..., headers=..., orig_headers=..., default_headers=..., cookies=..., protocols=..., version=..., auth=..., bearer_auth=..., basic_auth=..., query=..., read_buffer_size=..., write_buffer_size=..., max_write_buffer_size=..., max_message_size=..., max_frame_size=..., accept_unmasked_frames=...)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
The Emulation settings for the request. |
...
|
proxy
|
Proxy
|
The proxy to use for the request. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind to an interface by SO_BINDTODEVICE. |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
The headers to use for the request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
The original headers to use for the request. |
...
|
default_headers
|
bool
|
The option enables default headers. |
...
|
cookies
|
str | Mapping[str, str]
|
The cookies to use for the request. |
...
|
protocols
|
Sequence[str]
|
The protocols to use for the request. |
...
|
version
|
Version
|
The HTTP version to use for the request. |
...
|
auth
|
str
|
The authentication to use for the request. |
...
|
bearer_auth
|
str
|
The bearer authentication to use for the request. |
...
|
basic_auth
|
Tuple[str, str | None]
|
The basic authentication to use for the request. |
...
|
query
|
Sequence[Tuple[str, str | int | float | bool]] | Mapping[str, str | int | float | bool]
|
The query parameters to use for the request. |
...
|
read_buffer_size
|
int
|
Read buffer capacity. This buffer is eagerly allocated and used for receiving messages. For high read load scenarios a larger buffer, e.g. 128 KiB, improves performance. For scenarios where you expect a lot of connections and don't need high read load performance a smaller buffer, e.g. 4 KiB, would be appropriate to lower total memory usage. The default value is 128 KiB. |
...
|
write_buffer_size
|
int
|
The target minimum size of the write buffer to reach before writing the data to the underlying stream. The default value is 128 KiB. If set to 0 each message will be eagerly written to the underlying stream. It is often more optimal to allow them to buffer a little, hence the default value. Note: flush() will always fully write the buffer regardless. |
...
|
max_write_buffer_size
|
int
|
The max size of the write buffer in bytes. Setting this can provide backpressure in the case the write buffer is filling up due to write errors. The default value is unlimited. Note: The write buffer only builds up past write_buffer_size when writes to the underlying stream are failing. So the write buffer can not fill up if you are not observing write errors even if not flushing. Note: Should always be at least write_buffer_size + 1 message and probably a little more depending on error handling strategy. |
...
|
max_message_size
|
int
|
The maximum size of an incoming message. None means no size limit. The default value is 64 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user. |
...
|
max_frame_size
|
int
|
The maximum size of a single incoming message frame. None means no size limit. The limit is for frame payload NOT including the frame header. The default value is 16 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user. |
...
|
accept_unmasked_frames
|
bool
|
When set to True, the server will accept and handle unmasked frames from the client. According to RFC 6455, the server must close the connection to the client in such cases, however it seems like there are some popular libraries that are sending unmasked frames, ignoring the RFC. By default this option is set to False, i.e. according to RFC6455. |
...
|
wreq.Message
A WebSocket message.
Source code in python/wreq/wreq.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
close
instance-attribute
Returns the close code and reason of the message if it is a close message.
json
instance-attribute
Returns the JSON representation of the message if it is a text message with JSON content.
from_binary
staticmethod
Creates a new binary message.
Arguments
data- The binary data or any JSON-serializable data of the message.
from_text
staticmethod
Creates a new text message.
Arguments
data- The text content or any JSON-serializable data of the message.
from_ping
staticmethod
from_pong
staticmethod
from_close
staticmethod
Creates a new close message.
Arguments
code- The close code.reason- An optional reason for closing.
Streaming
wreq.Streamer
A stream response.
An asynchronous iterator yielding data chunks (bytes) or HTTP trailers (HeaderMap) from the response stream.
Used to stream response content and receive HTTP trailers if present.
Implemented in the stream method of the Response class.
Can be used in an asynchronous for loop in Python.
When streaming a response, each iteration yields either a bytes object (for body data) or a HeaderMap (for HTTP trailers, if the server sends them). This allows you to access HTTP/1.1 or HTTP/2 trailers in addition to the main body.
Examples
import asyncio
import wreq
from wreq import Method, Emulation, HeaderMap
async def main():
resp = await wreq.get("https://example.com/stream-with-trailers")
async with resp.stream() as streamer:
async for chunk in streamer:
if isinstance(chunk, bytes):
print("Chunk: ", chunk)
elif isinstance(chunk, HeaderMap):
print("Trailers: ", chunk)
await asyncio.sleep(0.1)
if __name__ == "__main__":
asyncio.run(main())
Source code in python/wreq/wreq.py
Network Types
wreq.SocketAddr
A IP socket address.
Source code in python/wreq/wreq.py
ip
Configuration
wreq.ClientConfig
typed-dict
Bases: TypedDict
Source code in python/wreq/wreq.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 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 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | |
__init__
__init__(*, emulation=..., user_agent=..., headers=..., orig_headers=..., referer=..., redirect=..., raise_for_status=..., cookie_store=..., cookie_provider=..., timeout=..., connect_timeout=..., read_timeout=..., tcp_keepalive=..., tcp_keepalive_interval=..., tcp_keepalive_retries=..., tcp_user_timeout=..., tcp_nodelay=..., tcp_reuse_address=..., pool_idle_timeout=..., pool_max_idle_per_host=..., pool_max_size=..., http1_only=..., http2_only=..., https_only=..., http1_options=..., http2_options=..., tls_verify=..., tls_verify_hostname=..., tls_identity=..., tls_keylog=..., tls_info=..., tls_min_version=..., tls_max_version=..., tls_options=..., no_proxy=..., proxies=..., local_address=..., local_addresses=..., interface=..., dns_options=..., gzip=..., brotli=..., deflate=..., zstd=...)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emulation
|
Emulation | Profile
|
Emulation config. |
...
|
user_agent
|
str
|
Sets the |
...
|
headers
|
Mapping[str, str] | HeaderMap
|
Sets the default headers for every request. |
...
|
orig_headers
|
Sequence[str] | OrigHeaderMap
|
Sets the original headers for every request. |
...
|
referer
|
bool
|
Enable or disable automatic setting of the |
...
|
redirect
|
Policy
|
Set a |
...
|
raise_for_status
|
bool
|
Enable or disable automatic raising of exceptions for HTTP status codes. |
...
|
cookie_store
|
bool
|
Enable a persistent cookie store for the client. |
...
|
cookie_provider
|
Jar
|
Set the persistent cookie store for the client. Cookies received in responses will be passed to this store, and additional requests will query this store for cookies. By default, no cookie store is used. |
...
|
timeout
|
timedelta
|
Enables a request timeout. The timeout is applied from when the request starts connecting until the response body has finished. Default is no timeout. |
...
|
connect_timeout
|
timedelta
|
Set a timeout for only the connect phase of a |
...
|
read_timeout
|
timedelta
|
Set a timeout for only the read phase of a |
...
|
tcp_keepalive
|
timedelta
|
Set that all sockets have Default is 15 seconds. |
...
|
tcp_keepalive_interval
|
timedelta
|
Set that all sockets have Default is 15 seconds. |
...
|
tcp_keepalive_retries
|
int
|
Set that all sockets have Default is 3 retries. |
...
|
tcp_user_timeout
|
timedelta
|
Set that all sockets have This option controls how long transmitted data may remain unacknowledged before the connection is force-closed. Default is 30 seconds. |
...
|
tcp_nodelay
|
bool
|
Set whether sockets have Default is |
...
|
tcp_reuse_address
|
bool
|
Enable SO_REUSEADDR. |
...
|
pool_idle_timeout
|
timedelta
|
Set an optional timeout for idle sockets being kept-alive. |
...
|
pool_max_idle_per_host
|
int
|
Sets the maximum idle connection per host allowed in the pool. |
...
|
pool_max_size
|
int
|
Sets the maximum number of connections in the pool. |
...
|
http1_only
|
bool
|
Only use HTTP/1. |
...
|
http2_only
|
bool
|
Only use HTTP/2. |
...
|
https_only
|
bool
|
Restrict the Client to be used with HTTPS only requests. |
...
|
http1_options
|
Http1Options
|
Sets the HTTP/1 options for the client. |
...
|
http2_options
|
Http2Options
|
Sets the HTTP/2 options for the client. |
...
|
tls_verify
|
bool | Path | CertStore
|
Sets whether to verify TLS certificates. |
...
|
tls_verify_hostname
|
bool
|
Configures the use of hostname verification when connecting. |
...
|
tls_identity
|
Identity
|
Represents a private key and X509 cert as a client certificate. |
...
|
tls_keylog
|
KeyLog
|
Key logging policy (environment or file). |
...
|
tls_info
|
bool
|
Add TLS information as |
...
|
tls_min_version
|
TlsVersion
|
Minimum TLS version. |
...
|
tls_max_version
|
TlsVersion
|
Maximum TLS version. |
...
|
tls_options
|
TlsOptions
|
Sets the TLS options. |
...
|
no_proxy
|
bool
|
Clear all This also disables the automatic usage of the "system" proxy. |
...
|
proxies
|
Sequence[Proxy]
|
The proxies to use for requests. |
...
|
local_address
|
IPv4Address | IPv6Address
|
Bind to a local IP Address. |
...
|
local_addresses
|
Tuple[IPv4Address | None, IPv6Address | None]
|
Bind to dual-stack local IP Addresses. |
...
|
interface
|
str
|
Bind connections only on the specified network interface. This option is only available on the following operating systems:
On Android, Linux, and Fuchsia, this uses the
Note that connections will fail if the provided interface name is not a network interface that currently exists when a connection is established. |
...
|
dns_options
|
ResolverOptions
|
|
...
|
gzip
|
bool
|
Enable auto gzip decompression by checking the |
...
|
brotli
|
bool
|
Enable auto brotli decompression by checking the |
...
|
deflate
|
bool
|
Enable auto deflate decompression by checking the |
...
|
zstd
|
bool
|
Enable auto zstd decompression by checking the |
...
|