pyhumps

3.8.0 · active · verified Thu Apr 09

pyhumps is a Python library that converts strings and dictionary keys between various casing styles, including snake case, camel case, Pascal case, and kebab case. It is inspired by the Humps library for Node.js. The library is actively maintained, with its current version being 3.8.0, and receives regular updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates converting strings and dictionary keys between snake_case, camelCase, PascalCase, and kebab-case. It highlights the `camelize`, `pascalize`, and `kebabize` functions for both individual strings and lists of dictionaries.

import humps

snake_case_string = "hello_world_example"
camel_case_string = humps.camelize(snake_case_string)
pascal_case_string = humps.pascalize(snake_case_string)
kebab_case_string = humps.kebabize(snake_case_string)

data = [
    {"first_name": "John", "last_name": "Doe"},
    {"first_name": "Jane", "last_name": "Smith"}
]
camelized_data = humps.camelize(data)

print(f"Original snake_case: {snake_case_string}")
print(f"Camel case: {camel_case_string}")
print(f"Pascal case: {pascal_case_string}")
print(f"Kebab case: {kebab_case_string}")
print(f"Camelized dictionary keys: {camelized_data}")

view raw JSON →