Name | camel-converter JSON |
Version |
4.0.1
JSON |
| download |
home_page | None |
Summary | Converts a string from snake case to camel case or camel case to snake case |
upload_time | 2024-10-08 16:55:39 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License Copyright (c) 2021 Paul Sanders Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
camel-case
converter
pydantic
python
snake-case
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Camel Converter
[![CI Status](https://github.com/sanders41/camel-converter/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/sanders41/camel-converter/actions?query=workflow%3CI+branch%3Amain+event%3Apush)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/sanders41/camel-converter/main.svg)](https://results.pre-commit.ci/latest/github/sanders41/camel-converter/main)
[![Coverage](https://codecov.io/github/sanders41/camel-converter/coverage.svg?branch=main)](https://codecov.io/gh/sanders41/camel-converter)
[![PyPI version](https://badge.fury.io/py/camel-converter.svg)](https://badge.fury.io/py/camel-converter)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/camel-converter?color=5cc141)](https://github.com/sanders41/camel-converter)
In JSON keys are frequently in camelCase format, while variable names in Python are typically
snake_case. The purpose of this pacakgae is to help convert between the two formats.
## Usage
- To convert from camel case to snake case:
```py
from camel_converter import to_snake
snake = to_snake("myString")
```
This will convert `myString` into `my_string`
- To convert a dictonary's keys from camel case to snake case:
```py
from camel_converter import dict_to_snake
snake = dict_to_snake({"myString": "val 1"})
```
This will convert `{"myString": "val 1"}` into `{"my_string": "val 1"}`. Non-string keys will be
left unchanged.
This is also available as a decorator for functions that return a dictionary.
```py
from camel_converter.decorators import dict_to_snake
@dict_to_snake
def my_func() -> dict[str, str]:
return {"myString": "val 1"}
snake = my_func()
```
`my_func` will return `{"my_string": "val 1"}`. Non-string keys will be
left unchanged.
- To convert from snake case to camel case:
```py
from camel_converter import to_camel
camel = to_camel("my_string")
```
This will convert `my_string` into `myString`
- To convert from a dictionary's keys from snake case to camel case:
```py
from camel_converter import dict_to_camel
camel = to_camel({"my_string": "val 1"})
```
This will convert `{"my_string": "val 1"}` into `{"myString": "val 1"}` Non-string keys will be
left unchanged.
This is also available as a decorator for functions that return a dictionary.
```py
from camel_converter.decorators import dict_to_camel
@dict_to_camel
def my_func() -> dict[str, str]:
return {"my_string": "val 1"}
camel = my_func()
```
`my_func` will return `{"myString": "val 1"}`. Non-string keys will be
left unchanged.
- To convert from snake to pascal case:
```py
from camel_converter import to_pascal
pascal = to_pascal("my_string")
```
This will convert `my_string` into `MyString`
- To convert from a dictionary's keys from snake case to pascal case:
```py
from camel_converter import dict_to_pascal
pascal = to_pascal({"my_string": "val 1"})
```
This will convert `{"my_string": "val 1"}` into `{"MyString": "val 1"}` Non-string keys will be
left unchanged.
This is also available as a decorator for functions that return a dictionary.
```py
from camel_converter.decorators import dict_to_pascal
@dict_to_pascal
def my_func() -> dict[str, str]:
return {"my_string": "val 1"}
pascal = my_func()
```
`my_func` will return `{"MyString": "val 1"}`. Non-string keys will be
left unchanged.
### Optional Extras
An optional extra is provided for [Pydantic](https://pydantic-docs.helpmanual.io/) that provides a
base class to automatically convert between snake case and camel case. To use this Pydantic class
install camel converter with:
```sh
pip install camel-converter[pydantic]
```
Then your Pydantic classes can inherit from CamelBase.
```py
from camel_converter.pydantic_base import CamelBase
class MyModel(CamelBase):
test_field: str
my_data = MyModel(**{"testField": "my value"})
print(my_data.test_field)
```
will result in `my value` being printed.
With setting up your model in this way `myField` from the source, i.e. JSON data, will map to `my_field` in your model.
## Contributing
If you are interested in contributing to this project please see our [contributing guide](CONTRIBUTING.md)
Raw data
{
"_id": null,
"home_page": null,
"name": "camel-converter",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "camel-case, converter, pydantic, python, snake-case",
"author": null,
"author_email": "Paul Sanders <paul@paulsanders.dev>",
"download_url": "https://files.pythonhosted.org/packages/ee/3d/dd783586dc0c4aee5b6b88489666fdb2c0c344ea0aa8a5c10746cc423707/camel_converter-4.0.1.tar.gz",
"platform": null,
"description": "# Camel Converter\n\n[![CI Status](https://github.com/sanders41/camel-converter/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/sanders41/camel-converter/actions?query=workflow%3CI+branch%3Amain+event%3Apush)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/sanders41/camel-converter/main.svg)](https://results.pre-commit.ci/latest/github/sanders41/camel-converter/main)\n[![Coverage](https://codecov.io/github/sanders41/camel-converter/coverage.svg?branch=main)](https://codecov.io/gh/sanders41/camel-converter)\n[![PyPI version](https://badge.fury.io/py/camel-converter.svg)](https://badge.fury.io/py/camel-converter)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/camel-converter?color=5cc141)](https://github.com/sanders41/camel-converter)\n\nIn JSON keys are frequently in camelCase format, while variable names in Python are typically\nsnake_case. The purpose of this pacakgae is to help convert between the two formats.\n\n## Usage\n\n- To convert from camel case to snake case:\n\n ```py\n from camel_converter import to_snake\n\n snake = to_snake(\"myString\")\n ```\n\n This will convert `myString` into `my_string`\n\n- To convert a dictonary's keys from camel case to snake case:\n\n ```py\n from camel_converter import dict_to_snake\n\n snake = dict_to_snake({\"myString\": \"val 1\"})\n ```\n\n This will convert `{\"myString\": \"val 1\"}` into `{\"my_string\": \"val 1\"}`. Non-string keys will be\n left unchanged.\n\n This is also available as a decorator for functions that return a dictionary.\n\n ```py\n from camel_converter.decorators import dict_to_snake\n\n @dict_to_snake\n def my_func() -> dict[str, str]:\n return {\"myString\": \"val 1\"}\n\n snake = my_func()\n ```\n\n `my_func` will return `{\"my_string\": \"val 1\"}`. Non-string keys will be\n left unchanged.\n\n- To convert from snake case to camel case:\n\n ```py\n from camel_converter import to_camel\n\n camel = to_camel(\"my_string\")\n ```\n\n This will convert `my_string` into `myString`\n\n- To convert from a dictionary's keys from snake case to camel case:\n\n ```py\n from camel_converter import dict_to_camel\n\n camel = to_camel({\"my_string\": \"val 1\"})\n ```\n\n This will convert `{\"my_string\": \"val 1\"}` into `{\"myString\": \"val 1\"}` Non-string keys will be\n left unchanged.\n\n This is also available as a decorator for functions that return a dictionary.\n\n ```py\n from camel_converter.decorators import dict_to_camel\n\n @dict_to_camel\n def my_func() -> dict[str, str]:\n return {\"my_string\": \"val 1\"}\n\n camel = my_func()\n ```\n\n `my_func` will return `{\"myString\": \"val 1\"}`. Non-string keys will be\n left unchanged.\n\n- To convert from snake to pascal case:\n\n ```py\n from camel_converter import to_pascal\n\n pascal = to_pascal(\"my_string\")\n ```\n\n This will convert `my_string` into `MyString`\n\n- To convert from a dictionary's keys from snake case to pascal case:\n\n ```py\n from camel_converter import dict_to_pascal\n\n pascal = to_pascal({\"my_string\": \"val 1\"})\n ```\n\n This will convert `{\"my_string\": \"val 1\"}` into `{\"MyString\": \"val 1\"}` Non-string keys will be\n left unchanged.\n\n This is also available as a decorator for functions that return a dictionary.\n\n ```py\n from camel_converter.decorators import dict_to_pascal\n\n @dict_to_pascal\n def my_func() -> dict[str, str]:\n return {\"my_string\": \"val 1\"}\n\n pascal = my_func()\n ```\n\n `my_func` will return `{\"MyString\": \"val 1\"}`. Non-string keys will be\n left unchanged.\n\n### Optional Extras\n\nAn optional extra is provided for [Pydantic](https://pydantic-docs.helpmanual.io/) that provides a\nbase class to automatically convert between snake case and camel case. To use this Pydantic class\ninstall camel converter with:\n\n```sh\npip install camel-converter[pydantic]\n```\n\nThen your Pydantic classes can inherit from CamelBase.\n\n```py\nfrom camel_converter.pydantic_base import CamelBase\n\n\nclass MyModel(CamelBase):\n test_field: str\n\n\nmy_data = MyModel(**{\"testField\": \"my value\"})\nprint(my_data.test_field)\n```\n\nwill result in `my value` being printed.\n\nWith setting up your model in this way `myField` from the source, i.e. JSON data, will map to `my_field` in your model.\n\n## Contributing\n\nIf you are interested in contributing to this project please see our [contributing guide](CONTRIBUTING.md)\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2021 Paul Sanders Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Converts a string from snake case to camel case or camel case to snake case",
"version": "4.0.1",
"project_urls": null,
"split_keywords": [
"camel-case",
" converter",
" pydantic",
" python",
" snake-case"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "32e5806359514cc8305f047bd6d39d63890298c0596f7328b534059724bd1a9e",
"md5": "8421b03b567a6ba88dc138675e05885f",
"sha256": "0cba7ca1354a29ca2191983deecc9dcf28889f606c28d6ed18ac7d4586b163ac"
},
"downloads": -1,
"filename": "camel_converter-4.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8421b03b567a6ba88dc138675e05885f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 6243,
"upload_time": "2024-10-08T16:55:37",
"upload_time_iso_8601": "2024-10-08T16:55:37.769690Z",
"url": "https://files.pythonhosted.org/packages/32/e5/806359514cc8305f047bd6d39d63890298c0596f7328b534059724bd1a9e/camel_converter-4.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ee3ddd783586dc0c4aee5b6b88489666fdb2c0c344ea0aa8a5c10746cc423707",
"md5": "5d9080a8021a0536ed410e76a201e8f2",
"sha256": "401414549ae4ac4073e38cdc4aa6d464dc534fc40aa06ff787bf0960b0c86535"
},
"downloads": -1,
"filename": "camel_converter-4.0.1.tar.gz",
"has_sig": false,
"md5_digest": "5d9080a8021a0536ed410e76a201e8f2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 38915,
"upload_time": "2024-10-08T16:55:39",
"upload_time_iso_8601": "2024-10-08T16:55:39.427891Z",
"url": "https://files.pythonhosted.org/packages/ee/3d/dd783586dc0c4aee5b6b88489666fdb2c0c344ea0aa8a5c10746cc423707/camel_converter-4.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-08 16:55:39",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "camel-converter"
}