A lightweight collection of reusable Python helper modules for console applications, mathematical operations, exception logging, source-code inspection, input validation, and unit conversion.
Status: Early development. Some modules and interfaces may change.
- Safely prompt for and convert console input.
- Build simple numbered console menus.
- Validate email address formatting.
- Log exceptions and tracebacks to local files.
- Inspect Python files for function and method names.
- Print function docstrings from Python modules.
- Perform arithmetic, fraction, root, rounding, and trigonometric operations.
- Convert common mass, pressure, length, energy, and temperature units.
- Python 3.10 or newer
- No runtime third-party dependencies
Development tools are installed separately through the package's optional development dependencies.
Clone the repository and install the package from the project root:
git clone https://github.com/RemoStain/HelperCollection.git
cd HelperCollection
python -m pip install .For local development, install the package in editable mode with the testing and build tools:
python -m pip install -e ".[dev]"Editable installation allows changes made inside helper_functions/ to be used immediately without reinstalling the package.
After installation, import from the package normally:
from helper_functions.safe_input import safe_input
from helper_functions.unit_converter import UnitConverterfrom helper_functions.safe_input import safe_input
age = safe_input(
expected_type=int,
message="Enter your age: ",
default=18,
)
print(age)Boolean input recognizes values such as true, false, yes, no, 1, and 0.
from helper_functions.unit_converter import UnitConverter
kilograms = UnitConverter.lb_to_kg(10)
celsius = UnitConverter.f_to_c(68)
print(kilograms)
print(celsius)from helper_functions.math_func import add_all, decimal_to_frac, TrigFunctions
print(add_all(2, 4, 6))
print(decimal_to_frac(0.75))
print(TrigFunctions.sin(30, type_=float))Trigonometric functions accept angles in degrees.
from helper_functions.exception_logging import log_exception
try:
result = 10 / 0
except Exception as error:
log_exception(error, verbose=True)Depending on the selected mode, exception details may be written to traceback.txt and log.txt in the current working directory.
from helper_functions.help_call import get_function_names
names = get_function_names("example.py", display=True)
print(names)Provides safer conversion of interactive console input.
| Function | Description |
|---|---|
safe_input(expected_type, message=None, default=None, is_password=False, feedback=False) |
Prompts for input and converts it to the requested type. Supports hidden password input, default values, boolean parsing, and basic interruption handling. |
Contains console and validation helpers.
| Function | Description |
|---|---|
_menu(header="Menu", items=[]) |
Displays a numbered menu and returns the selected item. |
_validate_email(email) |
Checks whether an email address matches the module's expected format. |
_cls() |
Clears the terminal using an ANSI escape sequence. |
_generate_dashes(n=0, title=False) |
Generates separator text for menus. |
_is_truthy(variable=None) |
Returns whether a value is truthy. |
_is_falsy(variable=None) |
Returns whether a value is falsy. |
Names beginning with an underscore should be treated as internal APIs and may change.
| Function | Description |
|---|---|
log_exception(e, verbose=False) |
Logs an exception summary and optionally writes detailed traceback information. |
| Function | Description |
|---|---|
get_function_names(filename, display=False) |
Returns functions and class methods discovered in a Python source file. |
print_docstring(filename, func_name="get_function_names") |
Loads a function from a file and prints its docstring. |
Provides mathematical constants and utility functions.
add_all(*nums, type_=None)sub_all(*nums, type_=None)mult_all(*nums, type_=None)div_all(*nums, floor=False, type_=None)exp_all(*nums, type_=None)div_with_modulo(*nums)
reduce_fraction(numerator, denominator)decimal_to_frac(num)improper_to_proper_frac(numerator, denominator)proper_to_improper_frac(whole, numerator, denominator)rounding(num, decimal=0, type_=None, force=False)
sq_root(num, root=2, type_=None)root_n(num, x, type_=None)apply_discount(number, discount)
describe_math_constant(constant)TrigFunctions.sin(x, type_=None)TrigFunctions.cos(x, type_=None)TrigFunctions.tan(x, type_=None)TrigFunctions.cosecant(x, type_=None)TrigFunctions.secant(x, type_=None)TrigFunctions.cotangent(x, type_=None)TrigFunctions.pythagorean_theorem(a, b, type_=None)
The UnitConverter class supplies static conversion methods.
| Category | Methods |
|---|---|
| Mass | lb_to_kg, kg_to_lb |
| Pressure | mmhg_to_kpa, kpa_to_mmhg |
| Length | ft_to_m, m_to_ft |
| Energy | kcal_to_kj, kj_to_kcal |
| Temperature | f_to_c, c_to_f |
The package's __init__.py exposes these modules:
from helper_functions import (
exception_logging,
helpers_and_menu,
help_call,
math_func,
safe_input,
unit_converter,
)helper_functions/
├── helper_functions/
│ ├── __init__.py
│ ├── exception_logging.py
│ ├── help_call.py
│ ├── helpers_and_menu.py
│ ├── math_func.py
│ ├── safe_input.py
│ └── unit_converter.py
├── tests/
│ ├── conftest.py
│ ├── test_exception_logging.py
│ ├── test_help_call.py
│ ├── test_helpers_and_menu.py
│ ├── test_math_func.py
│ ├── test_package.py
│ ├── test_safe_input.py
│ └── test_unit_converter.py
├── .gitignore
├── pyproject.toml
├── README.md
└── requirements-dev.txt
The project includes a pytest test suite covering package imports and the public behavior of each module.
Install the package with its development dependencies before running the tests:
python -m pip install -e ".[dev]"Run the full suite from the project root:
python -m pytestRun a single test module:
python -m pytest tests/test_safe_input.pyRun a specific test:
python -m pytest tests/test_math_func.py::test_nameUse verbose output:
python -m pytest -vThe test files are organized by module:
| Test file | Coverage area |
|---|---|
test_package.py |
Package imports and exported modules |
test_exception_logging.py |
Exception logging behavior |
test_help_call.py |
Source inspection and docstring helpers |
test_helpers_and_menu.py |
Menu and validation helpers |
test_math_func.py |
Arithmetic, fractions, roots, rounding, and trigonometry |
test_safe_input.py |
Input conversion, defaults, booleans, and interruption handling |
test_unit_converter.py |
Unit conversion methods |
tests/conftest.py contains shared pytest fixtures and test configuration. Add shared setup there only when it is used by multiple test modules.
When adding or changing a public function:
- Add or update the matching tests.
- Run the full test suite.
- Confirm the package can still be imported after installation.
- Update this README when usage or public behavior changes.
Install the build tool through the development dependencies, then build from the project root:
python -m buildThe generated distributions are written to dist/:
dist/
├── helper_functions-<version>-py3-none-any.whl
└── helper_functions-<version>.tar.gz
The build/, dist/, and *.egg-info/ directories are generated files and should not be committed.
- Console clearing depends on ANSI escape-sequence support.
- Trigonometric calculations use custom approximations and may not match the precision or edge-case handling of Python's
mathmodule. unit_converter.pyis marked as work in progress.
When extending the package:
- Keep imports compatible with installed package usage.
- Add or update tests for public behavior.
- Run
python -m pytestbefore committing changes. - Run
python -m buildbefore creating a release. - Update this README when a public interface changes.
No license has been specified.