Skip to content

wreq.blocking

The blocking (synchronous) client provides the same functionality as the async client but with a synchronous API.

wreq.blocking

Response

A blocking response from a request.

Source code in python/wreq/blocking.py
class Response:
    r"""
    A blocking response from a request.
    """

    url: str
    r"""
    Get the URL of the response.
    """

    status: StatusCode
    r"""
    Get the status code of the response.
    """

    version: Version
    r"""
    Get the HTTP version of the response.
    """

    headers: HeaderMap
    r"""
    Get the headers of the response.
    """

    cookies: Sequence[Cookie]
    r"""
    Get the cookies of the response.
    """

    content_length: int | None
    r"""
    Get the content length of the response.
    """

    remote_addr: SocketAddr | None
    r"""
    Get the remote address of the response.
    """

    local_addr: SocketAddr | None
    r"""
    Get the local address of the response.
    """

    local_addr: SocketAddr | None
    r"""
    Get the local address of the response.
    """

    history: Sequence[History]
    r"""
    Get the redirect history of the Response.
    """

    tls_info: TlsInfo | None
    r"""
    Get the TLS information of the response.
    """

    def raise_for_status(self) -> None:
        r"""
        Turn a response into an error if the server returned an error.
        """

    def stream(self) -> Streamer:
        r"""
        Get the response into a `Streamer` of `bytes` from the body.
        """
        ...

    def text(self, encoding: str | None = None) -> str:
        r"""
        Get the text content with the response encoding, defaulting to utf-8 when unspecified.
        """
        ...

    def json(self) -> Any:
        r"""
        Get the JSON content of the response.
        """

    def bytes(self) -> bytes:
        r"""
        Get the bytes content of the response.
        """
        ...

    def close(self) -> None:
        r"""
        Close the response.

        This method closes the network connection regardless of whether connection pooling is
        enabled or not. It is recommended to use context managers (`with` statement) to properly
        manage response lifecycle instead of calling this method manually.
        """

    def __enter__(self) -> Any: ...
    def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
    def __str__(self) -> str: ...

url instance-attribute

url

Get the URL of the response.

status instance-attribute

status

Get the status code of the response.

version instance-attribute

version

Get the HTTP version of the response.

headers instance-attribute

headers

Get the headers of the response.

cookies instance-attribute

cookies

Get the cookies of the response.

content_length instance-attribute

content_length

Get the content length of the response.

remote_addr instance-attribute

remote_addr

Get the remote address of the response.

local_addr instance-attribute

local_addr

Get the local address of the response.

history instance-attribute

history

Get the redirect history of the Response.

tls_info instance-attribute

tls_info

Get the TLS information of the response.

raise_for_status

raise_for_status()

Turn a response into an error if the server returned an error.

Source code in python/wreq/blocking.py
def raise_for_status(self) -> None:
    r"""
    Turn a response into an error if the server returned an error.
    """

stream

stream()

Get the response into a Streamer of bytes from the body.

Source code in python/wreq/blocking.py
def stream(self) -> Streamer:
    r"""
    Get the response into a `Streamer` of `bytes` from the body.
    """
    ...

text

text(encoding=None)

Get the text content with the response encoding, defaulting to utf-8 when unspecified.

Source code in python/wreq/blocking.py
def text(self, encoding: str | None = None) -> str:
    r"""
    Get the text content with the response encoding, defaulting to utf-8 when unspecified.
    """
    ...

json

json()

Get the JSON content of the response.

Source code in python/wreq/blocking.py
def json(self) -> Any:
    r"""
    Get the JSON content of the response.
    """

bytes

bytes()

Get the bytes content of the response.

Source code in python/wreq/blocking.py
def bytes(self) -> bytes:
    r"""
    Get the bytes content of the response.
    """
    ...

close

close()

Close the response.

This method closes the network connection regardless of whether connection pooling is enabled or not. It is recommended to use context managers (with statement) to properly manage response lifecycle instead of calling this method manually.

Source code in python/wreq/blocking.py
def close(self) -> None:
    r"""
    Close the response.

    This method closes the network connection regardless of whether connection pooling is
    enabled or not. It is recommended to use context managers (`with` statement) to properly
    manage response lifecycle instead of calling this method manually.
    """

