UniqueId: A Minimal Wrapper around uuid4#
- class my.types.UniqueId.UniqueId(root: RootModelRootType = PydanticUndefined)#
A simple wrapper for uuid4 strings (32 hex digits, hyphenated), with validation & utilities.
Also exported under the shorthand alias
Uid.- root#
The UUID string itself.
Examples
Wrap an existing UUID string (normalized to lowercase), or generate a fresh one:
>>> from my import Uid >>> uid = Uid('D6F00951-6E49-4C56-B443-56774EA3C71D') >>> str(uid) 'd6f00951-6e49-4c56-b443-56774ea3c71d' >>> uid == 'D6F00951-6E49-4C56-B443-56774EA3C71D' True >>> bool(Uid.RGX.fullmatch(Uid.newstr())) True
- classmethod UniqueId.validate_uid(uid: str) str#
Validate and normalize a UUID string.
- Parameters:
uid – UUID string to validate.
- Returns:
Lowercase normalized UUID.
- Raises:
AssertionError – If string is not a valid UUID format.
- classmethod UniqueId.new(uid: str = '') UniqueId#
Create a new UniqueId, generating one if not provided.
- Parameters:
uid – Optional UUID string. If empty, generates a new UUID.
- Returns:
UniqueId instance.
Examples
Wrap a known UUID (note the bare-string repr):
>>> from my import UniqueId >>> UniqueId.new('D6F00951-6E49-4C56-B443-56774EA3C71D') d6f00951-6e49-4c56-b443-56774ea3c71d
- classmethod UniqueId.newstr() str#
Generate a new UUID as a string (just a convenience wrapper around
new()).
- classmethod UniqueId.remove_uids(text: str) str#
Remove all lines containing UUIDs from the given text.
Examples
Strip an identifier line from a block of text:
>>> from my import UniqueId >>> text = 'keep me\nuid: d6f00951-6e49-4c56-b443-56774ea3c71d\nand me' >>> UniqueId.remove_uids(text) 'keep me\nand me'