uuid-utils
uuid-utils is a Python library that provides a fast, drop-in replacement for Python's standard `uuid` module, leveraging Rust for performance. It supports all standard UUID versions (1, 3, 4, 5) and also newer draft versions like UUIDv6, UUIDv7, and UUIDv8. Currently at version 0.14.1, the library maintains an active release cadence with frequent updates and performance enhancements.
Warnings
- breaking The byte-order for `uuid1` and `uuid6` was fixed in version 0.14.1. If you relied on the previous, incorrect byte-order in earlier versions, this change may break compatibility with existing data or systems.
- deprecated Support for Python 3.7 was dropped in version 0.7.0. Users on Python 3.7 will not be able to upgrade to newer versions of `uuid-utils`.
- gotcha The default `UUID` class returned by `uuid_utils` is a custom class. If you require standard library `uuid.UUID` instances (e.g., for ORMs like Django), you must import from `uuid_utils.compat`.
- gotcha The behavior of `getnode` was changed in version 0.14.0 to be compatible with Python's standard library `uuid.getnode()`. If your application relied on the specific behavior of `getnode` in earlier `uuid-utils` versions, this might introduce subtle changes.
- gotcha While `uuid-utils` explicitly calls to 'reseed RNG in fork process' (since 0.14.0) to improve multiprocessing safety for random UUIDs, standard library's `uuid.uuid4()` has historically had issues where child processes generated identical UUIDs if the RNG was not reseeded. Although `uuid-utils` addresses this, always test UUID generation thoroughly in multiprocessing environments to ensure uniqueness.
Install
-
pip install uuid-utils
Imports
- uuid
import uuid_utils as uuid
- uuid4
from uuid_utils import uuid4
- UUID
from uuid_utils.compat import UUID
Quickstart
import uuid_utils as uuid
# Generate a random UUID (Version 4)
random_uuid = uuid.uuid4()
print(f"Random UUID (v4): {random_uuid}")
# Generate a time-ordered UUID (Version 7)
time_ordered_uuid = uuid.uuid7()
print(f"Time-ordered UUID (v7): {time_ordered_uuid}")
# Generate a name-based UUID using SHA-1 hash (Version 5)
namespace_dns = uuid.NAMESPACE_DNS
name_uuid = uuid.uuid5(namespace_dns, 'example.com')
print(f"Name-based UUID (v5) for 'example.com': {name_uuid}")
# To get a standard library UUID instance (e.g. for Django):
from uuid_utils.compat import uuid4 as compat_uuid4
compat_instance = compat_uuid4()
print(f"Compat UUID (v4): {compat_instance}")
print(f"Is compat instance a standard uuid.UUID? {isinstance(compat_instance, uuid.UUID)}")