Pywrapid Webclient

Documentation coming soon

Webclient

class WebClient(authorization_type: AuthorizationType = AuthorizationType.NONE, credentials: Type[WebCredentials] | None = None, dict_config: dict | None = None, wrapid_config: Type[WrapidConfig] | None = None)[source]

Bases: object

Web Client base

Generic web client class as base for creating application specific clients or to be used directly as a general use web client. Wraps the request library and adds generic exceptions.

Passes web calls transparently to requests, meaning you can use any requests option you see fit, such as proxy settings etc by passing them as key word arguments. If a configuration section named client_options is passed to the client, these options will be set for the web communication. Passed arguments will have precedence over configuration items.

The client allows you to mix and match authetication types with authorization types to fit strange combinations used in some APIs.

Can be used with a wrapid config or straight up dict config for use in clients extending this class.

Allows raise of exception on non-2xx responses (optional).

Init function for web client class

Parameters:
  • authorization_type (AuthorizationType (ENUM), optional) – wrapid authorization type to use for clients communication.

  • credentials (Type[WebCredentials], optional) – wrapid credentials object to use for clients communication.

  • dict_config (dict, optional, mutually exlusive with wrapid_conf) – dict object to store in the clients config parameter.

  • wrapid_config (Type[WrapidConfig], optional, mutually exlusive with dict_config) – wrapid configuration object to store configuration in the clients config parameter from.

Raises:

ClientException

__init__(authorization_type: AuthorizationType = AuthorizationType.NONE, credentials: Type[WebCredentials] | None = None, dict_config: dict | None = None, wrapid_config: Type[WrapidConfig] | None = None)[source]

Init function for web client class

Parameters:
  • authorization_type (AuthorizationType (ENUM), optional) – wrapid authorization type to use for clients communication.

  • credentials (Type[WebCredentials], optional) – wrapid credentials object to use for clients communication.

  • dict_config (dict, optional, mutually exlusive with wrapid_conf) – dict object to store in the clients config parameter.

  • wrapid_config (Type[WrapidConfig], optional, mutually exlusive with dict_config) – wrapid configuration object to store configuration in the clients config parameter from.

Raises:

ClientException

_unpack_jwt(token: str) dict[source]

Decodes and unpacks JWT tokens content

Does not include signature verification or encrypted parts

Parameters:

token (str) – Token to unpack

Returns:

Unpacked JWT token

Return type:

dict

call(method: str, url: str, raise_for_status: bool = False, skip_authentication: bool = False, **options: Any) Response[source]

Send web request to the target url

Parameters:
  • method (str) – Method of the HTTP request

  • url (str) – URL of the request

  • raise_for_status (bool) – Raise for non 2xx repsonses

  • skip_authentication (bool) – Skip authentication and skip token refresh controls

  • **options (dict) – request options

Raises:
Returns:

requests.Response object

Return type:

Response

generate_session(method: str = 'POST', **options: Any) None[source]

Authenticate and generate new token

Parameters:

method (str, optional) – HTTP Method to use. Defaults to “POST”.

Raises:

ClientAuthenticationError

property get_config: dict

Get current configuration

Returns:

configuration {dict} – Dict representation of configuration

session_expired() bool[source]

Check if our session has expired

Returns:

True if token is expired, False if still valid

Return type:

bool

Credentials

class WebCredentials(login_url: str = '')[source]

Bases: object

Credential base class

Init class for web credentials

property login_url: str

Getter for login url

property options: dict

Getter for options

class BasicAuthCredentials(username: str, password: str, login_url: str = '', config: Type[WrapidConfig] | dict | None = None)[source]

Bases: WebCredentials

Credential class for basic auth

Init class for web credentials

class X509Credentials(cert_file: str = '', key_file: str = '', login_url: str = '', config: Type[WrapidConfig] | dict | None = None)[source]

Bases: WebCredentials

Credential class for x509 auth

Init class for web credentials

Client Exceptions

exception ClientException[source]

Bases: Exception

Base Client Exception

exception ClientError[source]

Bases: ClientException

Client Error Exception

exception ClientAuthorizationError[source]

Bases: ClientError

Client Authorization Error Exception

exception ClientAuthenticationError[source]

Bases: ClientError

Client Authorization Error Exception

exception ClientTokenRefreshError[source]

Bases: ClientError

Token Refresh Error Exception

exception ClientTimeout[source]

Bases: ClientError

Client Timeout Exception

exception ClientConnectionError[source]

Bases: ClientError

Client Connection Error Exception

exception ClientHTTPError[source]

Bases: ClientError

Client HTTP Error Exception

exception ClientURLError[source]

Bases: ClientError

Client URL Error Exception

Credential Exceptions

exception CredentialException[source]

Bases: Exception

Credential Certificate Error Exception

exception CredentialError[source]

Bases: CredentialException

Credential Certificate Error Exception

exception CredentialCertificateFileError[source]

Bases: CredentialError

Credential Certificate Error Exception

exception CredentialKeyFileError[source]

Bases: CredentialError

Credential Key Error Exception

exception CredentialURLError[source]

Bases: CredentialError

Credential URL Error Exception