b64uuid.b64uuid module

class b64uuid.b64uuid.B64UUID(initial: Union[None, uuid.UUID, str, bytes, int] = None)[source]

Bases: object

Class represents Base64 URL safe UUID

Parameters

initial (None, uuid.UUID, str, bytes, int) –

The parameter will be converted to uuid.UUID, and assigned to uuid property of the new created instance.

The way of converting to uuid.UUID:

  • Case None (default) : Automatic generated by uuid.uuid4()

  • Case uuid.UUID : No convertion

  • Case strIt should be one of:
    • An UUID string of 32 hexadecimal digits

    • A Base64 URL safe UUID string

  • Case bytes : A string of 16 bytes in big-endian order

  • Case int : A single 128-bit integer

property string: str

Base64 URL safe UUID of the instance

Returns

An URL safe string represents the UUID value of the instance

Return type

str

Note

The property is the same as converting to str:

from b64uuid import Base64UUID

bid = Base64UUID()
s1 = bid.string
s2 = str(bid)

assert s1 == s2  # equals!
property uuid: uuid.UUID

UUID of the instance

Returns

Corresponding stdlib UUID object of the instance

Return type

uuid.UUID

b64uuid.b64uuid.b64id_to_uuid(s: str) uuid.UUID[source]

Convert a Base64 URL safe ID string to an uuid.UUID object

Parameters

s (str) – The UUID string in Base64 url safe style

Returns

Corresponding stdlib UUID object

Return type

uuid.UUID

b64uuid.b64uuid.uuid_to_b64id(value: uuid.UUID) str[source]

Convert an uuid.UUID object to a Base64 URL safe ID string

Parameters

value (uuid.UUID) – The UUID to convert

Returns

Base64 URL safe ID string

Return type

str