Skip to main content

A collection of useful utility functions for various tasks in Python, focusing on string manipulation and formatting.

Project description

UMT Python Package

UMT Python Package is a collection of useful utility functions for various tasks in Python, focusing on string manipulation and formatting.

Install

pip install umt-python

# or using uv
uv add umt-python

# or using poetry
poetry add umt-python

Quick Start

from umt_python import random_string, format_string, to_base64

# Generate a random string
random_str = random_string(10)
print(random_str)  # e.g., "aBcD3fGh1j"

# Format a string with placeholders
formatted = format_string("Hello, {0}! Today is {1}.", "World", "Monday")
print(formatted)  # "Hello, World! Today is Monday."

# Encode string to Base64
encoded = to_base64("Hello World")
print(encoded)  # "SGVsbG8gV29ybGQ="

Function List

String Manipulation Functions

Function Type Description Example
delete_spaces (string_: str) -> str Remove all whitespace characters from a string delete_spaces("Hello World") # "HelloWorld"
format_string (template: str, *values: object) -> str Replace placeholders {0}, {1}, etc. in a template string format_string("Sum of {0} and {1} is {2}", 1, 2, 3) # "Sum of 1 and 2 is 3"
reverse_string (char: str) -> str Reverse a string reverse_string("Hello") # "olleH"
to_half_width (string_: str) -> str Convert full-width characters to half-width to_half_width("Hello 123") # "Hello 123"

Base64 Encoding Functions

Function Type Description Example
to_base64 (char: str) -> str Encode a string to Base64 to_base64("Hello") # "SGVsbG8="
from_base64 (base64_string: str) -> str Decode a Base64 string from_base64("SGVsbG8=") # "Hello"

String Padding Functions

Function Type Description Example
pad_start (string_: str, target_length: int, pad_string: str) -> str Pad string from the start to reach target length pad_start("123", 5, "0") # "00123"
pad_end (string_: str, target_length: int, pad_string: str) -> str Pad string from the end to reach target length pad_end("abc", 5, "0") # "abc00"

String Trimming Functions

Function Type Description Example
trim_characters (string_: str, chars: str) -> str Remove specified characters from both ends trim_characters("-.-hello-.-", "-.") # "hello"
trim_start_characters (string_: str, chars: str) -> str Remove specified characters from the start trim_start_characters("!!!hello", "!") # "hello"
trim_end_characters (string_: str, chars: str) -> str Remove specified characters from the end trim_end_characters("hello!!!", "!") # "hello"

Random String Generation

Function Type Description Example
random_string (size: int = 8, char_pool: str = DEFAULT_RANDOM_STRING_CHARS) -> str Generate a random string of specified length random_string(10) # "aBcD3fGh1j"
random_string_initialization (char_pool: str = DEFAULT_RANDOM_STRING_CHARS) -> Callable[[int], str] Create a custom random string generator with specific character pool custom_random = random_string_initialization("xyz")custom_random(3) # "xyx"

String Validation Functions

Function Type Description Example
has_no_letters (text: str) -> bool Check if string contains no letters (only numbers, emojis, special chars) has_no_letters("123!@#") # True / has_no_letters("abc123") # False

Number Functions

Function Type Description Example
format_number (value: float | int, *, locale: str | None = None, minimum_fraction_digits: int | None = None, maximum_fraction_digits: int | None = None, style: Literal["decimal", "currency", "percent"] = "decimal", currency: str | None = None) -> str Format a number with locale-aware separators, fraction-digit controls, and decimal/percent/currency styles. Mirrors Intl.NumberFormat from the TypeScript source. format_number(1234567.89) # "1,234,567.89" / format_number(1234567.89, locale="de-DE") # "1.234.567,89" / format_number(0.75, style="percent") # "75%" / format_number(1234.5, style="currency", currency="USD") # "$1,234.50"
to_ordinal (value: int | float) -> str Convert a number to its English ordinal string (handles 11th/12th/13th specially) to_ordinal(1) # "1st" / to_ordinal(11) # "11th" / to_ordinal(21) # "21st"
to_percentage (value: float | int, total: float | int, decimals: int = 2) -> float Calculate the percentage of a value relative to a total (returns 0 when total is 0) to_percentage(1, 3) # 33.33 / to_percentage(25, 100) # 25.0

Constants

  • DEFAULT_RANDOM_STRING_CHARS: Default character pool for random string generation (ASCII letters + digits)

Requirements

  • Python 3.9 or higher

Development

This project uses uv for dependency management.

# Install dependencies
uv sync

# Run tests
uv run pytest

# Format code
uv run ruff format

# Lint code
uv run ruff check

License

MIT License

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

umt_python-0.3.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

umt_python-0.3.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file umt_python-0.3.0.tar.gz.

File metadata

  • Download URL: umt_python-0.3.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for umt_python-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4d48c40e816095f15d398df63f8d3cb5762a3c4f0121fd9a5cbecd2690c5d2f4
MD5 f09e77a15822d909f3822c708bc0b265
BLAKE2b-256 5defb8619b3a83a4bac38067f288f57c49bf0a525246e350621e2d80e483204c

See more details on using hashes here.

File details

Details for the file umt_python-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: umt_python-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for umt_python-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bb08e7a03137b786ffc471d947e65c757d5f8b1f8c259cbfab311d0fbff9c00
MD5 aff2786ff59b5532eed806d8638b50cc
BLAKE2b-256 692e487344bb1303c4694ff0754105348f207be8c2f5a4f3da95bacc224ae9d0

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