Skip to main content

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

Project description

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

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.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_camelcase("from_that_thrift_shop")  # False
humps.is_snakecase("downTheRoad")  # False

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

Humps 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhumps-3.7.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhumps-3.7.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pyhumps-3.7.1.tar.gz.

File metadata

  • Download URL: pyhumps-3.7.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/35.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for pyhumps-3.7.1.tar.gz
Algorithm Hash digest
SHA256 5616f0afdbc73ef479fa9999f4abdcb336a0232707ff1a0b86e29fc9339e18da
MD5 b1fb68f3c9a73dcafc800757df515783
BLAKE2b-256 c31bc6d9fb7f322d3a3f094b6f3a582a265257dcdeaa764ce2efb11ab8194c72

See more details on using hashes here.

File details

Details for the file pyhumps-3.7.1-py3-none-any.whl.

File metadata

  • Download URL: pyhumps-3.7.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/35.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for pyhumps-3.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6f2d833f2c7afae039d71b7dc0aba5412ae5b8c8c33d4a208c1d412de17229e
MD5 1f693df0b40a66680aa4e73894758aa7
BLAKE2b-256 7b96b1725d817a0c9f8f0c775b872753563bc1fafe0d8b2acf0b1c5aef38d36c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page