leaf_engine.utils.uuid
Attributes
Functions
|
Returns ULID for arbitrary set of arguments. |
|
Generates a random UUID4. lru_cache decorator makes calls with the same |
|
Return UUID5 for arbitrary set of arguments. UUID5 is computed as a SHA1 |
|
Returns True if value is valid UUID. |
Module Contents
- leaf_engine.utils.uuid.get_ulid(*args) str
Returns ULID for arbitrary set of arguments.
ULIDs are computed as a timestamp encoding + some random bytes. See here for more info: https://blog.daveallie.com/ulid-primary-keys. Calling this function with the same arguments returns the same ULID value.
Attempts to implement ULID as currently implemented in Postgres - see here: https://bitbucket.org/leaflogistics/migrations/src/production/archive/setup/extensions/generate_ulid.sql
``` SELECT (lpad(to_hex(floor(extract(epoch FROM clock_timestamp()) * 1000)::bigint), 12, ‘0’) ||
encode(gen_random_bytes(10), ‘hex’))::uuid;
- Returns:
ULID string.
- Return type:
- leaf_engine.utils.uuid.get_uuid(*args) str
Generates a random UUID4. lru_cache decorator makes calls with the same args return the same UUID. Args must be hashable.
>>> get_uuid(1, "a") >>> df[column].apply(get_uuid, 'RANDOM_ARG')
- Return type:
- leaf_engine.utils.uuid.get_uuid5(*args) str
Return UUID5 for arbitrary set of arguments. UUID5 is computed as a SHA1 hash of args.
- Returns:
UUID5 string.
- Return type:
- leaf_engine.utils.uuid.is_uuid(value: str | uuid.UUID, version=4) bool
Returns True if value is valid UUID.
- leaf_engine.utils.uuid.NAMESPACE