Skip to main content

A simple python lib to convert string and dict keys to camelcase, pascal case, kebab case and snake case.

Project description

pycasestyle

pycasestyle is a Python library for converting variable naming styles between CamelCase, snake_case, kebab-case, and PascalCase.

Supported styles: - CamelCase - SnakeCase - KebabCase - PascalCase

Installation

To install pycasestyle, you can use pip:

.. code-block:: bash pip install pycasestyle

Usage

You can import the text formatting styles directly from the pycasestyle module and use them in your code. Here's an example of how to use the text formatting styles:

.. code-block:: python import pycasestyle

# Converting to camelcase from text
camelcased_text = pycasestyle.camelcase.from_string("i want a camel")
print(camelcased_text)  # Output: "iWantACamel"

# Converting to camelcase from dict
camelcased_dict = pycasestyle.camelcase.from_dict({"i want a camel": "value"})
print(camelcased_dict)  # Output: {"iWantACamel": "value"}

# Converting to snakecase from text
snakecased_text = pycasestyle.snakecase.from_string("I Want A Snake")
print(snakecased_text)  # Output: "i_want_a_snake"

# Converting to snakecase from dict
snakecased_dict = pycasestyle.snakecase.from_dict({"I Want A Snake": "value"})
print(snakecased_dict)  # Output: {"i_want_a_snake": "value"}

# Converting to kebab-case
kebabcased_text = pycasestyle.kebabcase.from_string("I Want A Kebab")
print(kebabcased_text)  # Output: "i-want-a-kebab"

# Converting to kebab-case from dict
kebabcased_dict = pycasestyle.kebabcase.from_dict({"I Want A Kebab": "value"})
print(kebabcased_dict)  # Output: {"i-want-a-kebab": "value"}

# Converting to PascalCase from text
pascalcased_text = pycasestyle.pascalcase.from_string("i want a pascal")
print(pascalcased_text)  # Output: "IWantAPascal"

# Converting to PascalCase from dict
pascalcased_dict = pycasestyle.pascalcase.from_dict({"i want a pascal": "value"})
print(pascalcased_dict)  # Output: {"IWantAPascal": "value"}

Use cases

If you needed convert schemas, mappings, contracts, etc. This tool is specific to turn easily your job.

Real use case:

You need to migrate information from Postgres to Elasticsearch, however, the mapping used in Elastic is following the camelcase pattern, whereas in Postgres it is with the Snakecase pattern, see how simple it is to solve:

.. code-block:: python import pycasestyle

postgres_contract = {
    "id": 1,
    "customers_id": 32,
    "users_id": 56,
    "period_datetime": "2024-08-10"
}

elastic_contract = pycasestyle.camelcase.from_dict(postgres_contract)
print(elastic_contract) # Output: {
    "id": 1,
    "customersId": 32,
    "usersId": 56,
    "periodDatetime": "2024-08-10"
}

Contributing

If you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request on the GitHub repository <https://github.com/preduus/pycasestyle>.

License

This project is licensed under the Apache License 2.0 License. See the LICENSE <https://github.com/preduus/pycasestyle/LICENSE> file for more details.

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

pycasestyle-0.1.3.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

pycasestyle-0.1.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pycasestyle-0.1.3.tar.gz.

File metadata

  • Download URL: pycasestyle-0.1.3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for pycasestyle-0.1.3.tar.gz
Algorithm Hash digest
SHA256 31c89121bae46e5436dc3bfb062d4122f634dde57ca5aa55643137ac284df4f8
MD5 d43b8ed3c38b9e7a105d067fcd38cf95
BLAKE2b-256 a9422c8c0c43b1f259c7474dd2d66b4d835fa9497cd4eda748ad54dd6c968de3

See more details on using hashes here.

File details

Details for the file pycasestyle-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pycasestyle-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for pycasestyle-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7109109110b186ae0f789fc2bb38ca6e9072d4f6f998657f8fe40d690361fb40
MD5 26aa4d73bac4f617b0f2dbd4244b9ef5
BLAKE2b-256 56ddd6d4ef3dac9d2ad86f52ee710a34a102a5a81ec8f796b6047d7f16f0deff

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