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

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.3.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file camel-converter-1.0.3.tar.gz.

File metadata

  • Download URL: camel-converter-1.0.3.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.7 Linux/5.8.0-1042-azure

File hashes

Hashes for camel-converter-1.0.3.tar.gz
Algorithm Hash digest
SHA256 824abe85c6fa29baf6485343a6b077a8cb64531c89d6852b68e0417e4c15c0ba
MD5 4d01a10553dcb29c741d2dd4c206c369
BLAKE2b-256 1defbdac6838dbc06486c4cf59587fe83db386e3caf7d2f4b935d798410d882b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: camel_converter-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.7 Linux/5.8.0-1042-azure

File hashes

Hashes for camel_converter-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c51cb9c9962aea9a77b8400dd5651bf7d1c75bc988ecc8588ca3c67a342f8db3
MD5 7d0a5eaacccffdb5d0280dad8db6ce2e
BLAKE2b-256 6c413aed37867f6760e4857b7510880afdcbb0b1bcc7588a8a2877548d8feeef

See more details on using hashes here.

Release history Release notifications | RSS feed

5.1.1

2 files

5.1.0

2 files

5.0.1

2 files

5.0.0

2 files

4.0.1

2 files

4.0.0

2 files

3.1.2

2 files

3.1.1

2 files

3.1.0

2 files

3.0.3

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.0.1

2 files

2.0.0

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

This release

1.0.3 This release

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.2.0.post1

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 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