Skip to main content

Humps logo

Convert strings (and dictionary keys) between snake case, camel case and pascal case in Python. Inspired by Humps for Node.

Jan 11, 2021: An open call for contributors:

Please email me at nficano@gmail.com.

Installation

To install humps, simply use pipenv (or pip, of course):

$ pipenv install pyhumps

Usage

Converting strings

import humps

humps.camelize("jack_in_the_box")  # jackInTheBox
humps.decamelize("rubyTuesdays")  # ruby_tuesdays
humps.pascalize("red_robin")  # RedRobin
humps.kebabize("white_castle")  # white-castle

Converting dictionary keys

import humps

array = [{"attrOne": "foo"}, {"attrOne": "bar"}]
humps.decamelize(array) # [{"attr_one": "foo"}, {"attr_one": "bar"}]

array = [{"attr_one": "foo"}, {"attr_one": "bar"}]
humps.camelize(array)  # [{"attrOne": "foo"}, {"attrOne": "bar"}]

array = [{'attr_one': 'foo'}, {'attr_one': 'bar'}]
humps.kebabize(array)  # [{'attr-one': 'foo'}, {'attr-one': 'bar'}]

array = [{"attr_one": "foo"}, {"attr_one": "bar"}]
humps.pascalize(array)  # [{"AttrOne": "foo"}, {"AttrOne": "bar"}]

Checking character casing

import humps

humps.is_camelcase("illWearYourGranddadsClothes")  # True
humps.is_pascalcase("ILookIncredible")  # True
humps.is_snakecase("im_in_this_big_ass_coat")  # True
humps.is_kebabcase('from-that-thrift-shop')  # True
humps.is_camelcase("down_the_road")  # False

humps.is_snakecase("imGonnaPopSomeTags")  # False
humps.is_kebabcase('only_got_twenty_dollars_in_my_pocket')  # False


# what about abbrevations, acronyms, and initialisms? No problem!
humps.decamelize("APIResponse")  # api_response

Cookbook

Pythonic Boto3 API Wrapper

# aws.py
import humps
import boto3

def api(service, decamelize=True, *args, **kwargs):
    service, func = service.split(":")
    client = boto3.client(service)
    kwargs = humps.pascalize(kwargs)
    response = getattr(client, func)(*args, **kwargs)
    return (depascalize(response) if decamelize else response)

# usage
api("s3:download_file", bucket="bucket", key="hello.png", filename="hello.png")

Metadata

Release files for pyhumps 3.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyhumps 3.8.0
File Size Uploaded Provenance Actions
pyhumps-3.8.0.tar.gz 9.0 kB Without provenance Details for pyhumps-3.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyhumps 3.8.0
File Interpreter ABI Platform Actions
pyhumps-3.8.0-py3-none-any.whl Python 3 none any Details for pyhumps-3.8.0-py3-none-any.whl

Total release size: 15.1 kB

Release files / pyhumps-3.8.0.tar.gz

Download URL pyhumps-3.8.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
498026258f7ee1a8e447c2e28526c0bea9407f9a59c03260aee4bd6c04d681a3
BLAKE2b-256 checksum
How to use checksums
c483fa6f8fb7accb21f39e8f2b6a18f76f6d90626bdb0a5e5448e5cc9b8ab014
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.2 requests/2.28.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.2.0 keyring/23.9.3 rfc3986/2.0.0 colorama/0.4.5 CPython/3.10.8

Release files / pyhumps-3.8.0-py3-none-any.whl

Download URL pyhumps-3.8.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
060e1954d9069f428232a1adda165db0b9d8dfdce1d265d36df7fbff540acfd6
BLAKE2b-256 checksum
How to use checksums
9e11a1938340ecb32d71e47ad4914843775011e6e9da59ba1229f181fef3119e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.2 requests/2.28.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.2.0 keyring/23.9.3 rfc3986/2.0.0 colorama/0.4.5 CPython/3.10.8

Security for pyhumps 3.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.8.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page