orangeqs.juice.identifiers._util#
Module Contents#
Functions#
Generate a unique identifier with the given prefix, service, and timestamp. |
|
Parse an identifier into its components: prefix, service, and timestamp. |
API#
- orangeqs.juice.identifiers._util.generate_id(prefix: str, service: str, timestamp: datetime.datetime | None = None) tuple[str, datetime.datetime, tuple[str, str, str]]#
Generate a unique identifier with the given prefix, service, and timestamp.
If no timestamp is provided, the current UTC time will be used.
The identifier will be in the format
{prefix}_{service}_{timestamp}, wheretimestampis inYYYYMMDDHHMMSSformat.Parameters#
prefix (str): The prefix for the identifier.
service (str): The name of the service generating the identifier.
timestamp (datetime.datetime | None, optional): The timestamp to use for the identifier. If None, the current UTC time is used.
Returns#
(str): The generated identifier.
(datetime.datetime): The timestamp used in the identifier.
(tuple[str, str, str]): The prefix, service and timestamp suffix of the identifier.
Raises#
(ValueError): If the provided timestamp is not timezone-aware.
- orangeqs.juice.identifiers._util.parse_id(identifier: str) tuple[str, str, datetime.datetime]#
Parse an identifier into its components: prefix, service, and timestamp.
The identifier is expected to be in the format
{prefix}_{service}_{timestamp}, wheretimestampis inYYYYMMDDHHMMSSformat.Parameters#
identifier (str): The identifier to decode.
Returns#
(tuple[str, str, datetime.datetime]): A tuple containing the prefix, service, and timestamp.
Raises#
(ValueError): If the identifier format is invalid.