mex.common.connector package

Submodules

mex.common.connector.base module

class mex.common.connector.base.BaseConnector

Bases: object

Base class for connectors that are handled as singletons.

abstractmethod __init__() None

Create a new connector instance.

abstractmethod close() None

Close the connector’s underlying sockets.

final classmethod get() Self

Get the singleton instance for this class from the store.

metrics() dict[str, int]

Generate metrics about connector usage.

class mex.common.connector.base._ConnectorStore

Bases: SingletonStore[BaseConnector]

Thin wrapper for storing thread-local singletons of connectors.

metrics() dict[str, int]

Generate metrics about all active connectors.

reset() None

Close all connectors and remove them from the singleton store.

mex.common.connector.http module

class mex.common.connector.http.HTTPConnector

Bases: BaseConnector

Base class for requests-based HTTP connectors.

PROPORTIONAL_BACKOFF_MIN: int | float = 3
TIMEOUT: int | float = 10
TIMEOUT_MAX: int | float = 100
__init__() None

Create a new http connection.

_check_availability() None

Send a GET request to verify the host is available.

_send_request(method: str, url: str, params: Mapping[str, list[str] | str | None] | None, **kwargs: Any) Response

Send the request with advanced retrying rules.

_set_authentication() None

Authenticate to the host.

_set_session() None

Create and set request session.

abstractmethod _set_url() None

Set url of the host.

close() None

Close the connector’s underlying requests session.

request(method: Literal['OPTIONS', 'POST', 'GET', 'PUT', 'DELETE'], endpoint: str | None = None, payload: Any = None, params: Mapping[str, list[str] | str | None] | None = None, **kwargs: Any) dict[str, Any]

Prepare and send a request with error handling and payload de/serialization.

Parameters:
  • method – HTTP method to use

  • endpoint – Path to API endpoint to be prefixed with host and version

  • payload – Data to be serialized as JSON using the MExEncoder

  • params – Dictionary to be sent in the query string of the request

  • kwargs – Further keyword arguments passed to requests

Raises:
  • RequestException – Error from requests that can’t be solved with a retry

  • HTTPError – Re-raised HTTP error with (truncated) response body

  • JSONDecodeError – If body of response cannot be parsed correctly

Returns:

Parsed JSON body of the response

request_raw(method: Literal['OPTIONS', 'POST', 'GET', 'PUT', 'DELETE'], endpoint: str | None = None, payload: Any = None, params: Mapping[str, list[str] | str | None] | None = None, **kwargs: Any) Response

Prepare and send a raw request with error handling and payload serialization.

Parameters:
  • method – HTTP method to use

  • endpoint – Path to API endpoint to be prefixed with host and version

  • payload – Data to be serialized as JSON using the MExEncoder

  • params – Dictionary to be sent in the query string of the request

  • kwargs – Further keyword arguments passed to requests

Raises:
  • RequestException – Error from requests that can’t be solved with a retry

  • HTTPError – Re-raised HTTP error with (truncated) response body

Returns:

Response object for the request

url: str = ''

mex.common.connector.utils module

mex.common.connector.utils.bounded_backoff(min_time: float, max_time: float) Callable[[TimedRequestException], int | float]

Get a function to calculate a bounded backoff time.

Module contents

class mex.common.connector.BaseConnector

Bases: object

Base class for connectors that are handled as singletons.

abstractmethod __init__() None

Create a new connector instance.

abstractmethod close() None

Close the connector’s underlying sockets.

classmethod get() Self

Get the singleton instance for this class from the store.

metrics() dict[str, int]

Generate metrics about connector usage.

class mex.common.connector.HTTPConnector

Bases: BaseConnector

Base class for requests-based HTTP connectors.

PROPORTIONAL_BACKOFF_MIN: int | float = 3
TIMEOUT: int | float = 10
TIMEOUT_MAX: int | float = 100
__init__() None

Create a new http connection.

_check_availability() None

Send a GET request to verify the host is available.

_send_request(method: str, url: str, params: Mapping[str, list[str] | str | None] | None, **kwargs: Any) Response

Send the request with advanced retrying rules.

_set_authentication() None

Authenticate to the host.

_set_session() None

Create and set request session.

abstractmethod _set_url() None

Set url of the host.

close() None

Close the connector’s underlying requests session.

request(method: Literal['OPTIONS', 'POST', 'GET', 'PUT', 'DELETE'], endpoint: str | None = None, payload: Any = None, params: Mapping[str, list[str] | str | None] | None = None, **kwargs: Any) dict[str, Any]

Prepare and send a request with error handling and payload de/serialization.

Parameters:
  • method – HTTP method to use

  • endpoint – Path to API endpoint to be prefixed with host and version

  • payload – Data to be serialized as JSON using the MExEncoder

  • params – Dictionary to be sent in the query string of the request

  • kwargs – Further keyword arguments passed to requests

Raises:
  • RequestException – Error from requests that can’t be solved with a retry

  • HTTPError – Re-raised HTTP error with (truncated) response body

  • JSONDecodeError – If body of response cannot be parsed correctly

Returns:

Parsed JSON body of the response

request_raw(method: Literal['OPTIONS', 'POST', 'GET', 'PUT', 'DELETE'], endpoint: str | None = None, payload: Any = None, params: Mapping[str, list[str] | str | None] | None = None, **kwargs: Any) Response

Prepare and send a raw request with error handling and payload serialization.

Parameters:
  • method – HTTP method to use

  • endpoint – Path to API endpoint to be prefixed with host and version

  • payload – Data to be serialized as JSON using the MExEncoder

  • params – Dictionary to be sent in the query string of the request

  • kwargs – Further keyword arguments passed to requests

Raises:
  • RequestException – Error from requests that can’t be solved with a retry

  • HTTPError – Re-raised HTTP error with (truncated) response body

Returns:

Response object for the request

url: str = ''