Module
pixano.utils.python
Functions
def
estimate_folder_size
(folder_path)
→ str Estimate a folder size and return it as a human-readable string.
Args:
folder_path: Folder path.
Returns:
Folder size as a human-readable string.
| Parameter | Type | Default |
|---|---|---|
folder_path | Path | — |
def
fn_sort_dict
(dict_, order_by, descending)
→ tuple[Any, ...] Function to sort a dictionary by multiple keys in different orders.
Args:
dict_: Dictionary to sort.
order_by: List of keys to sort by.
descending: List of booleans indicating the order for each key.
| Parameter | Type | Default |
|---|---|---|
dict_ | dict[str, Any] | — |
order_by | list[str] | — |
descending | list[bool] | — |
def
get_super_type_from_dict
(sub_type, dict_types)
→ type | None Get the first super type in a dictionary of types for the given type.
Args:
sub_type: Sub type to find the super type for.
dict_types: Dictionary of types.
Returns:
Super type if found, None otherwise.
| Parameter | Type | Default |
|---|---|---|
sub_type | type | — |
dict_types | dict[str, type] | — |
def
natural_key
(string)
→ list Return key for string natural sort.
Args:
string: Input string.
Returns:
Sort key.
| Parameter | Type | Default |
|---|---|---|
string | str | — |
def
quote_sql_string
(value)
→ str Quote a string as a SQL string literal, escaping embedded single quotes.
Args:
value: The raw string.
Returns:
A SQL string literal, e.g. ``O'Brien`` -> ``'O''Brien'``.
| Parameter | Type | Default |
|---|---|---|
value | str | — |
def
to_snake_case
(value)
→ str Transform a string into a snake_case identifier (used for dataset folder names).
| Parameter | Type | Default |
|---|---|---|
value | str | — |
def
to_sql_list
(ids)
→ str Convert an id, or a collection of ids, into a SQL ``IN``-list literal.
Single quotes inside ids are escaped (doubled), so the result is a valid,
injection-safe SQL list even for ids containing ``'``. An empty collection
yields ``(NULL)`` — a list that matches nothing — rather than raising, so a
filtered query with no candidate ids degrades to an empty result instead of
a 500.
Args:
ids: A single id, or a sequence/set of ids.
Returns:
A SQL list literal such as ``('a', 'b')`` or ``(NULL)``.
| Parameter | Type | Default |
|---|---|---|
ids | str | Sequence[str] | set[str] | — |
def
unique_list
(sequence)
→ list[Any] Select unique elements in a list while keeping order.
Args:
sequence: Input sequence.
Returns:
List of unique elements.
| Parameter | Type | Default |
|---|---|---|
sequence | Sequence[Any] | — |