用于mmid的python帮助程序库。
chatora.mmid的Python项目详细描述
chatora.mmid
用于mmid的python助手库,类似于uuidv1,但可排序。
用法
importdatetimeimportrandomimportuuidfromchatora.mmid.apiimportBaseMMID1BASE_DT=datetime.datetime(2011,1,1,tzinfo=datetime.timezone.utc)classMMID1v0(BaseMMID1):__slots__=('int',)UUID_VERSION=4MMID_VERSION=0TS_BIT_LENGTH=55EPOCH_DT=datetime.datetime(2010,1,1,tzinfo=datetime.timezone.utc)# ConstructassertMMID1v0().version==4assertMMID1v0(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).assertMMID1v0(dt=BASE_DT)<MMID1v0(dt=BASE_DT+datetime.timedelta(days=1))clock_seq=random.getrandbits(14)assertMMID1v0(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.assertMMID1v0.create_min_instance_from_time(dt=BASE_DT,)==MMID1v0(hex_='811ed178-c6c0-4000-0000-000000000000')assertMMID1v0.create_max_instance_from_time(dt=BASE_DT,)==MMID1v0(hex_='811ed178-c6c0-4000-ffff-ffffffffffff')# Compatible with UUID1uuid1=uuid.uuid1()mmid1v0=MMID1v0(src_uuid1=uuid1)assertuuid1==mmid1v0assertmmid1v0.uuid1==uuid1
更改日志
0.1(2019-01-16)
- 出生!
0.1.1(2019-01-16)
- 删除未使用的要求。
0.1.2(2019-01-17)
- 固定时间戳/日期时间精度。
- 接受decimal.decimal()时间戳值。
0.1.3(2019-01-17)
- 固定时间戳/日期时间精度。
0.1.4(2019-05-14)
- 删除
structlog
依赖项。