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.patterns: Reusable software design patterns.
- peprock.subclasses: Class hierarchy helpers.
API documentation
Full API documentation is published to api.peprock.ponte.energy.
Overview and examples
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.patterns
Reusable software design patterns.
Observer
>>> from peprock.patterns import Subject, Observer
>>> class MyObserver(Observer):
>>> def notify(self, __subject, message):
>>> print(f"My observer notified by {type(subject).__name__}: {message}")
>>> observer = MyObserver()
>>> subject = Subject()
>>> subject.register_observer(observer)
>>> subject.notify_observers("Hello, world!")
My observer notified by Subject: Hello, world!
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.1.0.tar.gz
(8.3 kB
view details)
Built Distribution
File details
Details for the file peprock-1.1.0.tar.gz
.
File metadata
- Download URL: peprock-1.1.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa9d4fd2d79303b6a10161b14992dea62b3c908893472cd4eaabb0fcb20bc51d |
|
MD5 | cc5fce1efb2dff5d66222271169f4e82 |
|
BLAKE2b-256 | 24a3e149914b270c8ac6361711775692bd16804d30b4e0549957ec72a057d4fa |
File details
Details for the file peprock-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: peprock-1.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4e2cae446b714b9b1b746778f6d96923454e891101907ef70034ab18fc0f7d1 |
|
MD5 | 563c039894e5ab18571a22cc270454c6 |
|
BLAKE2b-256 | ea6e83e34b1b98ad9b3db84308897eacf1197de867e9230245dcdb64168c923e |