pyhumps


Namepyhumps JSON
Version 3.8.0 PyPI version JSON
download
home_pagehttps://github.com/nficano/humps
Summary🐫 Convert strings (and dictionary keys) between snake case, camel case and pascal case in Python. Inspired by Humps for Node
upload_time2022-10-21 10:38:59
maintainer
docs_urlNone
authorNick Ficano
requires_python
licenseThe Unlicense (Unlicense)
keywords humps snakecase convert case camelcase
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
<p align="center">
  <img src="https://raw.githubusercontent.com/nficano/humps/master/artwork/humps.png" alt="Humps logo" width="245" height="118">
</p>

<div align="center">
  <a href="http://humps.readthedocs.io/en/latest/?badge=latest">
    <img src="https://readthedocs.org/projects/humps/badge/?version=latest" />
  </a>
  <a href="https://coveralls.io/github/nficano/humps?branch=master">
    <img src="https://coveralls.io/repos/github/nficano/humps/badge.svg?branch=master#cachebus" />
  </a>
  <a href="https://pypi.org/project/pyhumps/">
    <img src="https://img.shields.io/pypi/v/pyhumps.svg#cachebust" />
  </a>
  <a href="https://pypi.org/project/pyhumps/">
    <img src="https://img.shields.io/pypi/dm/pyhumps.svg" />
  </a>
  <a href="https://pypi.python.org/pypi/pyhumps/">
    <img src="https://img.shields.io/pypi/pyversions/pyhumps.svg" />
  </a>
</div>
</p>

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.

## 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):

```bash
$ pipenv install pyhumps
```

## Usage

### Converting strings

```python
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

```python
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

```python
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
```

<hr>

## Cookbook

#### Pythonic Boto3 API Wrapper

