ulidx
ULID generation and conversion. A ULID is a 128-bit identifier that is both lexicographically sortable by creation time and random enough to be used as a primary key — 26 characters in Crockford base32, no hyphens.
Install
pip install ulidx
Usage
from ulidx import Ulid
# plain generation
Ulid.generate() # '01J8Z9K2M3N4P5Q6R7S8T9V0WX'
# guaranteed strictly increasing within a process, even in the same millisecond
Ulid.generate(n_monotonic=True)
# pin the timestamp (aware or naive datetime, or epoch seconds)
Ulid.generate(n_timestamp=1700000000)
# bulk
Ulid.generate_batch(1000)
# back and forth
value = Ulid.generate()
Ulid.to_timestamp(value) # float, epoch seconds
Ulid.to_time(value) # datetime in UTC+8
Ulid.to_bytes(value) # 16 raw bytes
Ulid.by_bytes(Ulid.to_bytes(value)) # round trip
Ulid.to_uuid(value) # uuid.UUID
Ulid.from_uuid(some_uuid) # 26-char str
API
| Method | Description |
|---|---|
generate(ts=None, monotonic=False) |
New 26-character ULID |
generate_batch(count, ...) |
List of ULIDs |
generate_uuid(ts=None, ...) |
New ULID as uuid.UUID |
by_bytes(data) |
16 bytes to ULID string |
to_bytes(ulid) |
ULID (str / bytes / UUID) to 16 bytes |
to_timestamp(ulid) |
Epoch seconds encoded in the ULID |
to_time(ulid, hour_offset=8) |
datetime in the given UTC offset |
to_uuid(ulid) / from_uuid(uuid) |
Convert between ULID and uuid.UUID |
Monotonicity
n_monotonic=True keeps the generator state per thread, so concurrent threads
never share a counter. Within a thread, ULIDs produced in the same millisecond
strictly increase, which keeps sorting stable when several IDs are created in
one tick.
License
MIT
Metadata
Release files for ulidx 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ulidx-0.0.1.tar.gz | 7.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ulidx-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.6 kB
Release files / ulidx-0.0.1.tar.gz
| Download URL | ulidx-0.0.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1599dcab5ccc3f991c99fbe0d13991e231dd72befd562fe9f67c1a28c934046
|
|
BLAKE2b-256 checksum How to use checksums |
f0ec81608253863fd528aded6f680b0338a9976a70e868b35f749e55a0b6a462
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / ulidx-0.0.1-py3-none-any.whl
| Download URL | ulidx-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
574ca9d53cdf109d8684f6f0a31f6177a15e985b7a852a8af5dfc50201387ae5
|
|
BLAKE2b-256 checksum How to use checksums |
b7b9012ad7fef58a9f51d14f310e08dfaa3d59b1c18e74c38b4b6519d4be65fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Security for ulidx 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.