Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nficano/humps
Convert strings (and dictionary keys) between snake case, camel case and pascal case in Python. Inspired by Humps for Node
https://github.com/nficano/humps
camelcase-to-snakecase pascal python3 snakecase
Last synced: 2 days ago
JSON representation
Convert strings (and dictionary keys) between snake case, camel case and pascal case in Python. Inspired by Humps for Node
- Host: GitHub
- URL: https://github.com/nficano/humps
- Owner: nficano
- License: unlicense
- Created: 2018-10-14T17:08:13.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-03T00:43:05.000Z (4 months ago)
- Last Synced: 2024-12-04T15:04:52.665Z (10 days ago)
- Topics: camelcase-to-snakecase, pascal, python3, snakecase
- Language: Python
- Homepage: http://humps.readthedocs.io/
- Size: 4.89 MB
- Stars: 330
- Watchers: 6
- Forks: 33
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Convert strings (and dictionary keys) between snake case, camel case and pascal case in Python. Inspired by [Humps](https://github.com/domchristie/humps) for Node.
## Installation
To install humps, simply use pipenv (or pip, of course):
```bash
$ pipenv install pyhumps
```## Usage
### Converting strings
```python
import humpshumps.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
```python
import humpsarray = [{"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
```python
import humpshumps.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") # Falsehumps.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
```python
# aws.py
import humps
import boto3def 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")
```