Utils
Auto-generated documentation for dynamo_query.utils module.
- dynamo-query / Modules / Dynamo Query / Utils
ascii_string_generator
def ascii_string_generator(length: int = 3) -> Iterator[str]:
Generator to build unique strings from “aa…a” to “zz…z”.
gen = ascii_string_generator()
next(gen) # 'aaa'
next(gen) # 'aab'
list(gen)[-1] # 'zzz'
Arguments
length- Length of a result string.
Yields
Lowercased ASCII string like “aaa”
chunkify
def chunkify(data: Iterable[_T], size: int) -> Iterator[List[_T]]:
Splits data to chunks of size length or less.
data = [1, 2, 3, 4, 5]
for chunk in chunkify(data, size=2):
print(chunk)
# [1, 2]
# [3, 4]
# [5]
Arguments
data- Data to chunkifysize- Max chunk size.
Returns
A generator of chunks.
get_format_keys
def get_format_keys(format_string: str) -> Set[str]:
Extract format keys from a formet-ready string.
keys = get_format_keys('key: {key} {value}')
keys # ['key', 'value']
Arguments
format_string- A format-ready string.
Returns
A set of format keys.
get_nested_item
def get_nested_item(
dict_obj: Dict[(str, Any)],
item_path: Iterable[str],
raise_errors: bool = False,
) -> Any:
Get nested item_path from dict_obj.
Arguments
dict_obj- Source dictionary.item_path- Keys list.raise_errors- Whether to raiseAttributeErroron not a dictionary item.
Raises
AttributeError- If nested item is not a dictionary.
pluralize
def pluralize(count: int, singular: str, plural: Optional[str] = None) -> str:
Pluralize a noun according to count.
Arguments
count- Count of objects.singular- Singular noun form.plural- Plural noun form. If not provided - appendsto singular form.
Returns
A noun in proper form.