Skip to main content

No project description provided

Project description

mystrtools

Python Version Version Tests Coverage DOI

Small Python utilities to convert strings across common naming styles.

Supported styles:

  • camelCase
  • PascalCase
  • snake_case
  • kebab-case
  • space separated words

Citation

If you use mystrtools, please cite it using CITATION.cff.

DOI: 10.5281/zenodo.18832671

Installation

With Poetry:

poetry install

Or as a package dependency:

pip install mystrtools

Quick Start

from mystrtools import camel_case, snake_case, kebab_case, pascal_case, camel_to_spaces

camel_case("hello_world")         # "helloWorld"
pascal_case("hello_world")        # "HelloWorld"
snake_case("HelloWorld")          # "hello_world"
kebab_case("HelloWorld")          # "hello-world"
camel_to_spaces("JSONParser")     # "json parser"

Core Methods

camel_case(text: str) -> str

Converts any supported input style to camelCase.

pascal_case(text: str) -> str

Converts any supported input style to PascalCase.

snake_case(text: str) -> str

Converts any supported input style to snake_case.

kebab_case(text: str) -> str

Converts any supported input style to kebab-case.

camel_to_spaces(text: str) -> str

Converts any supported input style to lowercase space-separated words.

Generic Cross-Format Conversion

convert_case(text: str, to_format: CaseFormat) -> str

CaseFormat accepted values:

  • "camel"
  • "pascal"
  • "snake"
  • "kebab"
  • "space"

Example:

from mystrtools import convert_case

convert_case("hello_world", "camel")   # "helloWorld"
convert_case("JSONParser", "snake")    # "json_parser"
convert_case("convert2JSON", "space")  # "convert 2 json"

If to_format is not valid, convert_case raises ValueError.

Explicit Transition Methods

All direct transitions are also available as dedicated helper functions.

From camel:

  • camel_to_pascal
  • camel_to_snake
  • camel_to_kebab
  • camel_to_space

From pascal:

  • pascal_to_camel
  • pascal_to_snake
  • pascal_to_kebab
  • pascal_to_space

From snake:

  • snake_to_camel
  • snake_to_pascal
  • snake_to_kebab
  • snake_to_space

From kebab:

  • kebab_to_camel
  • kebab_to_pascal
  • kebab_to_snake
  • kebab_to_space

From space-separated:

  • space_to_camel
  • space_to_pascal
  • space_to_snake
  • space_to_kebab

Example:

from mystrtools import snake_to_camel, kebab_to_snake, space_to_pascal

snake_to_camel("hello_world")  # "helloWorld"
kebab_to_snake("hello-world")  # "hello_world"
space_to_pascal("hello world") # "HelloWorld"

Compatibility Matrix

The table below shows supported conversions between source and target styles.

From \ To camel pascal snake kebab space
camel camel_case / convert_case(..., "camel") camel_to_pascal camel_to_snake camel_to_kebab camel_to_space
pascal pascal_to_camel pascal_case / convert_case(..., "pascal") pascal_to_snake pascal_to_kebab pascal_to_space
snake snake_to_camel snake_to_pascal snake_case / convert_case(..., "snake") snake_to_kebab snake_to_space
kebab kebab_to_camel kebab_to_pascal kebab_to_snake kebab_case / convert_case(..., "kebab") kebab_to_space
space space_to_camel space_to_pascal space_to_snake space_to_kebab camel_to_spaces / convert_case(..., "space")

Note: all methods share the same normalization behavior (acronyms, mixed separators, numbers, and blank input handling).

Quick examples by source format:

from mystrtools import convert_case

convert_case("helloWorld", "snake")   # camel -> snake: "hello_world"
convert_case("HelloWorld", "kebab")  # pascal -> kebab: "hello-world"
convert_case("hello_world", "pascal")# snake -> pascal: "HelloWorld"
convert_case("hello-world", "camel") # kebab -> camel: "helloWorld"
convert_case("hello world", "snake") # space -> snake: "hello_world"

Edge-Case Conversion Matrix

Reference outputs for common tricky inputs:

Input camel pascal snake kebab space
JSONParser jsonParser JsonParser json_parser json-parser json parser
convert2JSON_value convert2JsonValue Convert2JsonValue convert_2_json_value convert-2-json-value convert 2 json value
multiple---separators__here multipleSeparatorsHere MultipleSeparatorsHere multiple_separators_here multiple-separators-here multiple separators here
`` (empty string) `` `` `` `` ``

Normalization Rules

The library applies the same normalization logic across all methods:

  • Handles mixed separators (_, -, spaces, punctuation)
  • Splits acronyms consistently (JSONParser -> json parser)
  • Keeps numeric blocks (version2Update -> version_2_update in snake)
  • Returns an empty string for empty/blank input

Development

Run tests:

pytest -q

Testing & Coverage

The project is configured to run tests with coverage reporting.

Run full test suite with coverage:

pytest

Generated artifacts:

  • Terminal coverage summary
  • HTML report in coverage/coverage_html
  • XML report in coverage/coverage.xml
  • JSON report in coverage/coverage.json

Example result:

61 passed
TOTAL ... 100%

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

mystrtools-0.1.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

mystrtools-0.1.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file mystrtools-0.1.0.tar.gz.

File metadata

  • Download URL: mystrtools-0.1.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Linux/6.18.12-200.fc43.x86_64

File hashes

Hashes for mystrtools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f5c628c76987d1acbf1199fdb2ffe2d10360b2fbc51ebc38c59818846d7fc5d9
MD5 342f6079a2b5199983374c1aac0c0d5b
BLAKE2b-256 2372c0ff6845c4abc86a9e0a084cda9f4fc71b59ea116a2c972a641e64c71536

See more details on using hashes here.

File details

Details for the file mystrtools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mystrtools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Linux/6.18.12-200.fc43.x86_64

File hashes

Hashes for mystrtools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 573f3b7e9ab060533861463836e257e2c4168998862ad1df696fc5e3d5bc601b
MD5 8a9eac9816f7045417275c7bf7d0fa7f
BLAKE2b-256 3b65006848ea4870921a6b45ea0da25dcb392a7143c0b0d87378ea1b0643b812

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page