uuid_utils 0.14.0__cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uuid_utils/__init__.py +58 -0
- uuid_utils/__init__.pyi +218 -0
- uuid_utils/_uuid_utils.abi3.so +0 -0
- uuid_utils/compat/__init__.py +83 -0
- uuid_utils/compat/__init__.pyi +79 -0
- uuid_utils/py.typed +0 -0
- uuid_utils-0.14.0.dist-info/METADATA +129 -0
- uuid_utils-0.14.0.dist-info/RECORD +10 -0
- uuid_utils-0.14.0.dist-info/WHEEL +5 -0
- uuid_utils-0.14.0.dist-info/licenses/LICENSE.md +27 -0
uuid_utils/__init__.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from uuid import SafeUUID
|
|
3
|
+
|
|
4
|
+
from ._uuid_utils import (
|
|
5
|
+
MAX,
|
|
6
|
+
NAMESPACE_DNS,
|
|
7
|
+
NAMESPACE_OID,
|
|
8
|
+
NAMESPACE_URL,
|
|
9
|
+
NAMESPACE_X500,
|
|
10
|
+
NIL,
|
|
11
|
+
RESERVED_FUTURE,
|
|
12
|
+
RESERVED_MICROSOFT,
|
|
13
|
+
RESERVED_NCS,
|
|
14
|
+
RFC_4122,
|
|
15
|
+
UUID,
|
|
16
|
+
__version__,
|
|
17
|
+
getnode,
|
|
18
|
+
uuid1,
|
|
19
|
+
uuid3,
|
|
20
|
+
uuid4,
|
|
21
|
+
uuid5,
|
|
22
|
+
uuid6,
|
|
23
|
+
uuid7,
|
|
24
|
+
uuid8,
|
|
25
|
+
)
|
|
26
|
+
from ._uuid_utils import (
|
|
27
|
+
reseed as reseed_rng,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# Reseed the RNG in the child process after a fork.
|
|
31
|
+
# Otherwise both parent and child processes may generate the same UUIDs for some time.
|
|
32
|
+
if hasattr(os, "fork"):
|
|
33
|
+
os.register_at_fork(after_in_child=reseed_rng)
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"MAX",
|
|
37
|
+
"NAMESPACE_DNS",
|
|
38
|
+
"NAMESPACE_OID",
|
|
39
|
+
"NAMESPACE_URL",
|
|
40
|
+
"NAMESPACE_X500",
|
|
41
|
+
"NIL",
|
|
42
|
+
"RESERVED_FUTURE",
|
|
43
|
+
"RESERVED_MICROSOFT",
|
|
44
|
+
"RESERVED_NCS",
|
|
45
|
+
"RFC_4122",
|
|
46
|
+
"UUID",
|
|
47
|
+
"SafeUUID",
|
|
48
|
+
"__version__",
|
|
49
|
+
"getnode",
|
|
50
|
+
"reseed_rng",
|
|
51
|
+
"uuid1",
|
|
52
|
+
"uuid3",
|
|
53
|
+
"uuid4",
|
|
54
|
+
"uuid5",
|
|
55
|
+
"uuid6",
|
|
56
|
+
"uuid7",
|
|
57
|
+
"uuid8",
|
|
58
|
+
]
|
uuid_utils/__init__.pyi
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import builtins
|
|
2
|
+
import sys
|
|
3
|
+
from typing import Final
|
|
4
|
+
from uuid import SafeUUID
|
|
5
|
+
|
|
6
|
+
from typing_extensions import LiteralString, TypeAlias
|
|
7
|
+
|
|
8
|
+
# Because UUID has properties called int and bytes we need to rename these temporarily.
|
|
9
|
+
_FieldsType: TypeAlias = tuple[int, int, int, int, int, int]
|
|
10
|
+
|
|
11
|
+
__version__: str
|
|
12
|
+
|
|
13
|
+
class UUID:
|
|
14
|
+
"""Instances of the UUID class represent UUIDs as specified in RFC 4122.
|
|
15
|
+
UUID objects are immutable, hashable, and usable as dictionary keys.
|
|
16
|
+
Converting a UUID to a string with str() yields something in the form
|
|
17
|
+
'12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
|
|
18
|
+
five possible forms: a similar string of hexadecimal digits, or a tuple
|
|
19
|
+
of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and
|
|
20
|
+
48-bit values respectively) as an argument named 'fields', or a string
|
|
21
|
+
of 16 bytes (with all the integer fields in big-endian order) as an
|
|
22
|
+
argument named 'bytes', or a string of 16 bytes (with the first three
|
|
23
|
+
fields in little-endian order) as an argument named 'bytes_le', or a
|
|
24
|
+
single 128-bit integer as an argument named 'int'.
|
|
25
|
+
|
|
26
|
+
UUIDs have these read-only attributes:
|
|
27
|
+
|
|
28
|
+
bytes the UUID as a 16-byte string (containing the six
|
|
29
|
+
integer fields in big-endian byte order)
|
|
30
|
+
|
|
31
|
+
bytes_le the UUID as a 16-byte string (with time_low, time_mid,
|
|
32
|
+
and time_hi_version in little-endian byte order)
|
|
33
|
+
|
|
34
|
+
fields a tuple of the six integer fields of the UUID,
|
|
35
|
+
which are also available as six individual attributes
|
|
36
|
+
and two derived attributes:
|
|
37
|
+
|
|
38
|
+
time_low the first 32 bits of the UUID
|
|
39
|
+
time_mid the next 16 bits of the UUID
|
|
40
|
+
time_hi_version the next 16 bits of the UUID
|
|
41
|
+
clock_seq_hi_variant the next 8 bits of the UUID
|
|
42
|
+
clock_seq_low the next 8 bits of the UUID
|
|
43
|
+
node the last 48 bits of the UUID
|
|
44
|
+
|
|
45
|
+
time the 60-bit timestamp
|
|
46
|
+
clock_seq the 14-bit sequence number
|
|
47
|
+
|
|
48
|
+
hex the UUID as a 32-character hexadecimal string
|
|
49
|
+
|
|
50
|
+
int the UUID as a 128-bit integer
|
|
51
|
+
|
|
52
|
+
urn the UUID as a URN as specified in RFC 4122
|
|
53
|
+
|
|
54
|
+
variant the UUID variant (one of the constants RESERVED_NCS,
|
|
55
|
+
RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE)
|
|
56
|
+
|
|
57
|
+
version the UUID version number
|
|
58
|
+
|
|
59
|
+
is_safe An enum indicating whether the UUID has been generated in
|
|
60
|
+
a way that is safe for multiprocessing applications, via
|
|
61
|
+
uuid_generate_time_safe(3).
|
|
62
|
+
|
|
63
|
+
timestamp The timestamp of the UUID in milliseconds since epoch.
|
|
64
|
+
Only works for UUID versions 1, 6 and 7,
|
|
65
|
+
otherwise raises ValueError.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
is_safe: Final[SafeUUID]
|
|
69
|
+
int: Final[builtins.int]
|
|
70
|
+
|
|
71
|
+
def __init__(
|
|
72
|
+
self,
|
|
73
|
+
hex: str | None = None,
|
|
74
|
+
bytes: builtins.bytes | None = None,
|
|
75
|
+
bytes_le: builtins.bytes | None = None,
|
|
76
|
+
fields: _FieldsType | None = None,
|
|
77
|
+
int: builtins.int | None = None,
|
|
78
|
+
version: builtins.int | None = None,
|
|
79
|
+
*,
|
|
80
|
+
is_safe: SafeUUID = ...,
|
|
81
|
+
) -> None: ...
|
|
82
|
+
@property
|
|
83
|
+
def bytes(self) -> builtins.bytes: ...
|
|
84
|
+
@property
|
|
85
|
+
def bytes_le(self) -> builtins.bytes: ...
|
|
86
|
+
@property
|
|
87
|
+
def clock_seq(self) -> builtins.int: ...
|
|
88
|
+
@property
|
|
89
|
+
def clock_seq_hi_variant(self) -> builtins.int: ...
|
|
90
|
+
@property
|
|
91
|
+
def clock_seq_low(self) -> builtins.int: ...
|
|
92
|
+
@property
|
|
93
|
+
def fields(self) -> _FieldsType: ...
|
|
94
|
+
@property
|
|
95
|
+
def hex(self) -> str: ...
|
|
96
|
+
@property
|
|
97
|
+
def node(self) -> builtins.int: ...
|
|
98
|
+
@property
|
|
99
|
+
def time(self) -> builtins.int: ...
|
|
100
|
+
@property
|
|
101
|
+
def time_hi_version(self) -> builtins.int: ...
|
|
102
|
+
@property
|
|
103
|
+
def time_low(self) -> builtins.int: ...
|
|
104
|
+
@property
|
|
105
|
+
def time_mid(self) -> builtins.int: ...
|
|
106
|
+
@property
|
|
107
|
+
def timestamp(self) -> builtins.int:
|
|
108
|
+
"""Get UUID timestamp milliseconds since epoch.
|
|
109
|
+
Only works for UUID versions 1, 6 and 7, otherwise raises ValueError."""
|
|
110
|
+
...
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def urn(self) -> str: ...
|
|
114
|
+
@property
|
|
115
|
+
def variant(self) -> str: ...
|
|
116
|
+
@property
|
|
117
|
+
def version(self) -> builtins.int | None: ...
|
|
118
|
+
def __int__(self) -> builtins.int: ...
|
|
119
|
+
def __hash__(self) -> builtins.int: ...
|
|
120
|
+
def __eq__(self, other: object) -> bool: ...
|
|
121
|
+
def __lt__(self, other: UUID) -> bool: ...
|
|
122
|
+
def __le__(self, other: UUID) -> bool: ...
|
|
123
|
+
def __gt__(self, other: UUID) -> bool: ...
|
|
124
|
+
def __ge__(self, other: UUID) -> bool: ...
|
|
125
|
+
|
|
126
|
+
def getnode() -> int: ...
|
|
127
|
+
def reseed_rng() -> None:
|
|
128
|
+
"""
|
|
129
|
+
Reseeds the underlying rng.
|
|
130
|
+
This is useful in cases where you fork, as without reseeding the
|
|
131
|
+
generated uuids may be identical. This can be called manually in the child process,
|
|
132
|
+
or automatically run after fork with:
|
|
133
|
+
|
|
134
|
+
os.register_at_fork(after_in_child=uuid_utils.reseed_rng)
|
|
135
|
+
"""
|
|
136
|
+
...
|
|
137
|
+
|
|
138
|
+
def uuid1(node: int | None = None, clock_seq: int | None = None) -> UUID:
|
|
139
|
+
"""Generate a UUID from a host ID, sequence number, and the current time.
|
|
140
|
+
If 'node' is not given, getnode() is used to obtain the hardware
|
|
141
|
+
address. If 'clock_seq' is given, it is used as the sequence number;
|
|
142
|
+
otherwise a random 14-bit sequence number is chosen."""
|
|
143
|
+
...
|
|
144
|
+
|
|
145
|
+
if sys.version_info >= (3, 12):
|
|
146
|
+
def uuid3(namespace: UUID, name: str | bytes) -> UUID:
|
|
147
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
148
|
+
...
|
|
149
|
+
else:
|
|
150
|
+
def uuid3(namespace: UUID, name: str) -> UUID:
|
|
151
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
152
|
+
...
|
|
153
|
+
|
|
154
|
+
def uuid4() -> UUID:
|
|
155
|
+
"""Generate a random UUID."""
|
|
156
|
+
...
|
|
157
|
+
|
|
158
|
+
if sys.version_info >= (3, 12):
|
|
159
|
+
def uuid5(namespace: UUID, name: str | bytes) -> UUID:
|
|
160
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
161
|
+
...
|
|
162
|
+
else:
|
|
163
|
+
def uuid5(namespace: UUID, name: str) -> UUID:
|
|
164
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
165
|
+
...
|
|
166
|
+
|
|
167
|
+
def uuid6(
|
|
168
|
+
node: int | None = None, timestamp: int | None = None, nanos: int | None = None
|
|
169
|
+
) -> UUID:
|
|
170
|
+
"""Generate a version 6 UUID using the given timestamp and a host ID.
|
|
171
|
+
This is similar to version 1 UUIDs,
|
|
172
|
+
except that it is lexicographically sortable by timestamp.
|
|
173
|
+
"""
|
|
174
|
+
...
|
|
175
|
+
|
|
176
|
+
def uuid7(timestamp: int | None = None, nanos: int | None = None) -> UUID:
|
|
177
|
+
"""Generate a version 7 UUID using a time value and random bytes."""
|
|
178
|
+
...
|
|
179
|
+
|
|
180
|
+
def uuid8(bytes: bytes) -> UUID:
|
|
181
|
+
"""Generate a custom UUID comprised almost entirely of user-supplied bytes."""
|
|
182
|
+
...
|
|
183
|
+
|
|
184
|
+
NAMESPACE_DNS: Final[UUID]
|
|
185
|
+
NAMESPACE_URL: Final[UUID]
|
|
186
|
+
NAMESPACE_OID: Final[UUID]
|
|
187
|
+
NAMESPACE_X500: Final[UUID]
|
|
188
|
+
RESERVED_NCS: Final[LiteralString]
|
|
189
|
+
RFC_4122: Final[LiteralString]
|
|
190
|
+
RESERVED_MICROSOFT: Final[LiteralString]
|
|
191
|
+
RESERVED_FUTURE: Final[LiteralString]
|
|
192
|
+
NIL: Final[UUID]
|
|
193
|
+
MAX: Final[UUID]
|
|
194
|
+
|
|
195
|
+
__all__ = [
|
|
196
|
+
"MAX",
|
|
197
|
+
"NAMESPACE_DNS",
|
|
198
|
+
"NAMESPACE_OID",
|
|
199
|
+
"NAMESPACE_URL",
|
|
200
|
+
"NAMESPACE_X500",
|
|
201
|
+
"NIL",
|
|
202
|
+
"RESERVED_FUTURE",
|
|
203
|
+
"RESERVED_MICROSOFT",
|
|
204
|
+
"RESERVED_NCS",
|
|
205
|
+
"RFC_4122",
|
|
206
|
+
"UUID",
|
|
207
|
+
"SafeUUID",
|
|
208
|
+
"__version__",
|
|
209
|
+
"getnode",
|
|
210
|
+
"reseed_rng",
|
|
211
|
+
"uuid1",
|
|
212
|
+
"uuid3",
|
|
213
|
+
"uuid4",
|
|
214
|
+
"uuid5",
|
|
215
|
+
"uuid6",
|
|
216
|
+
"uuid7",
|
|
217
|
+
"uuid8",
|
|
218
|
+
]
|
|
Binary file
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from uuid import (
|
|
2
|
+
NAMESPACE_DNS,
|
|
3
|
+
NAMESPACE_OID,
|
|
4
|
+
NAMESPACE_URL,
|
|
5
|
+
NAMESPACE_X500,
|
|
6
|
+
RESERVED_FUTURE,
|
|
7
|
+
RESERVED_MICROSOFT,
|
|
8
|
+
RESERVED_NCS,
|
|
9
|
+
RFC_4122,
|
|
10
|
+
UUID,
|
|
11
|
+
getnode,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
import uuid_utils
|
|
15
|
+
|
|
16
|
+
NIL = UUID("00000000-0000-0000-0000-000000000000")
|
|
17
|
+
MAX = UUID("ffffffff-ffff-ffff-ffff-ffffffffffff")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def uuid1(node=None, clock_seq=None):
|
|
21
|
+
"""Generate a UUID from a host ID, sequence number, and the current time.
|
|
22
|
+
If 'node' is not given, getnode() is used to obtain the hardware
|
|
23
|
+
address. If 'clock_seq' is given, it is used as the sequence number;
|
|
24
|
+
otherwise a random 14-bit sequence number is chosen."""
|
|
25
|
+
return UUID(int=uuid_utils.uuid1(node, clock_seq).int)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def uuid3(namespace, name):
|
|
29
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
30
|
+
namespace = uuid_utils.UUID(namespace.hex) if namespace else namespace
|
|
31
|
+
return UUID(int=uuid_utils.uuid3(namespace, name).int)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def uuid4():
|
|
35
|
+
"""Generate a random UUID."""
|
|
36
|
+
return UUID(int=uuid_utils.uuid4().int)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def uuid5(namespace, name):
|
|
40
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
41
|
+
namespace = uuid_utils.UUID(namespace.hex) if namespace else namespace
|
|
42
|
+
return UUID(int=uuid_utils.uuid5(namespace, name).int)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def uuid6(node=None, timestamp=None):
|
|
46
|
+
"""Generate a version 6 UUID using the given timestamp and a host ID.
|
|
47
|
+
This is similar to version 1 UUIDs,
|
|
48
|
+
except that it is lexicographically sortable by timestamp.
|
|
49
|
+
"""
|
|
50
|
+
return UUID(int=uuid_utils.uuid6(node, timestamp).int)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def uuid7(timestamp=None, nanos=None):
|
|
54
|
+
"""Generate a version 7 UUID using a time value and random bytes."""
|
|
55
|
+
return UUID(int=uuid_utils.uuid7(timestamp, nanos).int)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def uuid8(bytes):
|
|
59
|
+
"""Generate a custom UUID comprised almost entirely of user-supplied bytes.."""
|
|
60
|
+
return UUID(bytes=uuid_utils.uuid8(bytes).bytes)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
__all__ = [
|
|
64
|
+
"MAX",
|
|
65
|
+
"NAMESPACE_DNS",
|
|
66
|
+
"NAMESPACE_OID",
|
|
67
|
+
"NAMESPACE_URL",
|
|
68
|
+
"NAMESPACE_X500",
|
|
69
|
+
"NIL",
|
|
70
|
+
"RESERVED_FUTURE",
|
|
71
|
+
"RESERVED_MICROSOFT",
|
|
72
|
+
"RESERVED_NCS",
|
|
73
|
+
"RFC_4122",
|
|
74
|
+
"UUID",
|
|
75
|
+
"getnode",
|
|
76
|
+
"uuid1",
|
|
77
|
+
"uuid3",
|
|
78
|
+
"uuid4",
|
|
79
|
+
"uuid5",
|
|
80
|
+
"uuid6",
|
|
81
|
+
"uuid7",
|
|
82
|
+
"uuid8",
|
|
83
|
+
]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from typing import Final
|
|
3
|
+
from uuid import (
|
|
4
|
+
NAMESPACE_DNS,
|
|
5
|
+
NAMESPACE_OID,
|
|
6
|
+
NAMESPACE_URL,
|
|
7
|
+
NAMESPACE_X500,
|
|
8
|
+
RESERVED_FUTURE,
|
|
9
|
+
RESERVED_MICROSOFT,
|
|
10
|
+
RESERVED_NCS,
|
|
11
|
+
RFC_4122,
|
|
12
|
+
UUID,
|
|
13
|
+
SafeUUID,
|
|
14
|
+
getnode,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
def uuid1(node: int | None = None, clock_seq: int | None = None) -> UUID:
|
|
18
|
+
"""Generate a UUID from a host ID, sequence number, and the current time.
|
|
19
|
+
If 'node' is not given, getnode() is used to obtain the hardware
|
|
20
|
+
address. If 'clock_seq' is given, it is used as the sequence number;
|
|
21
|
+
otherwise a random 14-bit sequence number is chosen."""
|
|
22
|
+
...
|
|
23
|
+
|
|
24
|
+
if sys.version_info >= (3, 12):
|
|
25
|
+
def uuid3(namespace: UUID, name: str | bytes) -> UUID:
|
|
26
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
27
|
+
...
|
|
28
|
+
|
|
29
|
+
else:
|
|
30
|
+
def uuid3(namespace: UUID, name: str) -> UUID:
|
|
31
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
32
|
+
...
|
|
33
|
+
|
|
34
|
+
def uuid4() -> UUID:
|
|
35
|
+
"""Generate a random UUID."""
|
|
36
|
+
...
|
|
37
|
+
|
|
38
|
+
if sys.version_info >= (3, 12):
|
|
39
|
+
def uuid5(namespace: UUID, name: str | bytes) -> UUID:
|
|
40
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
41
|
+
...
|
|
42
|
+
else:
|
|
43
|
+
def uuid5(namespace: UUID, name: str) -> UUID:
|
|
44
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
45
|
+
...
|
|
46
|
+
|
|
47
|
+
def uuid6(node: int | None = None, timestamp: int | None = None) -> UUID:
|
|
48
|
+
"""Generate a version 6 UUID using the given timestamp and a host ID.
|
|
49
|
+
This is similar to version 1 UUIDs,
|
|
50
|
+
except that it is lexicographically sortable by timestamp.
|
|
51
|
+
"""
|
|
52
|
+
...
|
|
53
|
+
|
|
54
|
+
def uuid7(timestamp: int | None = None, nanos: int | None = None) -> UUID:
|
|
55
|
+
"""Generate a version 7 UUID using a time value and random bytes."""
|
|
56
|
+
...
|
|
57
|
+
|
|
58
|
+
def uuid8(bytes: bytes) -> UUID:
|
|
59
|
+
"""Generate a custom UUID comprised almost entirely of user-supplied bytes.."""
|
|
60
|
+
...
|
|
61
|
+
|
|
62
|
+
NIL: Final[UUID]
|
|
63
|
+
MAX: Final[UUID]
|
|
64
|
+
|
|
65
|
+
__all__ = [
|
|
66
|
+
"MAX",
|
|
67
|
+
"NAMESPACE_DNS",
|
|
68
|
+
"NAMESPACE_OID",
|
|
69
|
+
"NAMESPACE_URL",
|
|
70
|
+
"NAMESPACE_X500",
|
|
71
|
+
"NIL",
|
|
72
|
+
"RESERVED_FUTURE",
|
|
73
|
+
"RESERVED_MICROSOFT",
|
|
74
|
+
"RESERVED_NCS",
|
|
75
|
+
"RFC_4122",
|
|
76
|
+
"UUID",
|
|
77
|
+
"SafeUUID",
|
|
78
|
+
"getnode",
|
|
79
|
+
]
|
uuid_utils/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: uuid_utils
|
|
3
|
+
Version: 0.14.0
|
|
4
|
+
Classifier: Development Status :: 4 - Beta
|
|
5
|
+
Classifier: Programming Language :: Python
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Rust
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
License-File: LICENSE.md
|
|
19
|
+
Summary: Fast, drop-in replacement for Python's uuid module, powered by Rust.
|
|
20
|
+
Keywords: rust,uuid
|
|
21
|
+
Author-email: Amin Alaee <mohammadamin.alaee@gmail.com>
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
24
|
+
Project-URL: Documentation, https://github.com/aminalaee/uuid-utils
|
|
25
|
+
Project-URL: Issues, https://github.com/aminalaee/uuid-utils/issues
|
|
26
|
+
Project-URL: Source, https://github.com/aminalaee/uuid-utils
|
|
27
|
+
|
|
28
|
+
# Python UUID Utils
|
|
29
|
+
|
|
30
|
+
<div align="center">
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/uuid-utils/)
|
|
33
|
+
[](https://pypi.org/project/uuid-utils)
|
|
34
|
+
[](https://codspeed.io/aminalaee/uuid-utils?utm_source=badge)
|
|
35
|
+
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
Fast, drop-in replacement for Python's uuid module, powered by Rust.
|
|
41
|
+
|
|
42
|
+
Avaialble UUID versions:
|
|
43
|
+
|
|
44
|
+
- `uuid1` - Version 1 UUIDs using a timestamp and monotonic counter.
|
|
45
|
+
- `uuid3` - Version 3 UUIDs based on the MD5 hash of some data.
|
|
46
|
+
- `uuid4` - Version 4 UUIDs with random data.
|
|
47
|
+
- `uuid5` - Version 5 UUIDs based on the SHA1 hash of some data.
|
|
48
|
+
- `uuid6` - Version 6 UUIDs using a timestamp and monotonic counter.
|
|
49
|
+
- `uuid7` - Version 7 UUIDs using a Unix timestamp ordered by time.
|
|
50
|
+
- `uuid8` - Version 8 UUIDs using user-defined data.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
Using `pip`:
|
|
54
|
+
```shell
|
|
55
|
+
$ pip install uuid-utils
|
|
56
|
+
```
|
|
57
|
+
or, using `conda`:
|
|
58
|
+
|
|
59
|
+
```shell
|
|
60
|
+
$ conda install -c conda-forge uuid-utils
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Example
|
|
64
|
+
|
|
65
|
+
```shell
|
|
66
|
+
>>> import uuid_utils as uuid
|
|
67
|
+
|
|
68
|
+
>>> # make a random UUID
|
|
69
|
+
>>> uuid.uuid4()
|
|
70
|
+
UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec')
|
|
71
|
+
|
|
72
|
+
>>> # make a random UUID using a Unix timestamp which is time-ordered.
|
|
73
|
+
>>> uuid.uuid7()
|
|
74
|
+
UUID('018afa4a-0d21-7e6c-b857-012bc678552b')
|
|
75
|
+
|
|
76
|
+
>>> # make a UUID using a SHA-1 hash of a namespace UUID and a name
|
|
77
|
+
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
|
|
78
|
+
UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')
|
|
79
|
+
|
|
80
|
+
>>> # make a UUID using an MD5 hash of a namespace UUID and a name
|
|
81
|
+
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
|
|
82
|
+
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Compatibility with Python UUID
|
|
86
|
+
|
|
87
|
+
In some cases, for example if you are using `Django`, you might need `UUID` instances to be returned
|
|
88
|
+
from the standrad-library `uuid`, not a custom `UUID` class.
|
|
89
|
+
In that case you can use the `uuid_utils.compat` which comes with a performance penalty
|
|
90
|
+
in comparison with the `uuid_utils` default behaviour, but is still faster than the standard-library.
|
|
91
|
+
|
|
92
|
+
```py
|
|
93
|
+
>>> import uuid_utils.compat as uuid
|
|
94
|
+
|
|
95
|
+
>>> # make a random UUID
|
|
96
|
+
>>> uuid.uuid4()
|
|
97
|
+
UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec')
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Benchmarks
|
|
101
|
+
|
|
102
|
+
| Benchmark | Min | Max | Mean | Min (+) | Max (+) | Mean (+) |
|
|
103
|
+
| ---------------- | ----- | ----- | ----- | ------------- | ------------- | ------------- |
|
|
104
|
+
| UUID v1 | 0.061 | 0.299 | 0.194 | 0.019 (3.3x) | 0.019 (15.4x) | 0.019 (10.1x) |
|
|
105
|
+
| UUID v3 | 0.267 | 0.307 | 0.293 | 0.035 (7.6x) | 0.041 (7.5x) | 0.039 (7.5x) |
|
|
106
|
+
| UUID v4 | 0.073 | 0.119 | 0.083 | 0.005 (15.2x) | 0.005 (24.6x) | 0.005 (17.1x) |
|
|
107
|
+
| UUID v5 | 0.058 | 0.189 | 0.146 | 0.008 (7.6x) | 0.038 (5.0x) | 0.016 (9.0x) |
|
|
108
|
+
| UUID v6 | 0.032 | 0.033 | 0.032 | 0.003 (10.1x) | 0.003 (10.3x) | 0.003 (10.1x) |
|
|
109
|
+
| UUID v7 | 0.063 | 0.063 | 0.063 | 0.004 (16.1x) | 0.004 (16.0x) | 0.004 (16.1x) |
|
|
110
|
+
| UUID from hex | 0.128 | 0.139 | 0.135 | 0.016 (8.2x) | 0.017 (8.0x) | 0.016 (8.3x) |
|
|
111
|
+
| UUID from bytes | 0.031 | 0.135 | 0.093 | 0.016 (2.0x) | 0.016 (8.6x) | 0.016 (5.9x) |
|
|
112
|
+
| UUID from int | 0.027 | 0.102 | 0.043 | 0.003 (8.3x) | 0.004 (25.0x) | 0.003 (12.4x) |
|
|
113
|
+
| UUID from fields | 0.031 | 0.162 | 0.077 | 0.005 (6.0x) | 0.005 (30.6x) | 0.005 (14.7x) |
|
|
114
|
+
|
|
115
|
+
<sup>Benchmark results might vary in different environments, but in most cases the uuid_utils should outperform stdlib uuid.</sup><br>
|
|
116
|
+
|
|
117
|
+
## How to develop locally
|
|
118
|
+
|
|
119
|
+
```shell
|
|
120
|
+
$ make build
|
|
121
|
+
$ make test
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Or:
|
|
125
|
+
|
|
126
|
+
```shell
|
|
127
|
+
$ RUSTFLAGS="--cfg uuid_unstable" maturin develop --release
|
|
128
|
+
```
|
|
129
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
uuid_utils/__init__.py,sha256=IK1KFAgXf56uuZMbXIXiR2RM77SGpovcvQiVYk1vncE,1003
|
|
2
|
+
uuid_utils/__init__.pyi,sha256=l6Lox5NQQ5GaS9s6ED9rWAEUFXEc_q3Ih35SvTBeSKQ,7411
|
|
3
|
+
uuid_utils/_uuid_utils.abi3.so,sha256=UFUhgIylfcqIRNKhWZvpwooJT7tT7du1ybNcfONjIQQ,822240
|
|
4
|
+
uuid_utils/compat/__init__.py,sha256=ng6cZaL3Oj38xPGOVCQmthDJJhWsNfQaXV9_1Hse-g4,2216
|
|
5
|
+
uuid_utils/compat/__init__.pyi,sha256=d75Gv0r1xxiiQUNeiYpsJnyWKa8iCPZhbVFX_38ZSrw,2183
|
|
6
|
+
uuid_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
uuid_utils-0.14.0.dist-info/METADATA,sha256=lIddL_Ap-YjOuEhN2O1wGlI9r7R9Ag5mfbGrwdwPQQg,4852
|
|
8
|
+
uuid_utils-0.14.0.dist-info/WHEEL,sha256=btCZOUXJMzNcRkylrJSGktvUfAhpsQmBEeAGzSFPuxs,145
|
|
9
|
+
uuid_utils-0.14.0.dist-info/licenses/LICENSE.md,sha256=DEf1K0xIS9BMeOfJaVQu6jGv5kT1h_O4qMzOhjUsYEY,1487
|
|
10
|
+
uuid_utils-0.14.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright © 2023, Amin Alaee.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
* Neither the name of the copyright holder nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|