Utils Reference

This module provides utilities used within the project.

class pypiwrap.utils.Size(bytes: int, iec: str, si: str)

A tuple that includes human-readable representations of a file size.

bytes: int

The size represented in bytes.

classmethod from_int(num: int) Size
iec: str

The size represented in binary/IEC units (KiB, MiB).

si: str

The size represented in decimal/SI units (KB, MB).

pypiwrap.utils.bytes_to_readable(number: float, unit: Literal['si', 'iec'] = 'si') str

Converts a number (in bytes) to a human-readable string representation.

Parameters:
  • number (float) – A value in bytes.

  • unit (str, optional) – Units to use when representing the result. May be “si” for decimal units (MB) which is the default or “iec” for binary units (MiB).

pypiwrap.utils.iso_to_datetime(iso: str) datetime

Converts an ISO 8601 string to a datetime object.

pypiwrap.utils.remove_additional(cls: type[Any], data: dict[str, Any]) dict[str, Any]

Takes any dataclass cls and a dictionary data that can unpack to it, discards any keys in data that are not fields of the dataclass, and returns a dictionary that can safely unpack to the dataclass.