Skip to main content

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%

Metadata

Release files for mystrtools 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mystrtools 0.1.0
File Size Uploaded Provenance
mystrtools-0.1.0.tar.gz 16.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mystrtools 0.1.0
File Interpreter ABI Platform
mystrtools-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.4 kB

Release files / mystrtools-0.1.0.tar.gz

Download URL mystrtools-0.1.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f5c628c76987d1acbf1199fdb2ffe2d10360b2fbc51ebc38c59818846d7fc5d9
BLAKE2b-256 checksum
How to use checksums
2372c0ff6845c4abc86a9e0a084cda9f4fc71b59ea116a2c972a641e64c71536
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.14.3 Linux/6.18.12-200.fc43.x86_64

Release files / mystrtools-0.1.0-py3-none-any.whl

Download URL mystrtools-0.1.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
573f3b7e9ab060533861463836e257e2c4168998862ad1df696fc5e3d5bc601b
BLAKE2b-256 checksum
How to use checksums
3b65006848ea4870921a6b45ea0da25dcb392a7143c0b0d87378ea1b0643b812
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.14.3 Linux/6.18.12-200.fc43.x86_64

Security for mystrtools 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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