Camel Converter
In JSON keys are frequently in camelCase format, while variable names in Python are typically snake_case. The purpose of this package 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
myStringintomy_string -
To convert a dictionary's keys from camel case to snake case:
from camel_converter import dict_to_snake snake = dict_to_snake({"myString": "val 1"})
This will convert
{"myString": "val 1"}into{"my_string": "val 1"}. Non-string keys will be left unchanged.This is also available as a decorator for functions that return a dictionary.
from camel_converter.decorators import dict_to_snake @dict_to_snake def my_func() -> dict[str, str]: return {"myString": "val 1"} snake = my_func()
my_funcwill return{"my_string": "val 1"}. Non-string keys will be left unchanged. -
To convert from snake case to camel case:
from camel_converter import to_camel camel = to_camel("my_string")
This will convert
my_stringintomyString -
To convert from a dictionary's keys from snake case to camel case:
from camel_converter import dict_to_camel camel = dict_to_camel({"my_string": "val 1"})
This will convert
{"my_string": "val 1"}into{"myString": "val 1"}Non-string keys will be left unchanged.This is also available as a decorator for functions that return a dictionary.
from camel_converter.decorators import dict_to_camel @dict_to_camel def my_func() -> dict[str, str]: return {"my_string": "val 1"} camel = my_func()
my_funcwill return{"myString": "val 1"}. Non-string keys will be left unchanged. -
To convert from snake to pascal case:
from camel_converter import to_pascal pascal = to_pascal("my_string")
This will convert
my_stringintoMyString -
To convert from a dictionary's keys from snake case to pascal case:
from camel_converter import dict_to_pascal pascal = dict_to_pascal({"my_string": "val 1"})
This will convert
{"my_string": "val 1"}into{"MyString": "val 1"}Non-string keys will be left unchanged.This is also available as a decorator for functions that return a dictionary.
from camel_converter.decorators import dict_to_pascal @dict_to_pascal def my_func() -> dict[str, str]: return {"my_string": "val 1"} pascal = my_func()
my_funcwill return{"MyString": "val 1"}. Non-string keys will be left unchanged. -
Class base model to add methods
Inheriting the Converter adds to_camel and from_camel methods to your class
from camel_converter import Converter
class SomeClass(Converter):
some_value = "some value"
def __init__(self) -> None:
self.another_value = "another value"
example = SomeClass()
print(example.to_camel())
This will print {"someValue": "some value", "anotherValue": "another value"}
from camel_converter import Converter
class SomeClass(Converter):
def __init__(self, some_value: str) -> None:
self.some_value = some_value
example = SomeClass.from_camel({"someValue": "some value"})
print(example.some_value)
This will print some value
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 interested in contributing to this project please see our contributing guide
Metadata
Release files for camel-converter 6.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| camel_converter-6.0.1.tar.gz | 47.2 kB | Without provenance | Details for camel_converter-6.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| camel_converter-6.0.1-py3-none-any.whl | Python 3 | none | any | Details for camel_converter-6.0.1-py3-none-any.whl |
Total release size: 54.3 kB
Release files / camel_converter-6.0.1.tar.gz
| Download URL | camel_converter-6.0.1.tar.gz |
|---|---|
| Size | 47.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91ee28e70b3e5728ade14642d126f03d2d20a592f6ffb96ed4f75aab3a9dce0e
|
|
BLAKE2b-256 checksum How to use checksums |
85337e4d6164eb40a3257ded85bf0a2f97fb7f4ba6fdebea8af8089b5d9d7cad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / camel_converter-6.0.1-py3-none-any.whl
| Download URL | camel_converter-6.0.1-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bcfbe1193d6b17cd16553cc985780e7d74a4b6f78e5b4e3ca4c7d7ce74a7926f
|
|
BLAKE2b-256 checksum How to use checksums |
4f1216c3614ea982d1fdf99cfa66ca910ffff84496af713ced2ce6495c2b2333
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for camel-converter 6.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.