Utils
Utility functions
koheesio.utils.PYTHON_MINOR_VERSION
module-attribute
#
float: Python minor version as a float (e.g. 3.7)
koheesio.utils.convert_str_to_bool #
Converts a string to a boolean if the string is either 'true' or 'false'
koheesio.utils.get_args_for_func #
Helper function that matches keyword arguments (params) on a given function
This function uses inspect to extract the signature on the passed Callable, and then uses functools.partial
to
construct a new Callable (partial) function on which the input was mapped.
Example
input_dict = {"a": "foo", "b": "bar"}
def example_func(a: str):
return a
func, kwargs = get_args_for_func(example_func, input_dict)
In this example,
- func
would be a callable with the input mapped toward it (i.e. can be called like any normal function)
- kwargs
would be a dict holding just the output needed to be able to run the function (e.g. {"a": "foo"})
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
The function to inspect |
required |
params
|
Dict
|
Dictionary with keyword values that will be mapped on the 'func' |
required |
Returns:
Type | Description |
---|---|
Tuple[Callable, Dict[str, Any]]
|
|
Source code in src/koheesio/utils.py
koheesio.utils.get_random_string #
Generate a random string of specified length
koheesio.utils.import_class #
Import class and module based on provided string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_class
|
str
|
|
required |
Returns:
Type | Description |
---|---|
object Class from specified input string.
|
|