Skip to main content

Compact, sortable UTC timestamp identifiers for distributed applications

Project description

LSB32 for Python

LSB32 converts timezone-aware Python datetime values into compact, sortable, seven-character identifiers.

2026-01-01 00:00:00 UTC -> D110000

The package handles epoch offsets, packed bits, Crockford symbols, padding, WebAssembly calls, and calendar reconstruction internally.

Installation

pip install lsb32

Quick start

from datetime import datetime, timezone
from LSB32 import decode, encode

original = datetime(2026, 1, 1, tzinfo=timezone.utc)
value = encode(original)

assert value == "D110000"
assert decode(value) == original

Current time

from LSB32 import decode, now

value = now()
created = decode(value)

now() returns the encoded string directly. Decoding returns a timezone-aware UTC datetime rounded to the encoded second.

Custom epoch

The default epoch is 2000 and covers calendar years 2000 through 2063. Pass the same custom epoch to both operations when another 64-year window is needed:

from datetime import datetime, timezone
from LSB32 import decode, encode

original = datetime(2089, 12, 31, 23, 59, 59, tzinfo=timezone.utc)
value = encode(original, epoch=2026)
restored = decode(value, epoch=2026)

assert restored == original

The epoch is not stored in the identifier. Producers and consumers must use the same value.

API

Function Result
encode(datetime, epoch=2000) Seven-character str
decode(value, epoch=2000) UTC datetime
now(epoch=2000) Current time as a seven-character str

encode requires timezone information and converts the input to UTC. Subsecond precision is discarded because the wire format stores whole seconds.

Errors

from LSB32 import Error, decode

try:
    decode("D110001")
except Error as failure:
    print(failure.code, failure)

Error reports invalid length, alphabet symbols, padding, date components, and dates outside the configured epoch.

Architecture

The wheel includes lsb32.wasm and lsb32.wat. Wasmtime executes the binary module; WAT is included for inspection and reproducible tooling. The public API does not expose raw integers or WASM status codes.

License

This package is licensed under the GNU Lesser General Public License, either version 3 or any later version. See LICENSE and COPYING.

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

lsb32-0.1.1.tar.gz (55.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lsb32-0.1.1-py3-none-any.whl (55.5 kB view details)

Uploaded Python 3

File details

Details for the file lsb32-0.1.1.tar.gz.

File metadata

  • Download URL: lsb32-0.1.1.tar.gz
  • Upload date:
  • Size: 55.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for lsb32-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7eb211c1ce0a2d0156f62ec0d2e6c35f499eb553bdb3f2f5dcd8d3095ff7a2c1
MD5 0e3fb231e4853e326b9ed88f43a1a44e
BLAKE2b-256 259ed6a0d1f065220f02e3d520152a0150fa337919bdcbd76cc5a74368c6264b

See more details on using hashes here.

File details

Details for the file lsb32-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lsb32-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 55.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for lsb32-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2c9aa33b93a8a38389b3cb1ac4924e540b508dab9c46538d658a1a113361598
MD5 f7e43c11552669cc031c75a3e0b7e861
BLAKE2b-256 5cc1018143b4d4fea6dbd877f2e6bad80aa0610bc0c24b0e0eb875c998ed0a48

See more details on using hashes here.

Supported by

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