Skip to main content

A collection of fundamental Python utilities for common tasks

Project description

PyFundamentals

A collection of fundamental Python utilities for common tasks such as string manipulation, date/time formatting, extended enumerations, threading with return values, bash-like operations, and exception handling.

Features

  • Basic Functions: Utility functions for checking empty strings and generating formatted date/time strings.
  • String Utilities: Comprehensive string manipulation including case conversion (CamelCase, snake_case), regex matching, Roman numeral conversion, random string generation, and text normalization.
  • Extended Enums: Enhanced Enum and Flag classes with additional methods like list and from_string for more flexible enumeration handling.
  • Overrides: Decorator-based method override checking for better code reliability in class hierarchies.
  • Threading: ReturningThread class that extends Python's Thread to allow capturing return values from threaded functions.
  • Bash Utilities: Functions to interact with system information like user details, hostname, IP addresses, and tool availability checks.
  • Exceptions: Custom exception classes for handling errors in the library.

Installation

Install from PyPI:

pip install PyFundamentals

Or clone the repository and install locally:

git clone https://github.com/PyFundamentals.git
cd PyFundamentals
pip install .

Usage

Basic Functions

from fundamentals import is_empty_string, now_string

some_value = "test"
if not is_empty_string(some_value):
    timestamp = now_string()  # e.g., "20241027-16:22:33.123456"

String Utilities

from fundamentals import make_cpp_id, IdentifierStringCase

cpp_id = make_cpp_id("some mixed case", IdentifierStringCase.SNAKE)  # "some_mixed_case"

Extended Enums

from enum import auto
from fundamentals import ExtendedEnum

class Color(ExtendedEnum):
    RED = auto()
    GREEN = auto()
    BLUE = auto()

# List all values
colors = Color.list()  # [<Color.RED: 1>, <Color.GREEN: 2>, <Color.BLUE: 3>]

# Parse from string (case-insensitive)
color = Color.from_string("green")  # Color.GREEN

Returning Thread

from fundamentals import ReturningThread

def worker(x, y):
    return x + y

thread = ReturningThread(target=worker, args=(5, 10))
thread.start()
result = thread.join()  # Returns 15

Exceptions

from fundamentals import StringUtilError

raise StringUtilError("An error occurred during string processing")

Testing

Run the test suite:

python -m unittest discover test/

For coverage (requires coverage.py):

coverage run --source=fundamentals -m unittest discover test/
coverage report

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass and code is linted
  5. Submit a pull request

License

This project is licensed under the GNU General Public License version 2 (GPLv2). See the LICENSE file for details.

Author

Dieter J Kybelksties

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

kingkybel_pyfundamentals-0.1.1.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

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

kingkybel_pyfundamentals-0.1.1-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kingkybel_pyfundamentals-0.1.1.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for kingkybel_pyfundamentals-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f4c34730afc881ba6868cee2824757d549f04fb335ed116096c6de3653e89c96
MD5 b41c1148a5741432e089a9ca7e3940ca
BLAKE2b-256 9885313bb4d7e7cad028f77e0b3c00a647a48a64d9b8481660f990e1da34a45c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kingkybel_pyfundamentals-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 445c993eb01d215ffa31efacd8d289b33a53094f9c7a218d338558df8ced8d41
MD5 2c897b3fe79239c6d6f29199bafeb608
BLAKE2b-256 697948a7b0aeada992ebd00aba67defe0d7e0c90db0adf65f2a5afa7cfac0afd

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