Skip to main content

Camel Converter

CI Status pre-commit.ci status Coverage PyPI 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

If you are using Pydantic, a common usage of Pydantic where this package is useful is in FastAPI you can use this package in your models to automatically do the conversion.

from pydantic import BaseModel

from camel_converter import to_camel


class MyModel(BaseModel):
    class Config:
        alias_generator = to_camel
        allow_population_by_field_name = True

    my_field: str

With setting up your model in this way myField from the source, i.e. JSON data, will map to my_field in your model.

You can also setup a model to inherit the config settings from so the class Config does not have to be manually set on every model:

from pydantic import BaseModel

from camel_converter import to_camel


class MyBaseModel(BaseModel):
    class Config:
        alias_generator = to_camel
        allow_population_by_field_name = True


class MyModel(MyBaseModel):
    my_field: str


class AnotherModel(MyBaseModel):
    another_field: int

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-0.1.2.tar.gz (3.4 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-0.1.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: camel-converter-0.1.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-1043-azure

File hashes

Hashes for camel-converter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fb7474e699e0a58226d1029ee43161895a0bd5bdc8eacf53a50b166ded8daacf
MD5 c1fbd068e497e8dba2064879a50a4270
BLAKE2b-256 bb3d4dfdc71faf758e47ef72d2ab46e2a1bb0b230068865aef4a9a40a633d076

See more details on using hashes here.

File details

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

File metadata

  • Download URL: camel_converter-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-1043-azure

File hashes

Hashes for camel_converter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f245cda7d2b9de22ad22a8f9aa3971909df3f10c52fe4231bc4843ddc663a1ef
MD5 8290b816e9e946223cc84800436e010d
BLAKE2b-256 3e04a669dba67bbc6e39698cc1c2aa7bf6706756d556bb09fe209df653371f9d

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

1.0.3

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

This release

0.1.2 This release

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