Skip to main content

Sortable seven-character timestamps backed by WebAssembly

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.

Development

python -m pip install -e .
python -m unittest discover -s tests
python -m build
python -m twine check dist/*

Regenerate shared artifacts from the repository root:

node wasm.mjs

Publishing

python -m twine upload dist/*

Configure PyPI credentials before publishing.

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.0.tar.gz (55.4 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.0-py3-none-any.whl (55.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lsb32-0.1.0.tar.gz
  • Upload date:
  • Size: 55.4 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.0.tar.gz
Algorithm Hash digest
SHA256 04a7c48f95dfd04b22198a72f56d50a5e4c05be3701f1078706cc730ce198819
MD5 4a9f84f2ed0aadded8f257e36f6a77a6
BLAKE2b-256 bca7ab2f41107ab0e8dd6e7fe47cea8c65cb362ce91d0569b4aa47cb1530a0fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lsb32-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 55.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 369c806ea50f49ca5c3304159eb5ca8e1d6f9f0a0d35e2c55e163bb01610a3ea
MD5 867af27e28548948cea4621d8b822d96
BLAKE2b-256 83ed6fb331bef251e658f07ffce24b2504246e349fe2eef2acd5a9086e37e838

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