leaf_engine.utils.uuid

Attributes

NAMESPACE

Functions

get_ulid(→ str)

Returns ULID for arbitrary set of arguments.

get_uuid(→ str)

Generates a random UUID4. lru_cache decorator makes calls with the same

get_uuid5(→ str)

Return UUID5 for arbitrary set of arguments. UUID5 is computed as a SHA1

is_uuid(→ bool)

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:

str

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:

str

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:

str

leaf_engine.utils.uuid.is_uuid(value: str | uuid.UUID, version=4) bool

Returns True if value is valid UUID.

Parameters:
  • value (Union[str, uuid.UUID]) – String or UUID object.

  • version (int, optional) – UUID version. Defaults to 4.

Returns:

Value is UUID.

Return type:

bool

leaf_engine.utils.uuid.NAMESPACE