Registry / serialization / pyhumps

pyhumps

JSON →
library3.8.0pypypi✓ verified 26d ago

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.

pip install pyhumps
INSTALL
IMPORT
SIG · PYHUMPS
P
pyhumps
serializationpythonv3.8.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

humps
import humps
import humps # after 'pip install humps'
The PyPI package name is `pyhumps`, but the module is imported as `humps`. Installing a package named `humps` (an older, unrelated project) instead of `pyhumps` will lead to an `AttributeError` when trying to use functions like `humps.camelize` from the expected library. Always ensure you install `pyhumps`.

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}")
Debug
Known issues
gotchaInstalling the wrong package: There is an older, unrelated PyPI package also named `humps`. If you install `humps` instead of `pyhumps`, you will get a different, unmaintained library. This will likely result in `AttributeError` when attempting to use functions like `camelize` or `decamelize` from the `pyhumps` API, as they won't exist in the incorrectly installed `humps` module.
fix
Always install the correct package using `pip install pyhumps`. If you suspect you have the wrong package, uninstall `humps` and then install `pyhumps`.
affects: All versions
gotchaShadowing the `humps` module: If you create a Python file named `humps.py` in your project or name a variable `humps`, it can shadow the installed `humps` module. This will cause Python to import your local file/variable instead of the library, leading to unexpected errors or `AttributeError`s.
fix
Avoid naming your Python files or critical variables `humps.py` or `humps` to prevent import conflicts and ensure the correct library module is loaded.
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'humps' has no attribute 'decamelize'
This error occurs when the `pyhumps` library is installed, but Python resolves `import humps` to a different, possibly built-in, or incomplete `humps` module, rather than the `pyhumps` package's intended `humps` module. This can happen due to conflicts with older `humps` packages or namespace issues.
fix
First, ensure only `pyhumps` is installed (`pip install pyhumps`). If a previous `humps` package was installed, uninstall it (`pip uninstall humps`). Consider using a clean virtual environment. The correct import statement should be `import humps` after installing `pyhumps`.
ModuleNotFoundError: No module named 'humps'
Despite `pyhumps` being installed, Python cannot locate the `humps` module during the import process. This is common when the `pyhumps` package is installed but the environment's `PYTHONPATH` isn't correctly configured, or when bundling applications with tools like PyInstaller.
fix
Verify `pyhumps` is installed in your active environment (`pip list | grep pyhumps`). If using PyInstaller, add `--hidden-import humps` to your command to ensure the `humps` module (provided by the `pyhumps` package) is correctly bundled.
AttributeError: 'str' object has no attribute 'items'
A `pyhumps` function designed to process dictionary keys (e.g., to convert keys to a different casing style) was inadvertently called with a string argument instead of a dictionary. The `.items()` method is exclusive to dictionary objects in Python.
fix
Ensure that the argument provided to the `pyhumps` function is a Python dictionary or a list of dictionaries. If your input data is a JSON string, first deserialize it into a Python dictionary using `json.loads()`.
Upgrade
Version history
3.8.0latest on PyPI · released Oct 21, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
Resources
pyhumps — pip install pyhumps · libregistry