Helpers

Shared utility functions for pykada.

Provides input validation helpers (require_non_empty_str(), check_user_external_id(), verify_csv_columns()), random-string generators, date/time format validators, and the copy_docstring_from() decorator used to propagate docstrings from client methods onto their functional wrapper equivalents.

pykada.helpers.remove_null_fields(obj)[source]

Removes fields with a value of None from a dictionary. :type obj: dict :param obj: :return: A dictionary with no values of None

Parameters:

obj (dict)

pykada.helpers.require_non_empty_str(value, field_name, idx=None)[source]

Ensures that a value is a non-empty string.

Parameters:
  • value (str) – The string value to check.

  • field_name (str) – The name of the field for error messaging.

  • idx (Optional[int]) – Optional index for context.

Raises:

ValueError – If value is not a non-empty string.

Return type:

None

pykada.helpers.check_user_external_id(user_id=None, external_id=None)[source]

Check if only one of user_id or external_id are provided. Throw an error if neither or both are provided. The AC API requires exactly one of these identifiers.

Parameters:
  • user_id (str) – The internal user identifier.

  • external_id (str) – The external user identifier.

Returns:

A dictionary containing the provided identifier.

pykada.helpers.verify_csv_columns(file_path, expected_headers_list)[source]

Verifies that a CSV file exists and contains exactly the columns specified in expected_headers_list. Column order does not matter.

Parameters:
  • file_path (str) – The path to the CSV file.

  • expected_headers_list (List[str]) – The exact column names expected in the CSV header.

Raises:
  • FileNotFoundError – If the file does not exist.

  • ValueError – If expected_headers_list is empty, the file has no header row, or the columns do not match.

Return type:

None

pykada.helpers.generate_random_alphanumeric_string(length=16)[source]

Generate a random alphanumeric string of the specified length.

pykada.helpers.generate_random_numeric_string(length=16)[source]

Generate a random numeric string of the specified length.

pykada.helpers.is_valid_date(date_str)[source]

Validates that a date string is in YYYY-MM-DD format.

Return type:

bool

Parameters:

date_str (str)

pykada.helpers.is_valid_time(time_str)[source]

Validates that a time string is in HH:MM format (00:00 to 23:59) with required leading zeros.

Return type:

bool

Parameters:

time_str (str)

pykada.helpers.copy_docstring_from(source_func, note=None)[source]

A decorator that copies and cleans the docstring from a source function and optionally appends a note to the end.