{"id":3428,"library":"camel-converter","title":"Camel Converter","description":"Camel Converter is a Python library designed to effortlessly convert strings and dictionary keys between camel case, snake case, and pascal case. It's particularly useful for handling JSON data where keys are often in camelCase, facilitating seamless integration with Python's snake_case conventions. The library also provides decorators for automatic dictionary key conversion in function returns and offers integration with Pydantic models. The current version is 5.1.0.","status":"active","version":"5.1.0","language":"en","source_language":"en","source_url":"https://github.com/sanders41/camel-converter","tags":["case-conversion","camel-case","snake-case","pascal-case","pydantic","json-conversion"],"install":[{"cmd":"pip install camel-converter","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for using the `CamelBase` Pydantic model integration.","package":"pydantic","optional":true}],"imports":[{"symbol":"to_snake","correct":"from camel_converter import to_snake"},{"symbol":"to_camel","correct":"from camel_converter import to_camel"},{"symbol":"to_pascal","correct":"from camel_converter import to_pascal"},{"symbol":"dict_to_snake","correct":"from camel_converter import dict_to_snake"},{"symbol":"dict_to_camel","correct":"from camel_converter import dict_to_camel"},{"symbol":"dict_to_pascal","correct":"from camel_converter import dict_to_pascal"},{"symbol":"dict_to_snake (decorator)","correct":"from camel_converter.decorators import dict_to_snake"},{"symbol":"dict_to_camel (decorator)","correct":"from camel_converter.decorators import dict_to_camel"},{"symbol":"dict_to_pascal (decorator)","correct":"from camel_converter.decorators import dict_to_pascal"},{"note":"Requires Pydantic to be installed separately.","symbol":"CamelBase","correct":"from camel_converter.pydantic_base import CamelBase"}],"quickstart":{"code":"from camel_converter import to_snake, to_camel, dict_to_snake\nfrom camel_converter.decorators import dict_to_camel\nfrom pydantic import BaseModel # For CamelBase example\n\n# String conversion\nsnake_case_string = to_snake('myCamelCaseString')\nprint(f\"'myCamelCaseString' to snake_case: {snake_case_string}\")\n\ncamel_case_string = to_camel('my_snake_case_string')\nprint(f\"'my_snake_case_string' to camelCase: {camel_case_string}\")\n\n# Dictionary key conversion\ncamel_dict = {'firstName': 'John', 'lastName': 'Doe', 'dateOfBirth': '1990-01-01'}\nsnake_dict = dict_to_snake(camel_dict)\nprint(f\"CamelCase dict to snake_case: {snake_dict}\")\n\n# Decorator usage\n@dict_to_camel\ndef get_data_from_db() -> dict:\n    # Simulate fetching data with snake_case keys\n    return {'user_id': 123, 'user_name': 'test_user'}\n\napi_response = get_data_from_db()\nprint(f\"Decorated function output (snake_case to camelCase): {api_response}\")\n\n# Pydantic integration (requires 'pydantic' to be installed)\ntry:\n    from camel_converter.pydantic_base import CamelBase\n\n    class User(CamelBase):\n        first_name: str\n        last_name: str\n\n    user_data_camel = {'firstName': 'Jane', 'lastName': 'Smith'}\n    user_obj = User(**user_data_camel)\n    print(f\"Pydantic CamelBase model from camelCase input: {user_obj.first_name} {user_obj.last_name}\")\nexcept ImportError:\n    print(\"Pydantic not installed. Skipping CamelBase example.\")","lang":"python","description":"This quickstart demonstrates basic string and dictionary key conversion using `to_snake`, `to_camel`, `dict_to_snake`, and decorator-based conversion with `dict_to_camel`. It also includes an example of using `CamelBase` for Pydantic models, which automatically handles camelCase to snake_case mapping for model instantiation."},"warnings":[{"fix":"For deeply nested structures, manually apply `dict_to_snake` or `dict_to_camel` at each level, or consider a custom recursive function.","message":"The library directly converts strings or dictionary keys. For converting complex nested structures (lists of dictionaries, deeply nested dictionaries), ensure you apply the conversion functions recursively or use tools built for such scenarios.","severity":"gotcha","affected_versions":"All"},{"fix":"Be aware that dictionaries with mixed key types will only have their string keys transformed. If non-string keys need transformation (e.g., `(1, 'someValue')` to `(1, 'some_value')`), convert them explicitly before or after processing.","message":"When using `dict_to_snake`, `dict_to_camel`, or `dict_to_pascal`, only string keys are converted. Non-string keys (e.g., integers, tuples) in a dictionary will be left unchanged in the output.","severity":"gotcha","affected_versions":"All"},{"fix":"Install Pydantic separately via `pip install pydantic` if you intend to use `CamelBase` for Pydantic model definitions.","message":"The `CamelBase` Pydantic integration requires Pydantic to be installed as an additional dependency. It is not part of the `camel-converter` core package dependencies.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure your environment uses Python 3.10 or a newer version.","message":"The library explicitly requires Python 3.10 or newer. Attempting to install or run it on older Python versions will result in compatibility errors.","severity":"gotcha","affected_versions":"<5.0.0 (older versions might support earlier Python), >=5.0.0 (requires >=3.10)"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}