leaf_engine.utils.uuid ====================== .. py:module:: leaf_engine.utils.uuid Attributes ---------- .. autoapisummary:: leaf_engine.utils.uuid.NAMESPACE Functions --------- .. autoapisummary:: leaf_engine.utils.uuid.get_ulid leaf_engine.utils.uuid.get_uuid leaf_engine.utils.uuid.get_uuid5 leaf_engine.utils.uuid.is_uuid Module Contents --------------- .. py:function:: 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. :rtype: str .. py:function:: 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') .. py:function:: get_uuid5(*args) -> str Return UUID5 for arbitrary set of arguments. UUID5 is computed as a SHA1 hash of args. :returns: UUID5 string. :rtype: str .. py:function:: is_uuid(value: Union[str, uuid.UUID], version=4) -> bool Returns True if value is valid UUID. :param value: String or UUID object. :type value: Union[str, uuid.UUID] :param version: UUID version. Defaults to 4. :type version: int, optional :returns: Value is UUID. :rtype: bool .. py:data:: NAMESPACE