keycloak.connection

Connection manager module.

Classes

ConnectionManager

Represents a simple server connection.

Module Contents

class keycloak.connection.ConnectionManager(base_url, headers={}, timeout=60, verify=True, proxies=None, cert=None, max_retries=1)[source]

Bases: object

Represents a simple server connection.

Parameters:
  • base_url (str) – The server URL.

  • headers (dict) – The header parameters of the requests to the server.

  • timeout (int) – Timeout to use for requests to the server.

  • verify (Union[bool,str]) – Boolean value to enable or disable certificate validation or a string containing a path to a CA bundle to use

  • proxies (dict) – The proxies servers requests is sent by.

  • cert (Union[str,Tuple[str,str]]) – An SSL certificate used by the requested host to authenticate the client. Either a path to an SSL certificate file, or two-tuple of (certificate file, key file).

  • max_retries (int) – The total number of times to retry HTTP requests.

property base_url[source]

Return base url in use for requests to the server.

Returns:

Base URL

Return type:

str

property headers[source]

Return header request to the server.

Returns:

Request headers

Return type:

dict

property timeout[source]

Return timeout in use for request to the server.

Returns:

Timeout

Return type:

int

property verify[source]

Return verify in use for request to the server.

Returns:

Verify indicator

Return type:

bool

property cert[source]

Return client certificates in use for request to the server.

Returns:

Client certificate

Return type:

Union[str,Tuple[str,str]]

_s[source]
async_s[source]
async aclose()[source]

Close the async connection on delete.

__del__()[source]

Del method.

param_headers(key)[source]

Return a specific header parameter.

Parameters:

key (str) – Header parameters key.

Returns:

If the header parameters exist, return its value.

Return type:

str

clean_headers()[source]

Clear header parameters.

exist_param_headers(key)[source]

Check if the parameter exists in the header.

Parameters:

key (str) – Header parameters key.

Returns:

If the header parameters exist, return True.

Return type:

bool

add_param_headers(key, value)[source]

Add a single parameter inside the header.

Parameters:
  • key (str) – Header parameters key.

  • value (str) – Value to be added.

del_param_headers(key)[source]

Remove a specific parameter.

Parameters:

key (str) – Key of the header parameters.

raw_get(path, **kwargs)[source]

Submit get request to the path.

Parameters:
  • path (str) – Path for request.

  • kwargs (dict) – Additional arguments

Returns:

Response the request.

Return type:

Response

Raises:

KeycloakConnectionError – HttpError Can’t connect to server.

raw_post(path, data, **kwargs)[source]

Submit post request to the path.

Parameters:
  • path (str) – Path for request.

  • data (dict) – Payload for request.

  • kwargs (dict) – Additional arguments

Returns:

Response the request.

Return type:

Response

Raises:

KeycloakConnectionError – HttpError Can’t connect to server.

raw_put(path, data, **kwargs)[source]

Submit put request to the path.

Parameters:
  • path (str) – Path for request.

  • data (dict) – Payload for request.

  • kwargs (dict) – Additional arguments

Returns:

Response the request.

Return type:

Response

Raises:

KeycloakConnectionError – HttpError Can’t connect to server.

raw_delete(path, data=None, **kwargs)[source]

Submit delete request to the path.

Parameters:
  • path (str) – Path for request.

  • data (dict | None) – Payload for request.

  • kwargs (dict) – Additional arguments

Returns:

Response the request.

Return type:

Response

Raises:

KeycloakConnectionError – HttpError Can’t connect to server.

async a_raw_get(path, **kwargs)[source]

Submit get request to the path.

Parameters:
  • path (str) – Path for request.

  • kwargs (dict) – Additional arguments

Returns:

Response the request.

Return type:

Response

Raises:

KeycloakConnectionError – HttpError Can’t connect to server.

async a_raw_post(path, data, **kwargs)[source]

Submit post request to the path.

Parameters:
  • path (str) – Path for request.

  • data (dict) – Payload for request.

  • kwargs (dict) – Additional arguments

Returns:

Response the request.

Return type:

Response

Raises:

KeycloakConnectionError – HttpError Can’t connect to server.

async a_raw_put(path, data, **kwargs)[source]

Submit put request to the path.

Parameters:
  • path (str) – Path for request.

  • data (dict) – Payload for request.

  • kwargs (dict) – Additional arguments

Returns:

Response the request.

Return type:

Response

Raises:

KeycloakConnectionError – HttpError Can’t connect to server.

async a_raw_delete(path, data=None, **kwargs)[source]

Submit delete request to the path.

Parameters:
  • path (str) – Path for request.

  • data (dict | None) – Payload for request.

  • kwargs (dict) – Additional arguments

Returns:

Response the request.

Return type:

Response

Raises:

KeycloakConnectionError – HttpError Can’t connect to server.

static _filter_query_params(query_params)[source]

Explicitly filter query params with None values for compatibility.

Httpx and requests differ in the way they handle query params with the value None, requests does not include params with the value None while httpx includes them as-is.

Parameters:

query_params (dict) – the query params

Returns:

the filtered query params

Return type:

dict