Utilities#
Core Utilities#
- Module:
salespyforce.utils.core_utils
- Synopsis:
Collection of supporting utilities and functions to complement the primary modules
- Usage:
from salespyforce.utils import core_utils- Example:
encoded_string = core_utils.encode_url(decoded_string)- Created By:
Jeff Shurtliff
- Last Modified:
Jeff Shurtliff
- Modified Date:
28 Feb 2026
- salespyforce.utils.core_utils.display_warning(warn_msg: str) None[source]#
This function displays a
UserWarningmessage via thewarningsmodule.Deprecated since version 1.4.0: Use
salespyforce.errors.handlers.display_warning()instead.- Parameters:
warn_msg (str) – The message to be displayed
- Returns:
None
- salespyforce.utils.core_utils.download_image(image_url: str | None = None, file_name: str | None = None, file_path: str | None = None, response=None, extension: str = 'jpeg') str[source]#
This function downloads an image and saves it to a specified directory.
Changed in version 1.5.0: This function now raises more specific exceptions instead of the generic
RuntimeErrorexception.- Parameters:
image_url (str, None) – The absolute URL to the image
file_name (str, None) – The file name (including extension) to use as the file name (Default: randomly generated)
file_path (str, None) – File path where the image file should be saved (Default:
./)response – The response of the previously performed API call
extension (str) – The file extension to use if a file name with extension is not provided (Default:
jpeg)
- Returns:
The full path to the downloaded image
- Raises:
salespyforce.errors.exceptions.MissingRequiredDataError,salespyforce.errors.exceptions.GETRequestError
- salespyforce.utils.core_utils.ensure_ends_with(eval_string, suffix)[source]#
This function ensures that a string ends with a given suffix.
Added in version 1.5.0.
- salespyforce.utils.core_utils.ensure_starts_with(eval_string, prefix)[source]#
This function ensures that a string starts with a given prefix.
Added in version 1.5.0.
- salespyforce.utils.core_utils.get_18_char_id(record_id: str) str[source]#
This function converts a 15-character Salesforce record ID to its 18-character case-insensitive form.
Added in version 1.4.0.
- Parameters:
record_id (str) – The Salesforce record ID to convert (or return unchanged if already 18 characters)
- Returns:
The 18-character Salesforce record ID
- Raises:
- salespyforce.utils.core_utils.get_file_type(file_path: str) str[source]#
This function attempts to identify if a given file path is for a YAML or JSON file.
- Parameters:
file_path (str) – The full path to the file
- Returns:
The file type in string format (e.g.
yamlorjson)- Raises:
FileNotFoundError,salespyforce.errors.exceptions.UnknownFileTypeError
- salespyforce.utils.core_utils.get_image_ref_id(image_url: str) str[source]#
This function parses an image URL to identify the reference ID (refid) value. (Reference 1, Reference 2)
- Parameters:
image_url (str) – The URL of an image from within Salesforce
- Returns:
The reference ID (
refid) value
- salespyforce.utils.core_utils.get_random_string(length: int = 32, prefix_string: str = '') str[source]#
This function returns a random alphanumeric string.
- salespyforce.utils.core_utils.is_valid_salesforce_url(url: str) bool[source]#
This function evaluates a URL to determine if it is a valid Salesforce URL.
Added in version 1.4.0.
- Parameters:
url (str) – The URL to evaluate
- Returns:
Boolean value depending on whether the URL meets the criteria
- salespyforce.utils.core_utils.matches_regex_pattern(pattern: str, text: str, full_match: bool = False, must_start_with: bool = False) bool[source]#
This function compares a text string against a regex pattern and determines whether they match.
Added in version 1.4.0.
- Parameters:
- Returns:
True if the regex pattern matches anywhere in the text string
- Raises:
Helper Utilities#
- Module:
salespyforce.utils.helper
- Synopsis:
Module that allows the salespyforce library to leverage a helper configuration file
- Usage:
from salespyforce.utils import helper- Example:
helper_settings = helper.get_settings('/tmp/helper.yml', 'yaml')- Created By:
Jeff Shurtliff
- Last Modified:
Jeff Shurtliff
- Modified Date:
25 Feb 2026
- salespyforce.utils.helper.get_helper_settings(file_path: str, file_type: str = 'yaml', defined_settings: dict | None = None) dict[source]#
This function returns a dictionary of the defined helper settings.
Changed in version 1.5.0: The
file_typeparameter now accepts bothyamlandymlas file extensions for YAML.- Parameters:
- Returns:
Dictionary of helper variables
- Raises:
- salespyforce.utils.helper.import_helper_file(file_path: str, file_type: str) dict[source]#
This function imports a YAML (.yml, .yaml) or JSON (.json) helper config file.
Changed in version 1.5.0: The
file_typeparameter now accepts bothyamlandymlas file extensions for YAML.- Parameters:
- Returns:
The parsed configuration data
- Raises:
FileNotFoundError,salespyforce.errors.exceptions.InvalidHelperFileTypeError
Logging Utilities#
- Module:
salespyforce.utils.log_utils
- Synopsis:
Collection of logging utilities and functions
- Usage:
from salespyforce.utils import log_utils- Example:
logger = log_utils.initialize_logging(__name__)- Created By:
Jeff Shurtliff
- Last Modified:
Jeff Shurtliff
- Modified Date:
31 Dec 2025
- class salespyforce.utils.log_utils.LessThanFilter(exclusive_maximum, name='')[source]#
Bases:
FilterThis class allows filters to be set to limit log levels to only less than a specified level.
See also
Zoey Greer is the original author of this class which was provided on Stack Overflow.
- salespyforce.utils.log_utils.initialize_logging(logger_name=None, log_level=None, formatter=None, debug=None, no_output=None, file_output=None, file_log_level=None, log_file=None, overwrite_log_files=None, console_output=None, console_log_level=None, syslog_output=None, syslog_log_level=None, syslog_address=None, syslog_port=None)[source]#
This function initializes logging for the salespyforce library.
Version Utilities#
- Module:
salespyforce.utils.version
- Synopsis:
Utilities for working with the package version
- Created By:
Jeff Shurtliff
- Last Modified:
Jeff Shurtliff
- Modified Date:
19 Feb 2026
- salespyforce.utils.version.get_full_version() str[source]#
This function returns the current full version of the
salespyforcepackage.Changed in version 1.5.0: The function will now attempt to retrieve the version from the
pyproject.tomlfile if it cannot be retrieved via the package metadata.Changed in version 1.4.0: The function now retrieves the version from the package metadata, rather than from the
__version__special variable.The package version is retrieved from the installed package metadata, which is populated from the
versionfield inpyproject.toml.- Returns:
The current package version as a string
- salespyforce.utils.version.get_major_minor_version(full_version: str | None = None) str[source]#
Return the current major.minor (i.e., X.Y) version of the package.
Changed in version 1.5.0: The function now accepts an optional full version if already defined.
Changed in version 1.4.0: The function utilizes the
salespyforce.utils.version.get_full_version()function to get the package version rather than using__version__.- Parameters:
full_version (str, None) – The full package version (e.g. X.Y.Z)
- Returns:
The current package version (X.Y) as a string
- salespyforce.utils.version.get_version_from_pyproject(pyproject_path: str | None = None) str[source]#
This function retrieves the current version from the pyproject.toml file.
Added in version 1.5.0.
- Parameters:
pyproject_path (str, None) – The path to the pyproject.toml file (optional)
- Returns:
The current package version as a string