pyutils (haaksmash)
A grab-bag of utility functions and objects for Python, developed by haaksmash. This library provides common, oft-repeated functionalities across various modules like enums, math, dictionaries, lists, booleans, dates, and objects. It is currently at version 1.0.2 and appears to have a stable, though not rapid, release cadence.
Warnings
- gotcha When defining enums using `utils.enum.Enum` with `Options.frozen = True`, enum members become immutable. Attempting to reassign a value to an enum member (e.g., `Colors.RED = 2`) will raise a `TypeError`.
- gotcha Due to the generic name 'utils', there is a potential for import conflicts with other packages that might define a 'utils' module or with local project modules also named 'utils'.
- deprecated The GitHub repository's last significant commit was over a year ago, suggesting the library may be in maintenance mode with infrequent updates. Users should verify active development if new features or urgent bug fixes are critical.
Install
-
pip install utils
Imports
- enum
from utils import enum
- TimePeriod
from utils.dates import TimePeriod
- flatten
from utils.lists import flatten
Quickstart
from datetime import date
from utils import enum
from utils.dates import TimePeriod
class Colors(enum.Enum):
RED = 0
GREEN = 1
# Defining an Enum class allows you to specify a few
# things about the way it's going to behave.
class Options:
frozen = True # can't change attributes
strict = True # can only compare to itself
# Usage of Enum
print(f"Red enum: {Colors.RED}")
print(f"Is Colors.RED == 0? {Colors.RED == 0}")
# Usage of TimePeriod
time_period = TimePeriod(date(2023, 1, 1), date(2023, 1, 31))
print(f"Time period: {time_period}")
print(f"Is 2023-01-15 in period? {date(2023, 1, 15) in time_period}")