seaworthy.client

A requests-based HTTP client for interacting with containers that have forwarded ports.

class ContainerHttpClient(host, port, url_defaults=None, session=None)[source]

HTTP client for a specific container.

In most cases, these should be obtained from ContainerDefinition.http_client() instead of being instantiated directly.

close()[source]

Closes the underlying Session object.

delete(path=None, url_kwargs=None, **kwargs)[source]

Sends a PUT request.

Parameters:
  • path – The HTTP path (either absolute or relative).
  • url_kwargs – Parameters to override in the generated URL. See ~hyperlink.URL.
  • **kwargs

    Optional arguments that request takes.

Returns:

response object

classmethod for_container(container, container_port=None)[source]
Parameters:
  • container – The container to make requests against.
  • container_port – The container port to make requests against. If None, the first container port is used.
Returns:

A ContainerClient object configured to make requests to the container.

get(path=None, url_kwargs=None, **kwargs)[source]

Sends a GET request.

Parameters:
  • path – The HTTP path (either absolute or relative).
  • url_kwargs – Parameters to override in the generated URL. See ~hyperlink.URL.
  • **kwargs

    Optional arguments that request takes.

Returns:

response object

head(path=None, url_kwargs=None, **kwargs)[source]

Sends a HEAD request.

Parameters:
  • path – The HTTP path (either absolute or relative).
  • url_kwargs – Parameters to override in the generated URL. See ~hyperlink.URL.
  • **kwargs

    Optional arguments that request takes.

Returns:

response object

options(path=None, url_kwargs=None, **kwargs)[source]

Sends an OPTIONS request.

Parameters:
  • path – The HTTP path (either absolute or relative).
  • url_kwargs – Parameters to override in the generated URL. See ~hyperlink.URL.
  • **kwargs

    Optional arguments that request takes.

Returns:

response object

patch(path=None, url_kwargs=None, **kwargs)[source]

Sends a PUT request.

Parameters:
  • path – The HTTP path (either absolute or relative).
  • url_kwargs – Parameters to override in the generated URL. See ~hyperlink.URL.
  • **kwargs

    Optional arguments that request takes.

Returns:

response object

post(path=None, url_kwargs=None, **kwargs)[source]

Sends a POST request.

Parameters:
  • path – The HTTP path (either absolute or relative).
  • url_kwargs – Parameters to override in the generated URL. See ~hyperlink.URL.
  • **kwargs

    Optional arguments that request takes.

Returns:

response object

put(path=None, url_kwargs=None, **kwargs)[source]

Sends a PUT request.

Parameters:
  • path – The HTTP path (either absolute or relative).
  • url_kwargs – Parameters to override in the generated URL. See ~hyperlink.URL.
  • **kwargs

    Optional arguments that request takes.

Returns:

response object

request(method, path=None, url_kwargs=None, **kwargs)[source]

Make a request against a container.

Parameters:
  • method – The HTTP method to use.
  • path (list) – The HTTP path (either absolute or relative).
  • url_kwargs (dict) – Parameters to override in the generated URL. See ~hyperlink.URL.
  • kwargs – Any other parameters to pass to Requests.
wait_for_response(client, timeout, path='/', expected_status_code=None)[source]

Try make a GET request with an HTTP client against a certain path and return once any response has been received, ignoring any errors.

Parameters:
  • client (ContainerHttpClient) – The HTTP client to use to connect to the container.
  • timeout – Timeout value in seconds.
  • path – HTTP path to request.
  • expected_status_code (int) – If set, wait until a response with this status code is received. If not set, the status code will not be checked.
Raises:

TimeoutError – If a request fails to be made within the timeout period.