Skip to main content

Converts a string from snake case to camel case or camel case to snake case

Project description

Camel Converter

CI Status pre-commit.ci status Coverage PyPI version PyPI - Python Version

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 into my_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 into myString

  • 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 into MyString

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


Download files

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

Source Distribution

camel_converter-1.0.7.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

camel_converter-1.0.7-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file camel_converter-1.0.7.tar.gz.

File metadata

  • Download URL: camel_converter-1.0.7.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.15 Linux/5.15.0-1022-azure

File hashes

Hashes for camel_converter-1.0.7.tar.gz
Algorithm Hash digest
SHA256 f3ff89d114af3ac278c553a41ebc346850e437b9cb4b140308c5419d1f1ed482
MD5 261e061e6db78f335d3424fc6d369648
BLAKE2b-256 264d3f4c517e6af806e503776a3c2c6fb1b003eeae8c0797d8b37a711b371b96

See more details on using hashes here.

File details

Details for the file camel_converter-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: camel_converter-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.9.15 Linux/5.15.0-1022-azure

File hashes

Hashes for camel_converter-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 625b8b0da1e6262b991eb92c7f193198ba0f664a64d7ac4884ea604febdd0bd3
MD5 589e37cb9c9ee69e2faefa30ff185a28
BLAKE2b-256 82208c28c76158df5e5e03e8febf4a2d3e92e9f1370af2df01932f701ccf9699

See more details on using hashes here.

Supported by

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