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")
humps.decamelize("rubyTuesdays")
humps.pascalize("red_robin")
humps.kebabize("white_castle")
Converting dictionary keys
import humps
array = [{"attrOne": "foo"}, {"attrOne": "bar"}]
humps.decamelize(array)
array = [{"attr_one": "foo"}, {"attr_one": "bar"}]
humps.camelize(array)
array = [{'attr_one': 'foo'}, {'attr_one': 'bar'}]
humps.kebabize(array)
array = [{"attr_one": "foo"}, {"attr_one": "bar"}]
humps.pascalize(array)
Checking character casing
import humps
humps.is_camelcase("illWearYourGranddadsClothes")
humps.is_pascalcase("ILookIncredible")
humps.is_snakecase("im_in_this_big_ass_coat")
humps.is_kebabcase('from-that-thrift-shop')
humps.is_camelcase("down_the_road")
humps.is_snakecase("imGonnaPopSomeTags")
humps.is_kebabcase('only_got_twenty_dollars_in_my_pocket')
humps.decamelize("APIResponse")
Cookbook
Pythonic Boto3 API Wrapper
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)
api("s3:download_file", bucket="bucket", key="hello.png", filename="hello.png")