WebSocket

A blocking WebSocket response.

Source code in python/wreq/blocking.py
class WebSocket:
    r"""
    A blocking WebSocket response.
    """

    status: StatusCode
    r"""
    Get the status code of the response.
    """

    version: Version
    r"""
    Get the HTTP version of the response.
    """

    headers: HeaderMap
    r"""
    Get the headers of the response.
    """

    cookies: Sequence[Cookie]
    r"""
    Get the cookies of the response.
    """

    remote_addr: SocketAddr | None
    r"""
    Get the remote address of the response.
    """

    local_addr: SocketAddr | None
    r"""
    Get the local address of the response.
    """

    protocol: str | None
    r"""
    Get the WebSocket protocol.
    """

    def recv(self, timeout: datetime.timedelta | None = None) -> Message | None:
        r"""
        Receive a message from the WebSocket.
        """

    def send(self, message: Message) -> None:
        r"""
        Send a message to the WebSocket.

        # Arguments

        * `message` - The message to send.
        """

    def send_all(self, messages: Sequence[Message]) -> None:
        r"""
        Send multiple messages to the WebSocket.

        # Arguments

        * `messages` - The sequence of messages to send.
        """

    def close(
        self,
        code: int | None = None,
        reason: str | None = None,
    ) -> None:
        r"""
        Close the WebSocket connection.

        # Arguments

        * `code` - An optional close code.
        * `reason` - An optional reason for closing.
        """

    def __enter__(self) -> Any: ...
    def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
    def __str__(self) -> str: ...

status instance-attribute

status

Get the status code of the response.

version instance-attribute

version

Get the HTTP version of the response.

headers instance-attribute

headers

Get the headers of the response.

cookies instance-attribute

cookies

Get the cookies of the response.

remote_addr instance-attribute

remote_addr

Get the remote address of the response.

local_addr instance-attribute

local_addr

Get the local address of the response.

protocol instance-attribute

protocol

Get the WebSocket protocol.

recv

recv(timeout=None)

Receive a message from the WebSocket.

Source code in python/wreq/blocking.py
def recv(self, timeout: datetime.timedelta | None = None) -> Message | None:
    r"""
    Receive a message from the WebSocket.
    """

send

send(message)

Send a message to the WebSocket.

Arguments
  • message - The message to send.
Source code in python/wreq/blocking.py
def send(self, message: Message) -> None:
    r"""
    Send a message to the WebSocket.

    # Arguments

    * `message` - The message to send.
    """

send_all

send_all(messages)

Send multiple messages to the WebSocket.

Arguments
  • messages - The sequence of messages to send.
Source code in python/wreq/blocking.py
def send_all(self, messages: Sequence[Message]) -> None:
    r"""
    Send multiple messages to the WebSocket.

    # Arguments

    * `messages` - The sequence of messages to send.
    """

close

close(code=None, reason=None)

Close the WebSocket connection.

Arguments
  • code - An optional close code.
  • reason - An optional reason for closing.
Source code in python/wreq/blocking.py
def close(
    self,
    code: int | None = None,
    reason: str | None = None,
) -> None:
    r"""
    Close the WebSocket connection.

    # Arguments

    * `code` - An optional close code.
    * `reason` - An optional reason for closing.
    """

Client

A blocking client for making HTTP requests.

