Skip to main content

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

Metadata

Release files for camel-converter 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for camel-converter 1.0.6
File Size Uploaded
camel-converter-1.0.6.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for camel-converter 1.0.6
File Interpreter ABI Platform
camel_converter-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 kB

Release files / camel-converter-1.0.6.tar.gz

Download URL camel-converter-1.0.6.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e70c1f8b83b9c172270a6cd92f6cdcd8e30502923058fec07be71fb701e6ce95
BLAKE2b-256 checksum
How to use checksums
425fed461835df04d256b0070ea6b4a263e06987a60724744f958aaa205cd37b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.9.13 Linux/5.15.0-1014-azure

Release files / camel_converter-1.0.6-py3-none-any.whl

Download URL camel_converter-1.0.6-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e752eb4c73b7cd94c45f74374fb4f6374286c80d60946002db998aae4349766
BLAKE2b-256 checksum
How to use checksums
115d0b26018db1d6f60d9cb92a43d7f8452c1104706f01ba4aa558bc7d9ea78c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.9.13 Linux/5.15.0-1014-azure

Release history Release notifications | RSS feed

5.1.1

2 release files

5.1.0

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.7

2 release files

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page