humps

raw JSON →
0.2.2 verified Mon Apr 27 auth: no python maintenance

humps is a Python library for converting strings between camelCase, snake_case, PascalCase, and other cases. The current version is 0.2.2. It has a low release cadence; the last release was in 2017.

pip install humps
error AttributeError: module 'humps' has no attribute 'camel'
cause Importing from humps.camel (old pattern) after v0.2.2, or a misspelled module name.
fix
Use 'from humps import camelize' or ensure you have the latest version (>=0.2.2).
error TypeError: expected string or bytes-like object
cause Passing a non-string (e.g., integer, dict) to humps functions.
fix
Ensure input is a string. For dict conversion, use loops or the humps.main.convert function.
gotcha humps only works on single strings, not on dict keys or nested structures. Use humps.main.convert for dict conversion.
fix For dict conversion, use humps.camelize or see the main module. Note that automatic dict key conversion is limited.
gotcha humps does not preserve leading or trailing underscores in snake_case conversion (e.g., '_private' becomes 'Private').
fix Manually handle underscore preservation if needed.
deprecated The old import path 'from humps.camel import case' is deprecated since v0.2.2.
fix Use 'from humps import camelize' instead.

Basic usage: convert strings between cases.

from humps import camelize, decamelize, pascalize

# Convert snake_case to camelCase
print(camelize('hello_world'))  # 'helloWorld'

# Convert camelCase to snake_case
print(decamelize('helloWorld'))  # 'hello_world'

# Convert snake_case to PascalCase
print(pascalize('hello_world'))  # 'HelloWorld'