Source code in python/wreq/blocking.py
class Client:
    r"""
    A blocking client for making HTTP requests.
    """

    cookie_jar: Jar | None
    r"""
    Get the cookie jar used by this client (if enabled/configured).

    Returns:
        - The provided `Jar` if the client was constructed with `cookie_provider=...`
        - The auto-created `Jar` if the client was constructed with `cookie_store=True`
    """

    def __init__(
        self,
        **kwargs: Unpack[ClientConfig],
    ) -> None:
        r"""
        Creates a new blocking Client instance.

        # Examples

        ```python
        import asyncio
        import wreq

        client = wreq.blocking.Client(
            user_agent="Mozilla/5.0",
            timeout=10,
        )
        response = client.get('https://httpbin.io/get')
        print(response.text())
        ```
        """
        ...

    def close(self) -> None:
        r"""
        Closes the client and any associated resources.

        After calling this method, the client should not be used to make further requests.

        Examples:

        ```python
        import asyncio
        import wreq

        client = wreq.blocking.Client()

        response = client.get('https://httpbin.io/get')
        print(response.text())

        client.close()
        ```
        """
        ...

    def request(
        self,
        method: Method,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given method and URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.request(Method.GET, "https://httpbin.io/anything")
        ```
        """
        ...

    def websocket(self, url: str, **kwargs: Unpack[WebSocketRequest]) -> "WebSocket":
        r"""
        Sends a WebSocket request.

        # Examples

        ```python
        import wreq
        import wreq.blocking

        client = wreq.blocking.Client()
        ws = client.websocket("wss://echo.websocket.org")
        ws.send(wreq.Message.from_text("Hello, WebSocket!"))
        message = ws.recv()
        print("Received:", message.data)
        ws.close()
        ```
        """
        ...

    def trace(
        self,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.trace("https://httpbin.io/anything")
        print(response.text())
        ```
        """
        ...

    def options(
        self,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.options("https://httpbin.io/anything")
        print(response.text())
        ```
        """
        ...

    def head(
        self,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.head("https://httpbin.io/anything")
        print(response.text())
        ```
        """
        ...

    def delete(
        self,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.delete("https://httpbin.io/anything")
        print(response.text())
        ```
        """
        ...

    def patch(
        self,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.patch("https://httpbin.io/anything", json={"key": "value"})
        print(response.text())
        ```
        """
        ...

    def put(
        self,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.put("https://httpbin.io/anything", json={"key": "value"})
        print(response.text())
        ```
        """
        ...

    def post(
        self,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.post("https://httpbin.io/anything", json={"key": "value"})
        print(response.text())
        ```
        """
        ...

    def get(
        self,
        url: str,
        **kwargs: Unpack[Request],
    ) -> "Response":
        r"""
        Sends a request with the given URL.

        # Examples

        ```python
        import wreq
        import wreq.blocking
        from wreq import Method

        client = wreq.blocking.Client()
        response = client.get("https://httpbin.io/anything")
        print(response.text())
        ```
        """
        ...

    def __enter__(self) -> Any: ...
    def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...

cookie_jar instance-attribute

cookie_jar

Get the cookie jar used by this client (if enabled/configured).

Returns:

Type Description
Jar | None
  • The provided Jar if the client was constructed with cookie_provider=...
Jar | None
  • The auto-created Jar if the client was constructed with cookie_store=True

__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 blocking Client instance.

Examples
import asyncio
import wreq

client = wreq.blocking.Client(
    user_agent="Mozilla/5.0",
    timeout=10,
)
response = client.get('https://httpbin.io/get')
print(response.text())

Parameters:

Name Type Description Default
emulation Emulation | Profile

Emulation config.

...
user_agent str

Sets the User-Agent header to be used by this client.

...
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 Referer header.

...
redirect Policy

Set a redirect.Policy for this client.

...
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 Client.

...
read_timeout timedelta

Set a timeout for only the read phase of a Client.

...
tcp_keepalive timedelta

Set that all sockets have SO_KEEPALIVE set with the supplied duration.

Default is 15 seconds.

...
tcp_keepalive_interval timedelta

Set that all sockets have SO_KEEPALIVE set with the supplied interval.

Default is 15 seconds.

...
tcp_keepalive_retries int

Set that all sockets have SO_KEEPALIVE set with the supplied retry count.

Default is 3 retries.

...
tcp_user_timeout timedelta

Set that all sockets have TCP_USER_TIMEOUT set with the supplied duration.

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 TCP_NODELAY enabled.

Default is True.

...
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 TlsInfo extension to responses.

...
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 proxies, so Client will use no proxy anymore.

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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 Content-Encoding response header.

...
brotli bool

Enable auto brotli decompression by checking the Content-Encoding response header.

...
deflate bool

Enable auto deflate decompression by checking the Content-Encoding response header.

...
zstd bool

Enable auto zstd decompression by checking the Content-Encoding response header.

...
Source code in python/wreq/blocking.py
def __init__(
    self,
    **kwargs: Unpack[ClientConfig],
) -> None:
    r"""
    Creates a new blocking Client instance.

    # Examples

    ```python
    import asyncio
    import wreq

    client = wreq.blocking.Client(
        user_agent="Mozilla/5.0",
        timeout=10,
    )
    response = client.get('https://httpbin.io/get')
    print(response.text())
    ```
    """
    ...

close

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

client = wreq.blocking.Client()

response = client.get('https://httpbin.io/get')
print(response.text())

client.close()
Source code in python/wreq/blocking.py
def close(self) -> None:
    r"""
    Closes the client and any associated resources.

    After calling this method, the client should not be used to make further requests.

    Examples:

    ```python
    import asyncio
    import wreq

    client = wreq.blocking.Client()

    response = client.get('https://httpbin.io/get')
    print(response.text())

    client.close()
    ```
    """
    ...

request

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.request(Method.GET, "https://httpbin.io/anything")

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def request(
    self,
    method: Method,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given method and URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.request(Method.GET, "https://httpbin.io/anything")
    ```
    """
    ...

websocket

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 wreq.blocking

client = wreq.blocking.Client()
ws = client.websocket("wss://echo.websocket.org")
ws.send(wreq.Message.from_text("Hello, WebSocket!"))
message = ws.recv()
print("Received:", message.data)
ws.close()

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/blocking.py
def websocket(self, url: str, **kwargs: Unpack[WebSocketRequest]) -> "WebSocket":
    r"""
    Sends a WebSocket request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    client = wreq.blocking.Client()
    ws = client.websocket("wss://echo.websocket.org")
    ws.send(wreq.Message.from_text("Hello, WebSocket!"))
    message = ws.recv()
    print("Received:", message.data)
    ws.close()
    ```
    """
    ...

trace

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.trace("https://httpbin.io/anything")
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def trace(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.trace("https://httpbin.io/anything")
    print(response.text())
    ```
    """
    ...

options

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.options("https://httpbin.io/anything")
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def options(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.options("https://httpbin.io/anything")
    print(response.text())
    ```
    """
    ...

head

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.head("https://httpbin.io/anything")
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def head(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.head("https://httpbin.io/anything")
    print(response.text())
    ```
    """
    ...

delete

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.delete("https://httpbin.io/anything")
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def delete(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.delete("https://httpbin.io/anything")
    print(response.text())
    ```
    """
    ...

patch

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.patch("https://httpbin.io/anything", json={"key": "value"})
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def patch(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.patch("https://httpbin.io/anything", json={"key": "value"})
    print(response.text())
    ```
    """
    ...

put

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.put("https://httpbin.io/anything", json={"key": "value"})
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def put(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.put("https://httpbin.io/anything", json={"key": "value"})
    print(response.text())
    ```
    """
    ...

post

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.post("https://httpbin.io/anything", json={"key": "value"})
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def post(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.post("https://httpbin.io/anything", json={"key": "value"})
    print(response.text())
    ```
    """
    ...

get

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 wreq.blocking
from wreq import Method

client = wreq.blocking.Client()
response = client.get("https://httpbin.io/anything")
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def get(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    client = wreq.blocking.Client()
    response = client.get("https://httpbin.io/anything")
    print(response.text())
    ```
    """
    ...

delete

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=...)

Shortcut method to quickly make a request.

Examples

import wreq
import wreq.blocking

response = wreq.blocking.delete("https://httpbin.io/anything")
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def delete(
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Shortcut method to quickly make a request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    response = wreq.blocking.delete("https://httpbin.io/anything")
    print(response.text())
    ```
    """
    ...

get

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=...)

Shortcut method to quickly make a request.

Examples

import wreq
import wreq.blocking

response = wreq.blocking.get("https://httpbin.io/anything")
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def get(
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Shortcut method to quickly make a request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    response = wreq.blocking.get("https://httpbin.io/anything")
    print(response.text())
    ```
    """
    ...

head

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=...)

Shortcut method to quickly make a request.

Examples

import wreq
import wreq.blocking

response = wreq.blocking.head("https://httpbin.io/anything")
print(response.status)

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def head(
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Shortcut method to quickly make a request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    response = wreq.blocking.head("https://httpbin.io/anything")
    print(response.status)
    ```
    """
    ...

options

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=...)

Shortcut method to quickly make a request.

Examples

import wreq
import wreq.blocking

response = wreq.blocking.options("https://httpbin.io/anything")
print(response.status)

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def options(
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Shortcut method to quickly make a request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    response = wreq.blocking.options("https://httpbin.io/anything")
    print(response.status)
    ```
    """
    ...

patch

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=...)

Shortcut method to quickly make a request.

Examples

import wreq
import wreq.blocking

response = wreq.blocking.patch("https://httpbin.io/anything", json={"key": "value"})
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def patch(
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Shortcut method to quickly make a request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    response = wreq.blocking.patch("https://httpbin.io/anything", json={"key": "value"})
    print(response.text())
    ```
    """
    ...

post

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=...)

Shortcut method to quickly make a request.

Examples

import wreq
import wreq.blocking

response = wreq.blocking.post("https://httpbin.io/anything", json={"key": "value"})
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def post(
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Shortcut method to quickly make a request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    response = wreq.blocking.post("https://httpbin.io/anything", json={"key": "value"})
    print(response.text())
    ```
    """
    ...

put

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=...)

Shortcut method to quickly make a request.

Examples

import wreq
import wreq.blocking

response = wreq.blocking.put("https://httpbin.io/anything", json={"key": "value"})
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def put(
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Shortcut method to quickly make a request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    response = wreq.blocking.put("https://httpbin.io/anything", json={"key": "value"})
    print(response.text())
    ```
    """
    ...

request

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=...)

Make a request with the given parameters.

Arguments

  • method - The method to use for the request.
  • url - The URL to send the request to.
  • **kwargs - Additional request parameters.

Examples

import wreq
import wreq.blocking
from wreq import Method

response = wreq.blocking.request(Method.GET, "https://www.rust-lang.org")
print(response.text())

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def request(
    method: Method,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Make a request with the given parameters.

    # Arguments

    * `method` - The method to use for the request.
    * `url` - The URL to send the request to.
    * `**kwargs` - Additional request parameters.

    # Examples

    ```python
    import wreq
    import wreq.blocking
    from wreq import Method

    response = wreq.blocking.request(Method.GET, "https://www.rust-lang.org")
    print(response.text())
    ```
    """
    ...

trace

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=...)

Shortcut method to quickly make a request.

Examples

import wreq
import wreq.blocking

response = wreq.blocking.trace("https://httpbin.io/anything")
print(response.status)

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:

  • Android
  • Fuchsia
  • Linux
  • macOS and macOS-like systems (iOS, tvOS, watchOS and visionOS)
  • Solaris and illumos

On Android, Linux, and Fuchsia, this uses the SO_BINDTODEVICE socket option. On macOS and macOS-like systems, Solaris, and illumos, this instead uses the IP_BOUND_IF and IPV6_BOUND_IF socket options (as appropriate).

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/blocking.py
def trace(
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Shortcut method to quickly make a request.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    response = wreq.blocking.trace("https://httpbin.io/anything")
    print(response.status)
    ```
    """
    ...

websocket

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=...)

Make a WebSocket connection with the given parameters.

Examples

import wreq
import wreq.blocking

ws = wreq.blocking.websocket("wss://echo.websocket.org")
ws.send(wreq.Message.from_text("Hello, World!"))
message = ws.recv()
print("Received:", message.data)
ws.close()

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/blocking.py
def websocket(
    url: str,
    **kwargs: Unpack[WebSocketRequest],
) -> "WebSocket":
    r"""
    Make a WebSocket connection with the given parameters.

    # Examples

    ```python
    import wreq
    import wreq.blocking

    ws = wreq.blocking.websocket("wss://echo.websocket.org")
    ws.send(wreq.Message.from_text("Hello, World!"))
    message = ws.recv()
    print("Received:", message.data)
    ws.close()
    ```
    """
    ...