Pywrapid Webclient
Documentation coming soon
Configuration
Client settings: client_options: request options such as ssl settings, timeout etc.
Token settings: refresh_token_timeout: Time the auth provider specifies for refresh token expiry in seconds <default: 86400> access_token_timeout: The time for access token expiry in seconds, omit or set to 0 to use response body values from auth provider <default: 0> token_expiry_offset: Seconds before expiration time we will treat tokens as already expired to trigger early renewal <default: 10> access_token_header: Custom response header name to look for access token after authentication <default: ‘’>
Any additional configuration parameter passed in will be included in the credential objects config. Same goes for any extra key value pair passed as parameter at instantiation.
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:
objectWeb 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:
- __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:
- _unpack_jwt(token: str) dict[source]
Decodes and unpacks JWT tokens content
Does not include signature verification or encrypted parts
- 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:
- 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:
Credentials
- class WebCredentials[source]
Bases:
objectCredential base class
Init class for web credentials
- class BasicAuthCredentials(username: str, password: str, login_url: str = '', config: Type[WrapidConfig] | dict | None = None, **kwargs: dict[str, Any])[source]
Bases:
WebCredentialsCredential class for basic auth
Init class for web credentials
- class X509Credentials(cert_file: str = '', key_file: str = '', login_url: str = '', jwt_key: str = '', access_token_timeout: int = 0, token_expiry_offset: int = 0, config: Type[WrapidConfig] | dict | None = None, **kwargs: dict[str, Any])[source]
Bases:
WebCredentialsCredential class for x509 auth
Init class for web credentials
Client Exceptions
- exception ClientAuthorizationError[source]
Bases:
ClientErrorClient Authorization Error Exception
- exception ClientAuthenticationError[source]
Bases:
ClientErrorClient Authorization Error Exception
- exception ClientTokenRefreshError[source]
Bases:
ClientErrorToken Refresh Error Exception
- exception ClientTimeout[source]
Bases:
ClientErrorClient Timeout Exception
- exception ClientConnectionError[source]
Bases:
ClientErrorClient Connection Error Exception
- exception ClientHTTPError[source]
Bases:
ClientErrorClient HTTP Error Exception
Credential Exceptions
- exception CredentialCertificateFileError[source]
Bases:
CredentialErrorCredential Certificate Error Exception