🐫 Convert strings (and dictionary keys) between snake case, camel case and pascal case in Python. Inspired by Humps for Node
Project description
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")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyhumps-3.8.0.tar.gz.
File metadata
- Download URL: pyhumps-3.8.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
498026258f7ee1a8e447c2e28526c0bea9407f9a59c03260aee4bd6c04d681a3
|
|
| MD5 |
c9cf66913dbcc98513af00035fcbc8e9
|
|
| BLAKE2b-256 |
c483fa6f8fb7accb21f39e8f2b6a18f76f6d90626bdb0a5e5448e5cc9b8ab014
|
File details
Details for the file pyhumps-3.8.0-py3-none-any.whl.
File metadata
- Download URL: pyhumps-3.8.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
060e1954d9069f428232a1adda165db0b9d8dfdce1d265d36df7fbff540acfd6
|
|
| MD5 |
d2476e8fb8c0cbedca855e55d70891ee
|
|
| BLAKE2b-256 |
9e11a1938340ecb32d71e47ad4914843775011e6e9da59ba1229f181fef3119e
|