Converts a string from snake case to camel case or camel case to snake case
Project description
Camel Converter
In JSON keys are frequently in camelCase format, while variable names in Python 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:
from camel_converter import to_snake snake = to_snake("myString")
This will convert
myString
intomy_string
-
To convert from snake case to camel case:
from camel_converter import to_camel camel = to_camel("my_string")
This will convert
my_string
intomyString
-
To convert from snake to upper camel case:
from camel_converter import to_upper_camel upper_camel = to_upper_camel("my_string")
This will convert
my_string
intoMyString
Optional Extras
An optional extra is provided for Pydantic that provides a base class to automatically convert between snake case and camel case. To use this Pydantic class install camel converter with:
pip install camel-converter[pydantic]
Then your Pydantic classes can inherit from CamelBase.
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 interesting in contributing to this project please see our contributing guide
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
File details
Details for the file camel-converter-1.0.1.tar.gz
.
File metadata
- Download URL: camel-converter-1.0.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 152b64f66c942f5d7d73d8d7264621aaa257a2750faa16e305d43c3b453c8661 |
|
MD5 | 770cf83143ec925dd24e0702a3d4616d |
|
BLAKE2b-256 | f015fbf8d26441455935f69450bbcd5833d43b653abf82bf11fc951301c93c77 |
File details
Details for the file camel_converter-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: camel_converter-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 724b585e27e3a34419ae2c12880a124f27b9979b261db6c2f69d2d4e0c0edfee |
|
MD5 | 3abba34cdac15f78ec2e67d1a18e12d5 |
|
BLAKE2b-256 | c53cdd2db316688ba72d930337586b26d0bac5269ad73989335192e82d3a55dc |