Skip to main content

Foundational Python library

Project description

peprock

Foundational Python library

Python 3.10 pre-commit Code style: black Ruff codecov test PyPI version

peprock is a collection of versatile Python libraries, provided as namespace packages:


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


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)

Uploaded Source

Built Distribution

peprock-1.0.0-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page