Python helper libraries for MMID.
Project description
chatora.mmid
Python helper libraries for MMID which is similar to UUIDv1 but sortable.
Usage
import datetime
import random
import uuid
from chatora.mmid.api import BaseMMID1
BASE_DT = datetime.datetime(2011, 1, 1, tzinfo=datetime.timezone.utc)
class MMID1v0(BaseMMID1):
__slots__ = ('int',)
UUID_VERSION = 4
MMID_VERSION = 0
TS_BIT_LENGTH = 55
EPOCH_DT = datetime.datetime(2010, 1, 1, tzinfo=datetime.timezone.utc)
# Construct
assert MMID1v0().version == 4
assert MMID1v0(dt=BASE_DT).dt == MMID1v0(ts=BASE_DT.timestamp()).dt == BASE_DT
# Sortable, which is useful for RDB column index (PostgreSQL UUID/BYTEA, MySQL BINARY).
assert MMID1v0(dt=BASE_DT) < MMID1v0(dt=BASE_DT + datetime.timedelta(days=1))
clock_seq = random.getrandbits(14)
assert MMID1v0(dt=BASE_DT, clock_seq=clock_seq) == MMID1v0(dt=BASE_DT, clock_seq=clock_seq)
# create_min_instance_from_time()/create_max_instance_from_time() may be useful in case of range query on RDB.
assert MMID1v0.create_min_instance_from_time(
dt=BASE_DT,
) == MMID1v0(hex_='811ed178-c6c0-4000-0000-000000000000')
assert MMID1v0.create_max_instance_from_time(
dt=BASE_DT,
) == MMID1v0(hex_='811ed178-c6c0-4000-ffff-ffffffffffff')
# Compatible with UUID1
uuid1 = uuid.uuid1()
mmid1v0 = MMID1v0(src_uuid1=uuid1)
assert uuid1 == mmid1v0
assert mmid1v0.uuid1 == uuid1
Changelog
0.1 (2019-01-16)
- Birth!
0.1.1 (2019-01-16)
- Remove unused requirements.
0.1.2 (2019-01-17)
- Fix timestamp/datetime precision.
- Accept decimal.Decimal() timestamp values.
0.1.3 (2019-01-17)
- Fix timestamp/datetime precision.
0.1.4 (2019-05-14)
- Remove
structlogdependency.
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
chatora.mmid-0.1.4.tar.gz
(10.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chatora.mmid-0.1.4.tar.gz.
File metadata
- Download URL: chatora.mmid-0.1.4.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
294c100c06cc66bdc30c51904bf6752b716fe61dca53fe1753bdfb433deac9da
|
|
| MD5 |
80089484cf9546b85baf0866defbe389
|
|
| BLAKE2b-256 |
9627544b9025815edcdb89c7a4580553c3965ed6b40b5fddfbd36b2841461262
|
File details
Details for the file chatora.mmid-0.1.4-py37-none-any.whl.
File metadata
- Download URL: chatora.mmid-0.1.4-py37-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3.7
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15446df28732d6159486d724587713394c48d6e95f5b8fe2535b3f291bf8f847
|
|
| MD5 |
ce7922ce411615d2be986a3ae8335f6f
|
|
| BLAKE2b-256 |
2c0518f00cc8a4aa798d6ab202b94dd8795c00602049dde8205625f802f33aa0
|