Foundational Python library
Project description
peprock
Foundational Python library
peprock is a collection of versatile Python libraries, provided as namespace packages:
- peprock.datetime: Date/time and related helpers and constants.
- peprock.models: General purpose model classes.
- peprock.subclasses: Class hierarchy helpers.
peprock.datetime
Date/time and related helpers and constants.
Complements the datetime package from the standard library, adding timezone awareness helpers and timedelta constants.
Timezone awareness helpers
>>> from datetime import datetime, timezone
>>> from peprock.datetime import ensure_aware, is_aware, is_naive
>>> naive = datetime.now()
>>> is_naive(naive)
True
>>> is_aware(naive)
False
>>> aware = ensure_aware(naive, assumed_tz=timezone.utc)
>>> is_naive(aware)
False
>>> is_aware(aware)
True
Timedelta constants
>>> from datetime import datetime
>>> from peprock.datetime import ONE_SECOND, ONE_HOUR
>>> dt = datetime(2023, 3, 2, 21, 17, 12)
>>> dt + ONE_HOUR + 5 * ONE_SECOND
datetime.datetime(2023, 3, 2, 22, 17, 17)
peprock.models
General purpose model classes.
Metric prefix
>>> from peprock.models import MetricPrefix
>>> MetricPrefix.mega.convert(5, to=MetricPrefix.kilo)
5000
>>> MetricPrefix.centi.convert(0.7, to=MetricPrefix.milli)
7.0
peprock.subclasses
Class hierarchy helpers.
>>> from peprock import subclasses
>>> subclasses.get(int)
{<enum 'IntEnum'>, <class 'sre_constants._NamedIntConstant'>, <enum 'IntFlag'>, <class 'bool'>}
>>> subclasses.get_by_name(int, name="bool")
<class 'bool'>
>>> len(subclasses.get(object))
568
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
peprock-1.0.0.tar.gz
(7.2 kB
view hashes)