Skip to main content

StringBender

Sub-class of Python str that adds case conversion functions. They are especially useful for transforming data model field names, ex: REST (camelCase) to Python (snake_case).

Table of Contents

Installation

From the command line:

pip install stringbender

or if you're using poetry:

poetry add stringbender

Functions

StringBender provides the following static functions for converting the case of a specified string:

These helper methods call a corresponding method in the stringbender.String class and converts the output to str.

Usage:

from stringbender import camel, kebob, pascal, snake, String

# ================================================================================
# EXAMPLES                           # OUTPUT

s = "Hasta la vista baby"
print(camel(s))                      # hastaLaVistaBaby
print(kebob(s)                       # hasta-la-vista-baby
print(pascal(s))                     # HastaLaVistaBaby
print(snake(s))                      # hasta_la_vista_baby

# ================================================================================
# Using a StringBender method with a built-in function

# Create an instance of stringbender.String:
s = String("vote*for*pedro")

# Check the default output:
print(s.camel())                     # vote*For*Pedro (hmm... this isn't right)

# Pass in a custom delimiter:
print(s.replace("*", " ").camel())   # voteForPedro (Much better!)

# ================================================================================
# Using a list of delimiters
s = snake("Careful man, there's a beverage here!", delimiters=[",", "'", "!"])
print(snake(s))                      # careful_man_there_s_a_beverage_here

The String Class

stringbender.String


Methods
Optional argument definitions below

camel() (String) :

Combines all words and he first letter of the first word is lower case, while the first letter of every subsequent word is uppercase.

kebob() (String)

Creates a hyphen delimited lower-case string.

pascal() (String)

Combines all words, and capitalizes the first letter of each word.

snake() (String)

Creates an underscore delimited lower-case string.

as_str() (str)

Returns the value as a str. This is the same as str(String(...))

Constants

DEFAULT_DELIMITERS: List[str] = [" ", ".", "-", "_", ":", "\\"]

Optional Method Arguments

delimiters: List[str] = DEFAULT_DELIMITERS
Used to split the string into words.

split_on_first_upper: bool
Splits on the first occurence of a capital letter following a lowercase letter.

title_case: bool
For character-delimited strings (kebob, snake), This will capitalize the first letter of each word.

Metadata

Release files for stringbender 0.4.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 stringbender 0.4.0
File Size Uploaded Provenance
stringbender-0.4.0.tar.gz 4.9 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 10.1 kB

Release files / stringbender-0.4.0.tar.gz

Download URL stringbender-0.4.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b0e38588d8c57f3a1dc1c8526ef3ad107c898ef3c28a8cd98029080fc2400a62
BLAKE2b-256 checksum
How to use checksums
85c165fd71e90458ce5e1b0fd22fd86644d5941f197c5a29f442cb772eceef6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1025-azure

Release files / stringbender-0.4.0-py3-none-any.whl

Download URL stringbender-0.4.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
639e3ae54714203b2c2d8a6a083a4e4210e7f92cfef84ff9ad8daff0fe855006
BLAKE2b-256 checksum
How to use checksums
5ec21ea69a29b770da8d0f48af0089337e36d70f8c732e775fc32d92f02488c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1025-azure

Security for stringbender 0.4.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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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