```python
# 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")
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nficano/humps",
    "name": "pyhumps",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "humps,snakecase,convert case,camelcase",
    "author": "Nick Ficano",
    "author_email": "nficano@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c4/83/fa6f8fb7accb21f39e8f2b6a18f76f6d90626bdb0a5e5448e5cc9b8ab014/pyhumps-3.8.0.tar.gz",
    "platform": null,
    "description": "\n<p align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/nficano/humps/master/artwork/humps.png\" alt=\"Humps logo\" width=\"245\" height=\"118\">\n</p>\n\n<div align=\"center\">\n  <a href=\"http://humps.readthedocs.io/en/latest/?badge=latest\">\n    <img src=\"https://readthedocs.org/projects/humps/badge/?version=latest\" />\n  </a>\n  <a href=\"https://coveralls.io/github/nficano/humps?branch=master\">\n    <img src=\"https://coveralls.io/repos/github/nficano/humps/badge.svg?branch=master#cachebus\" />\n  </a>\n  <a href=\"https://pypi.org/project/pyhumps/\">\n    <img src=\"https://img.shields.io/pypi/v/pyhumps.svg#cachebust\" />\n  </a>\n  <a href=\"https://pypi.org/project/pyhumps/\">\n    <img src=\"https://img.shields.io/pypi/dm/pyhumps.svg\" />\n  </a>\n  <a href=\"https://pypi.python.org/pypi/pyhumps/\">\n    <img src=\"https://img.shields.io/pypi/pyversions/pyhumps.svg\" />\n  </a>\n</div>\n</p>\n\nConvert strings (and dictionary keys) between snake case, camel case and pascal case in Python. Inspired by [Humps](https://github.com/domchristie/humps) for Node.\n\n## Jan 11, 2021: An open call for contributors:\n\nPlease email me at nficano@gmail.com.\n\n## Installation\n\nTo install humps, simply use pipenv (or pip, of course):\n\n```bash\n$ pipenv install pyhumps\n```\n\n## Usage\n\n### Converting strings\n\n```python\nimport humps\n\nhumps.camelize(\"jack_in_the_box\")  # jackInTheBox\nhumps.decamelize(\"rubyTuesdays\")  # ruby_tuesdays\nhumps.pascalize(\"red_robin\")  # RedRobin\nhumps.kebabize(\"white_castle\")  # white-castle\n```\n\n### Converting dictionary keys\n\n```python\nimport humps\n\narray = [{\"attrOne\": \"foo\"}, {\"attrOne\": \"bar\"}]\nhumps.decamelize(array) # [{\"attr_one\": \"foo\"}, {\"attr_one\": \"bar\"}]\n\narray = [{\"attr_one\": \"foo\"}, {\"attr_one\": \"bar\"}]\nhumps.camelize(array)  # [{\"attrOne\": \"foo\"}, {\"attrOne\": \"bar\"}]\n\narray = [{'attr_one': 'foo'}, {'attr_one': 'bar'}]\nhumps.kebabize(array)  # [{'attr-one': 'foo'}, {'attr-one': 'bar'}]\n\narray = [{\"attr_one\": \"foo\"}, {\"attr_one\": \"bar\"}]\nhumps.pascalize(array)  # [{\"AttrOne\": \"foo\"}, {\"AttrOne\": \"bar\"}]\n```\n\n### Checking character casing\n\n```python\nimport humps\n\nhumps.is_camelcase(\"illWearYourGranddadsClothes\")  # True\nhumps.is_pascalcase(\"ILookIncredible\")  # True\nhumps.is_snakecase(\"im_in_this_big_ass_coat\")  # True\nhumps.is_kebabcase('from-that-thrift-shop')  # True\nhumps.is_camelcase(\"down_the_road\")  # False\n\nhumps.is_snakecase(\"imGonnaPopSomeTags\")  # False\nhumps.is_kebabcase('only_got_twenty_dollars_in_my_pocket')  # False\n\n\n# what about abbrevations, acronyms, and initialisms? No problem!\nhumps.decamelize(\"APIResponse\")  # api_response\n```\n\n<hr>\n\n## Cookbook\n\n#### Pythonic Boto3 API Wrapper\n\n```python\n# aws.py\nimport humps\nimport boto3\n\ndef api(service, decamelize=True, *args, **kwargs):\n    service, func = service.split(\":\")\n    client = boto3.client(service)\n    kwargs = humps.pascalize(kwargs)\n    response = getattr(client, func)(*args, **kwargs)\n    return (depascalize(response) if decamelize else response)\n\n# usage\napi(\"s3:download_file\", bucket=\"bucket\", key=\"hello.png\", filename=\"hello.png\")\n```\n",
    "bugtrack_url": null,
    "license": "The Unlicense (Unlicense)",
    "summary": "\ud83d\udc2b  Convert strings (and dictionary keys) between snake case, camel case and pascal case in Python. Inspired by Humps for Node",
    "version": "3.8.0",
    "split_keywords": [
        "humps",
        "snakecase",
        "convert case",
        "camelcase"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "d2476e8fb8c0cbedca855e55d70891ee",
                "sha256": "060e1954d9069f428232a1adda165db0b9d8dfdce1d265d36df7fbff540acfd6"
            },
            "downloads": -1,
            "filename": "pyhumps-3.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d2476e8fb8c0cbedca855e55d70891ee",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6095,
            "upload_time": "2022-10-21T10:38:58",
            "upload_time_iso_8601": "2022-10-21T10:38:58.231075Z",
            "url": "https://files.pythonhosted.org/packages/9e/11/a1938340ecb32d71e47ad4914843775011e6e9da59ba1229f181fef3119e/pyhumps-3.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "c9cf66913dbcc98513af00035fcbc8e9",
                "sha256": "498026258f7ee1a8e447c2e28526c0bea9407f9a59c03260aee4bd6c04d681a3"
            },
            "downloads": -1,
            "filename": "pyhumps-3.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c9cf66913dbcc98513af00035fcbc8e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9018,
            "upload_time": "2022-10-21T10:38:59",
            "upload_time_iso_8601": "2022-10-21T10:38:59.496082Z",
            "url": "https://files.pythonhosted.org/packages/c4/83/fa6f8fb7accb21f39e8f2b6a18f76f6d90626bdb0a5e5448e5cc9b8ab014/pyhumps-3.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-10-21 10:38:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "nficano",
    "github_project": "humps",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyhumps"
}
        
Elapsed time: 0.01467s