You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module extends immutable UUID objects (the UUID class) with the functions `uuid6()`and `uuid7()` from [the IETF draft][draft repository].
10
+
This module extends immutable UUID objects (the UUID class) with the functions `uuid6()`, `uuid7()`, and `uuid8()` from [the IETF draft][draft repository].
11
11
12
12
## Install
13
13
@@ -18,7 +18,7 @@ pip install uuid6
18
18
## Usage
19
19
20
20
```python
21
-
from uuid6 import uuid6, uuid7
21
+
from uuid6 import uuid6, uuid7, uuid8
22
22
23
23
my_uuid = uuid6()
24
24
print(my_uuid)
@@ -27,8 +27,20 @@ assert my_uuid < uuid6()
27
27
my_uuid = uuid7()
28
28
print(my_uuid)
29
29
assert my_uuid < uuid7()
30
+
31
+
my_uuid = uuid8()
32
+
print(my_uuid)
33
+
assert my_uuid < uuid8()
30
34
```
31
35
36
+
## Which UUID version should I use?
37
+
38
+
> Implementations SHOULD utilize UUID version 7 over UUID version 1 and 6 if possible.
39
+
40
+
UUID version 7 features a time-ordered value field derived from the widely implemented and well known Unix Epoch timestamp source, the number of milliseconds seconds since midnight 1 Jan 1970 UTC, leap seconds excluded. As well as improved entropy characteristics over versions 1 or 6.
41
+
42
+
If your use case requires greater granularity than UUID vesion 7 can provide, you might consider UUID version 8. UUID version 8 doesn't provide as good entropy characteristics as UUID version 7, but it utilizes timestamp with nanosecond level of precision.
-`unix_ts_ms`: 48 bit big-endian unsigned number of Unix epoch timestamp with millisecond level of precision
83
-
-`ver`: The 4 bit UUIDv7 version (0111)
93
+
-`ver`: The 4 bit UUIDv8 version (1000)
84
94
-`subsec_a`: 12 bits allocated to sub-second precision values
85
95
-`var`: 2 bit UUID variant (10)
86
96
-`subsec_b`: 8 bits allocated to sub-second precision values
87
97
-`rand`: The remaining 54 bits are filled with [cryptographically strong random data][python randbits]
88
98
89
-
20 extra bits dedicated to sub-second precision provide nanosecond resolution. The `unix_ts`and `subsec` fields guarantee the order of UUIDs generated within the same nanosecond by monotonically incrementing the timer.
99
+
20 extra bits dedicated to sub-second precision provide nanosecond resolution. The `unix_ts_ms`, `subsec_a`, and `subsec_b` fields guarantee the order of UUIDs generated within the same nanosecond by monotonically incrementing the timer.
90
100
91
101
## Performance
92
102
@@ -96,34 +106,19 @@ Run the shell script [bench.sh][bench] to test on your own machine.
0 commit comments