API Reference

Response

class pywreck.Response(status: int, headers: Dict[str, str], data: bytes)[source]

HTTP Response Container

Request API

async pywreck.request(method: str, host: str, uri: str, payload: bytes = b'', headers: Optional[Mapping[str, str]] = None, port: int = 443, timeout: Optional[float] = 5.0, ssl: Union[bool, SSLContext] = True) Response[source]

Make a full HTTP request

Drives a full request/response cycle using the HTTP/1.1 protocol.

No exception handling is done for:

  • Malformed HTTP/1.1 responses

  • Network communication errors

The raw exceptions will be raised for any violation of HTTP/1.1 protocol.

Parameters:
  • method (str) – HTTP method string send in the request line.

  • host (str) – Host string controlling both the DNS request and the host header.

  • uri (str) – Request-Uniform Resource Identifier (URI), usually the absolute path to the resource being requested.

  • payload (bytes) – The encoded HTTP request body bytes to be sent.

  • headers (dict) – (optional) A dictionary of headers to be sent with the request. Default: {}

  • port (int) – (optional) The TCP port used for the connection. Default: 443

  • timeout (float) – (optional) Timeout in seconds for the request. Default: 5 seconds.

  • ssl (bool or ssl.SSLContext) – (optional) Indicates if SSL is to be used in establishing the connection. Also accepts an SSLContext object. Default: True

Return type:

Response

HTTP Method APIs

When using HTTP method functions directly, the method string does not have to be specified in the function call parameters.

Supported methods:

  • get

  • head

  • post

  • put

  • delete

Connection API

class pywreck.Connection(reader: StreamReader, writer: StreamWriter, lock: Lock, host: str, close_timeout: Optional[float])[source]

Streaming connection wrapper

Provides an interface to make HTTP requests via a streaming connection.

It is not recommended to instantiate Connection objects directly; use Connection.create() instead.

async classmethod create(host: str, port: int = 443, ssl: Union[bool, SSLContext] = True, close_timeout: Optional[float] = 5.0) Connection[source]

Create a Connection

Parameters:
  • host (str) – Host string controlling both the DNS request and the host header.

  • port (int) – (optional) The TCP port used for the connection. Default: 443

  • ssl (bool or ssl.SSLContext) – (optional) Indicates if SSL is to be used in establishing the connection. Also accepts an SSLContext object. Default: True

  • close_timeout (float) – (optional) The amount of time to wait in seconds for the connection to close before forcing the connection to close via TCP RST. Default: 5 seconds

Return type:

Connection

async request(method: str, uri: str, payload: bytes = b'', headers: Optional[Mapping[str, str]] = None, timeout: Optional[float] = 5.0) Response[source]

Make an HTTP request

Drives a full request/response cycle using the HTTP/1.1 protocol.

No exception handling is done for:

  • Malformed HTTP/1.1 responses

  • Network communication errors

The raw exceptions will be raised for any violation of HTTP/1.1 protocol.

Parameters:
  • method (str) – HTTP method string send in the request line.

  • uri (str) – Request-Uniform Resource Identifier (URI), usually the absolute path to the resource being requested.

  • payload (bytes) – (optional) The encoded HTTP request body bytes to be sent. Default: b””

  • headers (dict) – (optional) A dictionary of headers to be sent with the request. Default: {}

  • timeout (float) – (optional) Timeout in seconds for the request. Default: 5 seconds.

Return type:

Response

async close() None[source]

Close the connection