.. module:: Utils Utils ========================= Common utility functions for data manipulation, string operations, and type conversions. Quick Examples -------------------------- String Utilities ~~~~~~~~~~~~~~~~ .. code-block:: python from core_mixins.utils import to_snake_case, random_string, to_one_line # Convert camelCase / PascalCase / acronyms to snake_case result = to_snake_case("myVariableName") # "my_variable_name" result = to_snake_case("HTTPSRequest") # "https_request" result = to_snake_case("parseHTTPSUrl") # "parse_https_url" # Generate random string token = random_string(length=32) # Convert multiline to single line text = """Line 1 Line 2 Line 3""" single = to_one_line(text) # "Line 1 Line 2 Line 3" Dictionary Utilities ~~~~~~~~~~~~~~~~~~~~ .. code-block:: python from core_mixins.utils import ( remove_attributes, rename_attributes, add_attributes, flatten_json ) data = {"name": "John", "age": 30, "email": "john@example.com"} # Remove attributes remove_attributes(data, ["email"]) # Rename attributes rename_attributes(data, {"age": "years"}) # Add missing attributes add_attributes(data, ["phone", "address"]) # Flatten nested JSON nested = {"user": {"name": "John", "details": {"age": 30}}} flat = flatten_json(nested) # {"user_name": "John", "user_details_age": 30} List Processing ~~~~~~~~~~~~~~~ .. code-block:: python from core_mixins.utils import get_batches items = list(range(10)) for batch in get_batches(items, n=3): print(batch) # [0, 1, 2] # [3, 4, 5] # [6, 7, 8] # [9] Data Type Conversion ~~~~~~~~~~~~~~~~~~~~ .. code-block:: python from core_mixins.utils import convert_data_type, bytes_to_str # Convert types in dictionary data = {"age": "30", "score": "95.5", "active": "true"} convert_data_type(data, {"age": "int", "score": "float", "active": "bool"}) # data = {"age": 30, "score": 95.5, "active": True} # Convert bytes to strings byte_data = {b"key": b"value", b"nested": [b"a", b"b"]} string_data = bytes_to_str(byte_data) # {"key": "value", "nested": ["a", "b"]} API Reference -------------------------- .. automodule:: core_mixins.utils :members: :undoc-members: :show-inheritance: