pyutils (haaksmash)

1.0.2 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates the core functionality of the `enum` module for creating robust enumerations and the `TimePeriod` class from the `dates` module for handling date ranges. It showcases how to define an enum with options like `frozen` and `strict`, and how to check if a date falls within a defined time period.

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}")

view raw JSON →