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

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.1.0.tar.gz (11.1 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.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: umt_python-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for umt_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e439dcbf7d07a778dec57ca817bbf2e9e3288df63686debe9628738a189abcd8
MD5 f81494c9d46e4d83eb52725e2e3dfa83
BLAKE2b-256 2aec0be4ac172be2376c9278620d88d0155d95bf46b3baca99bb4b8d4cc6c8da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: umt_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for umt_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abd1b1c47134f645e82783a43718a2db34eaf12d464aec7b8b64e29a0717608e
MD5 c5b0db82466ce47f6565765c13014738
BLAKE2b-256 4866e273629c8a07fa53cb7fc9127b60e28002dd750e3ffd1084e4270b2ddd1d

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