Skip to content

rnet.blocking

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

rnet.blocking

Response

A blocking response from a request.

Source code in rnet/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.
    """

    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) -> str:
        r"""
        Get the text content of the response.
        """
        ...

    def text_with_charset(self, encoding: str) -> str:
        r"""
        Get the full response text given a specific encoding.
        """
        ...

    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 connection.
        """

    def __enter__(self) -> "Response": ...
    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 rnet/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 rnet/blocking.py
def stream(self) -> Streamer:
    r"""
    Get the response into a `Streamer` of `bytes` from the body.
    """
    ...

text

text()

Get the text content of the response.

Source code in rnet/blocking.py
def text(self) -> str:
    r"""
    Get the text content of the response.
    """
    ...

text_with_charset

text_with_charset(encoding)

Get the full response text given a specific encoding.

Source code in rnet/blocking.py
def text_with_charset(self, encoding: str) -> str:
    r"""
    Get the full response text given a specific encoding.
    """
    ...

json

json()

Get the JSON content of the response.

Source code in rnet/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 rnet/blocking.py
def bytes(self) -> bytes:
    r"""
    Get the bytes content of the response.
    """
    ...

close

close()

Close the response connection.

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

WebSocket

A blocking WebSocket response.

Source code in rnet/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.
    """

    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) -> "WebSocket": ...
    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.

protocol instance-attribute

protocol

Get the WebSocket protocol.

recv

recv(timeout=None)

Receive a message from the WebSocket.

Source code in rnet/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 rnet/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 rnet/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 rnet/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 rnet/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 rnet

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

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

        # Examples

        ```python
        import rnet
        from rnet import Method

        client = rnet.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 rnet

        client = rnet.blocking.Client()
        ws = client.websocket("wss://echo.websocket.org")
        ws.send(rnet.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 rnet
        from rnet import Method

        client = rnet.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 rnet
        from rnet import Method

        client = rnet.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 rnet
        from rnet import Method

        def main():
        client = rnet.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 rnet
        from rnet import Method

        client = rnet.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 rnet
        from rnet import Method

        client = rnet.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 rnet
        from rnet import Method

        client = rnet.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 rnet
        from rnet import Method

        client = rnet.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 rnet
        from rnet import Method

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

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__(**kwargs)

Creates a new blocking Client instance.

Examples
import asyncio
import rnet

client = rnet.blocking.Client(
    user_agent="Mozilla/5.0",
    timeout=10,
)
response = client.get('https://httpbin.io/get')
print(response.text())
Source code in rnet/blocking.py
def __init__(
    self,
    **kwargs: Unpack[ClientConfig],
) -> None:
    r"""
    Creates a new blocking Client instance.

    # Examples

    ```python
    import asyncio
    import rnet

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

request

request(method, url, **kwargs)

Sends a request with the given method and URL.

Examples
import rnet
from rnet import Method

client = rnet.blocking.Client()
response = client.request(Method.GET, "https://httpbin.io/anything")
Source code in rnet/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 rnet
    from rnet import Method

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

websocket

websocket(url, **kwargs)

Sends a WebSocket request.

Examples
import rnet

client = rnet.blocking.Client()
ws = client.websocket("wss://echo.websocket.org")
ws.send(rnet.Message.from_text("Hello, WebSocket!"))
message = ws.recv()
print("Received:", message.data)
ws.close()
Source code in rnet/blocking.py
def websocket(self, url: str, **kwargs: Unpack[WebSocketRequest]) -> "WebSocket":
    r"""
    Sends a WebSocket request.

    # Examples

    ```python
    import rnet

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

trace

trace(url, **kwargs)

Sends a request with the given URL.

Examples
import rnet
from rnet import Method

client = rnet.blocking.Client()
response = client.trace("https://httpbin.io/anything")
print(response.text())
Source code in rnet/blocking.py
def trace(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import rnet
    from rnet import Method

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

options

options(url, **kwargs)

Sends a request with the given URL.

Examples
import rnet
from rnet import Method

client = rnet.blocking.Client()
response = client.options("https://httpbin.io/anything")
print(response.text())
Source code in rnet/blocking.py
def options(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import rnet
    from rnet import Method

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

head

head(url, **kwargs)

Sends a request with the given URL.

Examples
import rnet
from rnet import Method

def main():
client = rnet.blocking.Client()
response = client.head("https://httpbin.io/anything")
print(response.text())
Source code in rnet/blocking.py
def head(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import rnet
    from rnet import Method

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

delete

delete(url, **kwargs)

Sends a request with the given URL.

Examples
import rnet
from rnet import Method

client = rnet.blocking.Client()
response = client.delete("https://httpbin.io/anything")
print(response.text())
Source code in rnet/blocking.py
def delete(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import rnet
    from rnet import Method

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

patch

patch(url, **kwargs)

Sends a request with the given URL.

Examples
import rnet
from rnet import Method

client = rnet.blocking.Client()
response = client.patch("https://httpbin.io/anything", json={"key": "value"})
print(response.text())
Source code in rnet/blocking.py
def patch(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import rnet
    from rnet import Method

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

put

put(url, **kwargs)

Sends a request with the given URL.

Examples
import rnet
from rnet import Method

client = rnet.blocking.Client()
response = client.put("https://httpbin.io/anything", json={"key": "value"})
print(response.text())
Source code in rnet/blocking.py
def put(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import rnet
    from rnet import Method

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

post

post(url, **kwargs)

Sends a request with the given URL.

Examples
import rnet
from rnet import Method

client = rnet.blocking.Client()
response = client.post("https://httpbin.io/anything", json={"key": "value"})
print(response.text())
Source code in rnet/blocking.py
def post(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import rnet
    from rnet import Method

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

get

get(url, **kwargs)

Sends a request with the given URL.

Examples
import rnet
from rnet import Method

client = rnet.blocking.Client()
response = client.get("https://httpbin.io/anything")
print(response.text())
Source code in rnet/blocking.py
def get(
    self,
    url: str,
    **kwargs: Unpack[Request],
) -> "Response":
    r"""
    Sends a request with the given URL.

    # Examples

    ```python
    import rnet
    from rnet import Method

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