uuid-utils 0.11.0__cp39-abi3-win_arm64.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.
Potentially problematic release.
This version of uuid-utils might be problematic. Click here for more details.
- uuid_utils/__init__.py +44 -0
- uuid_utils/__init__.pyi +201 -0
- uuid_utils/_uuid_utils.pyd +0 -0
- uuid_utils/compat/__init__.py +77 -0
- uuid_utils/compat/__init__.pyi +79 -0
- uuid_utils/py.typed +0 -0
- uuid_utils-0.11.0.dist-info/METADATA +130 -0
- uuid_utils-0.11.0.dist-info/RECORD +10 -0
- uuid_utils-0.11.0.dist-info/WHEEL +4 -0
- uuid_utils-0.11.0.dist-info/licenses/LICENSE.md +27 -0
uuid_utils/__init__.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from uuid import SafeUUID
|
|
2
|
+
|
|
3
|
+
from ._uuid_utils 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
|
+
__version__,
|
|
14
|
+
getnode,
|
|
15
|
+
uuid1,
|
|
16
|
+
uuid3,
|
|
17
|
+
uuid4,
|
|
18
|
+
uuid5,
|
|
19
|
+
uuid6,
|
|
20
|
+
uuid7,
|
|
21
|
+
uuid8,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"NAMESPACE_DNS",
|
|
26
|
+
"NAMESPACE_OID",
|
|
27
|
+
"NAMESPACE_URL",
|
|
28
|
+
"NAMESPACE_X500",
|
|
29
|
+
"RESERVED_FUTURE",
|
|
30
|
+
"RESERVED_MICROSOFT",
|
|
31
|
+
"RESERVED_NCS",
|
|
32
|
+
"RFC_4122",
|
|
33
|
+
"UUID",
|
|
34
|
+
"SafeUUID",
|
|
35
|
+
"__version__",
|
|
36
|
+
"getnode",
|
|
37
|
+
"uuid1",
|
|
38
|
+
"uuid3",
|
|
39
|
+
"uuid4",
|
|
40
|
+
"uuid5",
|
|
41
|
+
"uuid6",
|
|
42
|
+
"uuid7",
|
|
43
|
+
"uuid8",
|
|
44
|
+
]
|
uuid_utils/__init__.pyi
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import builtins
|
|
2
|
+
import sys
|
|
3
|
+
from uuid import SafeUUID
|
|
4
|
+
|
|
5
|
+
from typing_extensions import TypeAlias
|
|
6
|
+
|
|
7
|
+
# Because UUID has properties called int and bytes we need to rename these temporarily.
|
|
8
|
+
_FieldsType: TypeAlias = tuple[int, int, int, int, int, int]
|
|
9
|
+
|
|
10
|
+
__version__: str
|
|
11
|
+
|
|
12
|
+
class UUID:
|
|
13
|
+
"""Instances of the UUID class represent UUIDs as specified in RFC 4122.
|
|
14
|
+
UUID objects are immutable, hashable, and usable as dictionary keys.
|
|
15
|
+
Converting a UUID to a string with str() yields something in the form
|
|
16
|
+
'12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
|
|
17
|
+
five possible forms: a similar string of hexadecimal digits, or a tuple
|
|
18
|
+
of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and
|
|
19
|
+
48-bit values respectively) as an argument named 'fields', or a string
|
|
20
|
+
of 16 bytes (with all the integer fields in big-endian order) as an
|
|
21
|
+
argument named 'bytes', or a string of 16 bytes (with the first three
|
|
22
|
+
fields in little-endian order) as an argument named 'bytes_le', or a
|
|
23
|
+
single 128-bit integer as an argument named 'int'.
|
|
24
|
+
|
|
25
|
+
UUIDs have these read-only attributes:
|
|
26
|
+
|
|
27
|
+
bytes the UUID as a 16-byte string (containing the six
|
|
28
|
+
integer fields in big-endian byte order)
|
|
29
|
+
|
|
30
|
+
bytes_le the UUID as a 16-byte string (with time_low, time_mid,
|
|
31
|
+
and time_hi_version in little-endian byte order)
|
|
32
|
+
|
|
33
|
+
fields a tuple of the six integer fields of the UUID,
|
|
34
|
+
which are also available as six individual attributes
|
|
35
|
+
and two derived attributes:
|
|
36
|
+
|
|
37
|
+
time_low the first 32 bits of the UUID
|
|
38
|
+
time_mid the next 16 bits of the UUID
|
|
39
|
+
time_hi_version the next 16 bits of the UUID
|
|
40
|
+
clock_seq_hi_variant the next 8 bits of the UUID
|
|
41
|
+
clock_seq_low the next 8 bits of the UUID
|
|
42
|
+
node the last 48 bits of the UUID
|
|
43
|
+
|
|
44
|
+
time the 60-bit timestamp
|
|
45
|
+
clock_seq the 14-bit sequence number
|
|
46
|
+
|
|
47
|
+
hex the UUID as a 32-character hexadecimal string
|
|
48
|
+
|
|
49
|
+
int the UUID as a 128-bit integer
|
|
50
|
+
|
|
51
|
+
urn the UUID as a URN as specified in RFC 4122
|
|
52
|
+
|
|
53
|
+
variant the UUID variant (one of the constants RESERVED_NCS,
|
|
54
|
+
RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE)
|
|
55
|
+
|
|
56
|
+
version the UUID version number
|
|
57
|
+
|
|
58
|
+
is_safe An enum indicating whether the UUID has been generated in
|
|
59
|
+
a way that is safe for multiprocessing applications, via
|
|
60
|
+
uuid_generate_time_safe(3).
|
|
61
|
+
|
|
62
|
+
timestamp The timestamp of the UUID in milliseconds since epoch.
|
|
63
|
+
Only works for UUID versions 1, 6 and 7,
|
|
64
|
+
otherwise raises ValueError.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(
|
|
68
|
+
self,
|
|
69
|
+
hex: str | None = None,
|
|
70
|
+
bytes: builtins.bytes | None = None,
|
|
71
|
+
bytes_le: builtins.bytes | None = None,
|
|
72
|
+
fields: _FieldsType | None = None,
|
|
73
|
+
int: builtins.int | None = None,
|
|
74
|
+
version: builtins.int | None = None,
|
|
75
|
+
*,
|
|
76
|
+
is_safe: SafeUUID = ...,
|
|
77
|
+
) -> None: ...
|
|
78
|
+
@property
|
|
79
|
+
def is_safe(self) -> SafeUUID: ...
|
|
80
|
+
@property
|
|
81
|
+
def bytes(self) -> builtins.bytes: ...
|
|
82
|
+
@property
|
|
83
|
+
def bytes_le(self) -> builtins.bytes: ...
|
|
84
|
+
@property
|
|
85
|
+
def clock_seq(self) -> builtins.int: ...
|
|
86
|
+
@property
|
|
87
|
+
def clock_seq_hi_variant(self) -> builtins.int: ...
|
|
88
|
+
@property
|
|
89
|
+
def clock_seq_low(self) -> builtins.int: ...
|
|
90
|
+
@property
|
|
91
|
+
def fields(self) -> _FieldsType: ...
|
|
92
|
+
@property
|
|
93
|
+
def hex(self) -> str: ...
|
|
94
|
+
@property
|
|
95
|
+
def int(self) -> builtins.int: ...
|
|
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 __eq__(self, other: object) -> bool: ...
|
|
120
|
+
def __lt__(self, other: UUID) -> bool: ...
|
|
121
|
+
def __le__(self, other: UUID) -> bool: ...
|
|
122
|
+
def __gt__(self, other: UUID) -> bool: ...
|
|
123
|
+
def __ge__(self, other: UUID) -> bool: ...
|
|
124
|
+
|
|
125
|
+
def getnode() -> int: ...
|
|
126
|
+
def uuid1(node: int | None = None, clock_seq: int | None = None) -> UUID:
|
|
127
|
+
"""Generate a UUID from a host ID, sequence number, and the current time.
|
|
128
|
+
If 'node' is not given, getnode() is used to obtain the hardware
|
|
129
|
+
address. If 'clock_seq' is given, it is used as the sequence number;
|
|
130
|
+
otherwise a random 14-bit sequence number is chosen."""
|
|
131
|
+
...
|
|
132
|
+
|
|
133
|
+
if sys.version_info >= (3, 12):
|
|
134
|
+
def uuid3(namespace: UUID, name: str | bytes) -> UUID:
|
|
135
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
136
|
+
...
|
|
137
|
+
else:
|
|
138
|
+
def uuid3(namespace: UUID, name: str) -> UUID:
|
|
139
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
140
|
+
...
|
|
141
|
+
|
|
142
|
+
def uuid4() -> UUID:
|
|
143
|
+
"""Generate a random UUID."""
|
|
144
|
+
...
|
|
145
|
+
|
|
146
|
+
if sys.version_info >= (3, 12):
|
|
147
|
+
def uuid5(namespace: UUID, name: str | bytes) -> UUID:
|
|
148
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
149
|
+
...
|
|
150
|
+
else:
|
|
151
|
+
def uuid5(namespace: UUID, name: str) -> UUID:
|
|
152
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
153
|
+
...
|
|
154
|
+
|
|
155
|
+
def uuid6(
|
|
156
|
+
node: int | None = None, timestamp: int | None = None, nanos: int | None = None
|
|
157
|
+
) -> UUID:
|
|
158
|
+
"""Generate a version 6 UUID using the given timestamp and a host ID.
|
|
159
|
+
This is similar to version 1 UUIDs,
|
|
160
|
+
except that it is lexicographically sortable by timestamp.
|
|
161
|
+
"""
|
|
162
|
+
...
|
|
163
|
+
|
|
164
|
+
def uuid7(timestamp: int | None = None, nanos: int | None = None) -> UUID:
|
|
165
|
+
"""Generate a version 7 UUID using a time value and random bytes."""
|
|
166
|
+
...
|
|
167
|
+
|
|
168
|
+
def uuid8(bytes: bytes) -> UUID:
|
|
169
|
+
"""Generate a custom UUID comprised almost entirely of user-supplied bytes."""
|
|
170
|
+
...
|
|
171
|
+
|
|
172
|
+
NAMESPACE_DNS: UUID
|
|
173
|
+
NAMESPACE_URL: UUID
|
|
174
|
+
NAMESPACE_OID: UUID
|
|
175
|
+
NAMESPACE_X500: UUID
|
|
176
|
+
RESERVED_NCS: str
|
|
177
|
+
RFC_4122: str
|
|
178
|
+
RESERVED_MICROSOFT: str
|
|
179
|
+
RESERVED_FUTURE: str
|
|
180
|
+
|
|
181
|
+
__all__ = [
|
|
182
|
+
"NAMESPACE_DNS",
|
|
183
|
+
"NAMESPACE_OID",
|
|
184
|
+
"NAMESPACE_URL",
|
|
185
|
+
"NAMESPACE_X500",
|
|
186
|
+
"RESERVED_FUTURE",
|
|
187
|
+
"RESERVED_MICROSOFT",
|
|
188
|
+
"RESERVED_NCS",
|
|
189
|
+
"RFC_4122",
|
|
190
|
+
"UUID",
|
|
191
|
+
"SafeUUID",
|
|
192
|
+
"__version__",
|
|
193
|
+
"getnode",
|
|
194
|
+
"uuid1",
|
|
195
|
+
"uuid3",
|
|
196
|
+
"uuid4",
|
|
197
|
+
"uuid5",
|
|
198
|
+
"uuid6",
|
|
199
|
+
"uuid7",
|
|
200
|
+
"uuid8",
|
|
201
|
+
]
|
|
Binary file
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
__all__ = [
|
|
17
|
+
"NAMESPACE_DNS",
|
|
18
|
+
"NAMESPACE_OID",
|
|
19
|
+
"NAMESPACE_URL",
|
|
20
|
+
"NAMESPACE_X500",
|
|
21
|
+
"RESERVED_FUTURE",
|
|
22
|
+
"RESERVED_MICROSOFT",
|
|
23
|
+
"RESERVED_NCS",
|
|
24
|
+
"RFC_4122",
|
|
25
|
+
"UUID",
|
|
26
|
+
"getnode",
|
|
27
|
+
"uuid1",
|
|
28
|
+
"uuid3",
|
|
29
|
+
"uuid4",
|
|
30
|
+
"uuid5",
|
|
31
|
+
"uuid6",
|
|
32
|
+
"uuid7",
|
|
33
|
+
"uuid8",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def uuid1(node=None, clock_seq=None):
|
|
38
|
+
"""Generate a UUID from a host ID, sequence number, and the current time.
|
|
39
|
+
If 'node' is not given, getnode() is used to obtain the hardware
|
|
40
|
+
address. If 'clock_seq' is given, it is used as the sequence number;
|
|
41
|
+
otherwise a random 14-bit sequence number is chosen."""
|
|
42
|
+
return UUID(int=uuid_utils.uuid1(node, clock_seq).int)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def uuid3(namespace, name):
|
|
46
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
47
|
+
namespace = uuid_utils.UUID(namespace.hex) if namespace else namespace
|
|
48
|
+
return UUID(int=uuid_utils.uuid3(namespace, name).int)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def uuid4():
|
|
52
|
+
"""Generate a random UUID."""
|
|
53
|
+
return UUID(int=uuid_utils.uuid4().int)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def uuid5(namespace, name):
|
|
57
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
58
|
+
namespace = uuid_utils.UUID(namespace.hex) if namespace else namespace
|
|
59
|
+
return UUID(int=uuid_utils.uuid5(namespace, name).int)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def uuid6(node=None, timestamp=None):
|
|
63
|
+
"""Generate a version 6 UUID using the given timestamp and a host ID.
|
|
64
|
+
This is similar to version 1 UUIDs,
|
|
65
|
+
except that it is lexicographically sortable by timestamp.
|
|
66
|
+
"""
|
|
67
|
+
return UUID(int=uuid_utils.uuid6(node, timestamp).int)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def uuid7(timestamp=None):
|
|
71
|
+
"""Generate a version 7 UUID using a time value and random bytes."""
|
|
72
|
+
return UUID(int=uuid_utils.uuid7(timestamp).int)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def uuid8(bytes):
|
|
76
|
+
"""Generate a custom UUID comprised almost entirely of user-supplied bytes.."""
|
|
77
|
+
return UUID(bytes=uuid_utils.uuid8(bytes).bytes)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from uuid import (
|
|
3
|
+
NAMESPACE_DNS,
|
|
4
|
+
NAMESPACE_OID,
|
|
5
|
+
NAMESPACE_URL,
|
|
6
|
+
NAMESPACE_X500,
|
|
7
|
+
RESERVED_FUTURE,
|
|
8
|
+
RESERVED_MICROSOFT,
|
|
9
|
+
RESERVED_NCS,
|
|
10
|
+
RFC_4122,
|
|
11
|
+
UUID,
|
|
12
|
+
SafeUUID,
|
|
13
|
+
getnode,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
from typing_extensions import TypeAlias
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"NAMESPACE_DNS",
|
|
20
|
+
"NAMESPACE_OID",
|
|
21
|
+
"NAMESPACE_URL",
|
|
22
|
+
"NAMESPACE_X500",
|
|
23
|
+
"RESERVED_FUTURE",
|
|
24
|
+
"RESERVED_MICROSOFT",
|
|
25
|
+
"RESERVED_NCS",
|
|
26
|
+
"RFC_4122",
|
|
27
|
+
"UUID",
|
|
28
|
+
"SafeUUID",
|
|
29
|
+
"getnode",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
# Because UUID has properties called int and bytes we need to rename these temporarily.
|
|
33
|
+
_Int: TypeAlias = int
|
|
34
|
+
_Bytes: TypeAlias = bytes
|
|
35
|
+
|
|
36
|
+
def uuid1(node: _Int | None = None, clock_seq: _Int | None = None) -> UUID:
|
|
37
|
+
"""Generate a UUID from a host ID, sequence number, and the current time.
|
|
38
|
+
If 'node' is not given, getnode() is used to obtain the hardware
|
|
39
|
+
address. If 'clock_seq' is given, it is used as the sequence number;
|
|
40
|
+
otherwise a random 14-bit sequence number is chosen."""
|
|
41
|
+
...
|
|
42
|
+
|
|
43
|
+
if sys.version_info >= (3, 12):
|
|
44
|
+
def uuid3(namespace: UUID, name: str | bytes) -> UUID:
|
|
45
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
46
|
+
...
|
|
47
|
+
|
|
48
|
+
else:
|
|
49
|
+
def uuid3(namespace: UUID, name: str) -> UUID:
|
|
50
|
+
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
|
|
51
|
+
...
|
|
52
|
+
|
|
53
|
+
def uuid4() -> UUID:
|
|
54
|
+
"""Generate a random UUID."""
|
|
55
|
+
...
|
|
56
|
+
|
|
57
|
+
if sys.version_info >= (3, 12):
|
|
58
|
+
def uuid5(namespace: UUID, name: str | bytes) -> UUID:
|
|
59
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
60
|
+
...
|
|
61
|
+
else:
|
|
62
|
+
def uuid5(namespace: UUID, name: str) -> UUID:
|
|
63
|
+
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
|
|
64
|
+
...
|
|
65
|
+
|
|
66
|
+
def uuid6(node: _Int | None = None, timestamp: _Int | None = None) -> UUID:
|
|
67
|
+
"""Generate a version 6 UUID using the given timestamp and a host ID.
|
|
68
|
+
This is similar to version 1 UUIDs,
|
|
69
|
+
except that it is lexicographically sortable by timestamp.
|
|
70
|
+
"""
|
|
71
|
+
...
|
|
72
|
+
|
|
73
|
+
def uuid7(timestamp: _Int | None = None) -> UUID:
|
|
74
|
+
"""Generate a version 7 UUID using a time value and random bytes."""
|
|
75
|
+
...
|
|
76
|
+
|
|
77
|
+
def uuid8(bytes: _Bytes) -> UUID:
|
|
78
|
+
"""Generate a custom UUID comprised almost entirely of user-supplied bytes.."""
|
|
79
|
+
...
|
uuid_utils/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: uuid_utils
|
|
3
|
+
Version: 0.11.0
|
|
4
|
+
Classifier: Development Status :: 3 - Alpha
|
|
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 :: Rust
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
License-File: LICENSE.md
|
|
18
|
+
Summary: Drop-in replacement for Python UUID with bindings in Rust
|
|
19
|
+
Keywords: rust,uuid
|
|
20
|
+
Author-email: Amin Alaee <me@aminalaee.dev>
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
23
|
+
Project-URL: Documentation, https://github.com/aminalaee/uuid-utils
|
|
24
|
+
Project-URL: Issues, https://github.com/aminalaee/uuid-utils/issues
|
|
25
|
+
Project-URL: Source, https://github.com/aminalaee/uuid-utils
|
|
26
|
+
|
|
27
|
+
# Python UUID Utils
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<a href="https://pypi.org/project/uuid-utils/">
|
|
31
|
+
<img src="https://badge.fury.io/py/uuid-utils.svg" alt="Package version">
|
|
32
|
+
</a>
|
|
33
|
+
<a href="https://pypi.org/project/uuid-utils" target="_blank">
|
|
34
|
+
<img src="https://img.shields.io/pypi/pyversions/uuid-utils.svg?color=%2334D058" alt="Supported Python versions">
|
|
35
|
+
</a>
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
Python UUID implementation using Rust's UUID library.
|
|
41
|
+
This will make `uuid4` function around 10x faster.
|
|
42
|
+
|
|
43
|
+
This package can be a drop-in replacement to the standard library UUID.
|
|
44
|
+
|
|
45
|
+
Avaialble UUID versions:
|
|
46
|
+
|
|
47
|
+
- `uuid1` - Version 1 UUIDs using a timestamp and monotonic counter.
|
|
48
|
+
- `uuid3` - Version 3 UUIDs based on the MD5 hash of some data.
|
|
49
|
+
- `uuid4` - Version 4 UUIDs with random data.
|
|
50
|
+
- `uuid5` - Version 5 UUIDs based on the SHA1 hash of some data.
|
|
51
|
+
- `uuid6` - Version 6 UUIDs using a timestamp and monotonic counter.
|
|
52
|
+
- `uuid7` - Version 7 UUIDs using a Unix timestamp ordered by time.
|
|
53
|
+
- `uuid8` - Version 8 UUIDs using user-defined data.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
Using `pip`:
|
|
57
|
+
```shell
|
|
58
|
+
$ pip install uuid-utils
|
|
59
|
+
```
|
|
60
|
+
or, using `conda`:
|
|
61
|
+
|
|
62
|
+
```shell
|
|
63
|
+
$ conda install -c conda-forge uuid-utils
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Example
|
|
67
|
+
|
|
68
|
+
```shell
|
|
69
|
+
>>> import uuid_utils as uuid
|
|
70
|
+
|
|
71
|
+
>>> # make a random UUID
|
|
72
|
+
>>> uuid.uuid4()
|
|
73
|
+
UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec')
|
|
74
|
+
|
|
75
|
+
>>> # make a random UUID using a Unix timestamp which is time-ordered.
|
|
76
|
+
>>> uuid.uuid7()
|
|
77
|
+
UUID('018afa4a-0d21-7e6c-b857-012bc678552b')
|
|
78
|
+
|
|
79
|
+
>>> # make a UUID using a SHA-1 hash of a namespace UUID and a name
|
|
80
|
+
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
|
|
81
|
+
UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')
|
|
82
|
+
|
|
83
|
+
>>> # make a UUID using an MD5 hash of a namespace UUID and a name
|
|
84
|
+
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
|
|
85
|
+
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Compatibility
|
|
89
|
+
|
|
90
|
+
In some cases, for example if you are using `Django`, you might need `UUID` instances to be returned
|
|
91
|
+
from the standrad-library `uuid`, not a custom `UUID` class.
|
|
92
|
+
In that case you can use the `uuid_utils.compat` which comes with a performance penalty
|
|
93
|
+
in comparison with the `uuid_utils` default behaviour, but is still faster than the standard-library.
|
|
94
|
+
|
|
95
|
+
```py
|
|
96
|
+
>>> import uuid_utils.compat as uuid
|
|
97
|
+
|
|
98
|
+
>>> # make a random UUID
|
|
99
|
+
>>> uuid.uuid4()
|
|
100
|
+
UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec')
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Benchmarks
|
|
104
|
+
|
|
105
|
+
| Benchmark | Min | Max | Mean | Min (+) | Max (+) | Mean (+) |
|
|
106
|
+
|------------------|---------|---------|---------|-----------------|-----------------|-----------------|
|
|
107
|
+
| UUID v1 | 0.061 | 0.299 | 0.194 | 0.019 (3.3x) | 0.019 (15.4x) | 0.019 (10.1x) |
|
|
108
|
+
| UUID v3 | 0.267 | 0.307 | 0.293 | 0.035 (7.6x) | 0.041 (7.5x) | 0.039 (7.5x) |
|
|
109
|
+
| UUID v4 | 0.145 | 0.301 | 0.249 | 0.004 (38.5x) | 0.005 (54.8x) | 0.005 (53.0x) |
|
|
110
|
+
| UUID v5 | 0.058 | 0.189 | 0.146 | 0.008 (7.6x) | 0.038 (5.0x) | 0.016 (9.0x) |
|
|
111
|
+
| UUID from hex | 0.128 | 0.139 | 0.135 | 0.016 (8.2x) | 0.017 (8.0x) | 0.016 (8.3x) |
|
|
112
|
+
| UUID from bytes | 0.031 | 0.135 | 0.093 | 0.016 (2.0x) | 0.016 (8.6x) | 0.016 (5.9x) |
|
|
113
|
+
| UUID from int | 0.027 | 0.102 | 0.043 | 0.003 (8.3x) | 0.004 (25.0x) | 0.003 (12.4x) |
|
|
114
|
+
| UUID from fields | 0.031 | 0.162 | 0.077 | 0.005 (6.0x) | 0.005 (30.6x) | 0.005 (14.7x) |
|
|
115
|
+
|
|
116
|
+
<sup>Benchmark results might vary in different environments, but in most cases the uuid_utils should outperform stdlib uuid.</sup><br>
|
|
117
|
+
|
|
118
|
+
## How to develop locally
|
|
119
|
+
|
|
120
|
+
```shell
|
|
121
|
+
$ make build
|
|
122
|
+
$ make test
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Or:
|
|
126
|
+
|
|
127
|
+
```shell
|
|
128
|
+
$ RUSTFLAGS="--cfg uuid_unstable" maturin develop --release
|
|
129
|
+
```
|
|
130
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
uuid_utils-0.11.0.dist-info/METADATA,sha256=1IxzJ6cxyDjls-gFk2Ks7N1_Jw0lVif3_uqb6U5QhFo,4839
|
|
2
|
+
uuid_utils-0.11.0.dist-info/WHEEL,sha256=wnpaYzw6DTRETs-AgcmcTw1aT0IqEATWae88mnkmgyc,94
|
|
3
|
+
uuid_utils-0.11.0.dist-info/licenses/LICENSE.md,sha256=IJMw6B06iYYOnseem_iUvnBfB1Wjhp13qgkfxKL5GQM,1513
|
|
4
|
+
uuid_utils/__init__.py,sha256=d8wMPt50wY4SCUdfC2VVcAI_8fW0g2lVA-7lIjAjBgI,709
|
|
5
|
+
uuid_utils/__init__.pyi,sha256=VF0h5095ufcHgTly-6kao4qXTZmzH0Y2h1WMQSN3HMc,7060
|
|
6
|
+
uuid_utils/_uuid_utils.pyd,sha256=NmN9nWIgnsmu5JeHSBAPxwEBOq-r7tpnCZ_VShNZ8t8,376320
|
|
7
|
+
uuid_utils/compat/__init__.py,sha256=QEAcG2N9_8Rr_9REdG11ZTvUtEPK98lfkku2RRWnR3g,2148
|
|
8
|
+
uuid_utils/compat/__init__.pyi,sha256=3zv8W-A9UTdq-jK5dW2H0wkv2Uugn6DMPipy2EdOosM,2338
|
|
9
|
+
uuid_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
uuid_utils-0.11.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.
|