kakaowork.utils module

kakaowork.utils.drop_none(value: Dict) Dict

Drop none value in the dict.

Parameters

value – A dict value

Returns

A dict without none value

Examples

>>> drop_none({'key': 'value', 'nokey': None})
{'key': 'value'}
kakaowork.utils.is_bool(text: Union[str, bytes]) bool

Whether a string can be cast to a bool type.

Parameters

text – A text to check type

Returns

True if it can be cast to a bool type, False otherwise.

Examples

>>> is_bool('true')
True
>>> is_bool('yes')
True
>>> is_bool('123')
False
kakaowork.utils.is_float(text: Union[str, bytes]) bool

Whether a string can be cast to a float type.

Parameters

text – A text to check type

Returns

True if it can be cast to a float type, False otherwise.

Examples

>>> is_float('1.0')
True
>>> is_float('123')
False
kakaowork.utils.is_int(text: Union[str, bytes]) bool

Whether a string can be cast to an int type.

Parameters

text – A text to check type

Returns

True if it can be cast to an int type, False otherwise.

Examples

>>> is_int('123')
True
>>> is_int('1.0')
False
kakaowork.utils.json_default(value: Any) Any

Returns defaults for JSON serialization.

Parameters

value – Any instance

Returns

Serializable value

Raises

TypeError – If the ‘value’ is not supported for serialization.

kakaowork.utils.normalize_token(token: str) str

Returns normalized token.

Parameters

token – A string to normalize

Returns

A normalized token

Examples

>>> normalize_token('to_str')
'to-str'
>>> normalize_token('TO_STR')
'to-str'
kakaowork.utils.parse_kv_pairs(line: str) Dict[str, Any]

Returns parsed key-value pairs from a text.

Parameters

line – A string text

Returns

a dict from parsed key-value pairs text

Examples

>>> parse_kv_pairs('key=value')
{'key': 'value'}
>>> parse_kv_pairs("key1=value1 key2='value2,still_value2,not_key1=\"not_value1\"'")
{'key1': 'value1', 'key2': 'value2,still_value2,not_key1="not_value1"'}
kakaowork.utils.text2bool(text: Union[str, bytes]) bool

Returns the text as a boolean value.

Parameters

text – A text to be cast as a boolean type.

Returns

True if it can be cast to a boolean type and its value is true, False otherwise.

Examples

>>> text2bool('true')
True
>>> text2bool('yes')
True
>>> text2bool('false')
False
>>> text2bool('123')
False
kakaowork.utils.to_kst(timestamp: Union[int, datetime]) datetime

Returns KST(Korea Standard Time) from timestamp.

Parameters

timestamp – an unix timestamp or a datetime instance

Returns

a KST timezone datetime instance

Raises

ValueError – If the ‘timestamp’ is not one of int or datetime type.