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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for umt_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b5f8643d370e22867735a972a2f5e6ec97206406801703a38c49720953929675
MD5 bca3d4652660f974e2a156873b4264b9
BLAKE2b-256 06c1608e13fdee63cb3e0d9052c1cb0281e6bd9d59da894f449586701c9c2b89

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for umt_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b13fdfb77adceef2b2db613774926bfef3bc1d2a1d75be746fae93f791d9e4e
MD5 3f9b3be10ff5c7de8a1283c7141692c3
BLAKE2b-256 665713eb6dde0e055801b8304d384b0f3bee43d20bc29e41d6064063593a7df4

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