uuid-utils 0.7.0__pp38-pypy38_pp73-macosx_10_12_x86_64.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 ADDED
@@ -0,0 +1,41 @@
1
+ from ._uuid_utils 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
+ __version__,
12
+ getnode,
13
+ uuid1,
14
+ uuid3,
15
+ uuid4,
16
+ uuid5,
17
+ uuid6,
18
+ uuid7,
19
+ uuid8,
20
+ )
21
+
22
+ __all__ = [
23
+ "NAMESPACE_DNS",
24
+ "NAMESPACE_OID",
25
+ "NAMESPACE_URL",
26
+ "NAMESPACE_X500",
27
+ "RESERVED_FUTURE",
28
+ "RESERVED_MICROSOFT",
29
+ "RESERVED_NCS",
30
+ "RFC_4122",
31
+ "UUID",
32
+ "__version__",
33
+ "getnode",
34
+ "uuid1",
35
+ "uuid3",
36
+ "uuid4",
37
+ "uuid5",
38
+ "uuid6",
39
+ "uuid7",
40
+ "uuid8",
41
+ ]
@@ -0,0 +1,176 @@
1
+ import sys
2
+ from enum import Enum
3
+
4
+ from _typeshed import Unused
5
+ from typing_extensions import TypeAlias
6
+
7
+ # Because UUID has properties called int and bytes we need to rename these temporarily.
8
+ _Int: TypeAlias = int
9
+ _Bytes: TypeAlias = bytes
10
+ _FieldsType: TypeAlias = tuple[int, int, int, int, int, int]
11
+
12
+ __version__: str
13
+
14
+ class SafeUUID(Enum):
15
+ safe: int
16
+ unsafe: int
17
+ unknown: None
18
+
19
+ class UUID:
20
+ """Instances of the UUID class represent UUIDs as specified in RFC 4122.
21
+ UUID objects are immutable, hashable, and usable as dictionary keys.
22
+ Converting a UUID to a string with str() yields something in the form
23
+ '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
24
+ five possible forms: a similar string of hexadecimal digits, or a tuple
25
+ of six integer fields (with 32-bit, 16-bit, 16-bit, 8-bit, 8-bit, and
26
+ 48-bit values respectively) as an argument named 'fields', or a string
27
+ of 16 bytes (with all the integer fields in big-endian order) as an
28
+ argument named 'bytes', or a string of 16 bytes (with the first three
29
+ fields in little-endian order) as an argument named 'bytes_le', or a
30
+ single 128-bit integer as an argument named 'int'.
31
+
32
+ UUIDs have these read-only attributes:
33
+
34
+ bytes the UUID as a 16-byte string (containing the six
35
+ integer fields in big-endian byte order)
36
+
37
+ bytes_le the UUID as a 16-byte string (with time_low, time_mid,
38
+ and time_hi_version in little-endian byte order)
39
+
40
+ fields a tuple of the six integer fields of the UUID,
41
+ which are also available as six individual attributes
42
+ and two derived attributes:
43
+
44
+ time_low the first 32 bits of the UUID
45
+ time_mid the next 16 bits of the UUID
46
+ time_hi_version the next 16 bits of the UUID
47
+ clock_seq_hi_variant the next 8 bits of the UUID
48
+ clock_seq_low the next 8 bits of the UUID
49
+ node the last 48 bits of the UUID
50
+
51
+ time the 60-bit timestamp
52
+ clock_seq the 14-bit sequence number
53
+
54
+ hex the UUID as a 32-character hexadecimal string
55
+
56
+ int the UUID as a 128-bit integer
57
+
58
+ urn the UUID as a URN as specified in RFC 4122
59
+
60
+ variant the UUID variant (one of the constants RESERVED_NCS,
61
+ RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE)
62
+
63
+ version the UUID version number (1 through 5, meaningful only
64
+ when the variant is RFC_4122)
65
+
66
+ is_safe An enum indicating whether the UUID has been generated in
67
+ a way that is safe for multiprocessing applications, via
68
+ uuid_generate_time_safe(3).
69
+ """
70
+
71
+ def __init__(
72
+ self,
73
+ hex: str | None = None,
74
+ bytes: _Bytes | None = None,
75
+ bytes_le: _Bytes | None = None,
76
+ fields: _FieldsType | None = None,
77
+ int: _Int | None = None,
78
+ version: _Int | None = None,
79
+ *,
80
+ is_safe: SafeUUID = ...,
81
+ ) -> None: ...
82
+ @property
83
+ def is_safe(self) -> SafeUUID: ...
84
+ @property
85
+ def bytes(self) -> _Bytes: ...
86
+ @property
87
+ def bytes_le(self) -> _Bytes: ...
88
+ @property
89
+ def clock_seq(self) -> _Int: ...
90
+ @property
91
+ def clock_seq_hi_variant(self) -> _Int: ...
92
+ @property
93
+ def clock_seq_low(self) -> _Int: ...
94
+ @property
95
+ def fields(self) -> _FieldsType: ...
96
+ @property
97
+ def hex(self) -> str: ...
98
+ @property
99
+ def int(self) -> _Int: ...
100
+ @property
101
+ def node(self) -> _Int: ...
102
+ @property
103
+ def time(self) -> _Int: ...
104
+ @property
105
+ def time_hi_version(self) -> _Int: ...
106
+ @property
107
+ def time_low(self) -> _Int: ...
108
+ @property
109
+ def time_mid(self) -> _Int: ...
110
+ @property
111
+ def timestamp(self) -> _Int:
112
+ """Get UUID timestamp milliseconds since epoch.
113
+ Only works for UUID versions 1, 6 and 7, otherwise raises ValueError."""
114
+ ...
115
+
116
+ @property
117
+ def urn(self) -> str: ...
118
+ @property
119
+ def variant(self) -> str: ...
120
+ @property
121
+ def version(self) -> _Int | None: ...
122
+ def __int__(self) -> _Int: ...
123
+ def __eq__(self, other: object) -> bool: ...
124
+ def __lt__(self, other: UUID) -> bool: ...
125
+ def __le__(self, other: UUID) -> bool: ...
126
+ def __gt__(self, other: UUID) -> bool: ...
127
+ def __ge__(self, other: UUID) -> bool: ...
128
+
129
+ if sys.version_info >= (3, 9):
130
+ def getnode() -> int: ...
131
+
132
+ else:
133
+ def getnode(*, getters: Unused = None) -> int: ... # undocumented
134
+
135
+ def uuid1(node: _Int | None = None, clock_seq: _Int | None = None) -> UUID:
136
+ """Generate a UUID from a host ID, sequence number, and the current time.
137
+ If 'node' is not given, getnode() is used to obtain the hardware
138
+ address. If 'clock_seq' is given, it is used as the sequence number;
139
+ otherwise a random 14-bit sequence number is chosen."""
140
+ ...
141
+
142
+ def uuid3(namespace: UUID, name: str) -> UUID:
143
+ """Generate a UUID from the MD5 hash of a namespace UUID and a name."""
144
+ ...
145
+
146
+ def uuid4() -> UUID:
147
+ """Generate a random UUID."""
148
+ ...
149
+
150
+ def uuid5(namespace: UUID, name: str) -> UUID:
151
+ """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
152
+ ...
153
+
154
+ def uuid6(node: _Int | None = None, timestamp: _Int | None = None) -> UUID:
155
+ """Generate a version 6 UUID using the given timestamp and a host ID.
156
+ This is similar to version 1 UUIDs,
157
+ except that it is lexicographically sortable by timestamp.
158
+ """
159
+ ...
160
+
161
+ def uuid7(timestamp: _Int | None = None) -> UUID:
162
+ """Generate a version 7 UUID using a time value and random bytes."""
163
+ ...
164
+
165
+ def uuid8(bytes: _Bytes) -> UUID:
166
+ """Generate a custom UUID comprised almost entirely of user-supplied bytes.."""
167
+ ...
168
+
169
+ NAMESPACE_DNS: UUID
170
+ NAMESPACE_URL: UUID
171
+ NAMESPACE_OID: UUID
172
+ NAMESPACE_X500: UUID
173
+ RESERVED_NCS: str
174
+ RFC_4122: str
175
+ RESERVED_MICROSOFT: str
176
+ RESERVED_FUTURE: str
@@ -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,41 @@
1
+ from uuid import UUID
2
+
3
+ from typing_extensions import TypeAlias
4
+
5
+ # Because UUID has properties called int and bytes we need to rename these temporarily.
6
+ _Int: TypeAlias = int
7
+ _Bytes: TypeAlias = bytes
8
+
9
+ def uuid1(node: _Int | None = None, clock_seq: _Int | None = None) -> UUID:
10
+ """Generate a UUID from a host ID, sequence number, and the current time.
11
+ If 'node' is not given, getnode() is used to obtain the hardware
12
+ address. If 'clock_seq' is given, it is used as the sequence number;
13
+ otherwise a random 14-bit sequence number is chosen."""
14
+ ...
15
+
16
+ def uuid3(namespace: UUID, name: str) -> UUID:
17
+ """Generate a UUID from the MD5 hash of a namespace UUID and a name."""
18
+ ...
19
+
20
+ def uuid4() -> UUID:
21
+ """Generate a random UUID."""
22
+ ...
23
+
24
+ def uuid5(namespace: UUID, name: str) -> UUID:
25
+ """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
26
+ ...
27
+
28
+ def uuid6(node: _Int | None = None, timestamp: _Int | None = None) -> UUID:
29
+ """Generate a version 6 UUID using the given timestamp and a host ID.
30
+ This is similar to version 1 UUIDs,
31
+ except that it is lexicographically sortable by timestamp.
32
+ """
33
+ ...
34
+
35
+ def uuid7(timestamp: _Int | None = None) -> UUID:
36
+ """Generate a version 7 UUID using a time value and random bytes."""
37
+ ...
38
+
39
+ def uuid8(bytes: _Bytes) -> UUID:
40
+ """Generate a custom UUID comprised almost entirely of user-supplied bytes.."""
41
+ ...
uuid_utils/py.typed ADDED
File without changes
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.3
2
+ Name: uuid_utils
3
+ Version: 0.7.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.8
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
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 in Rust
19
+ Keywords: rust,uuid
20
+ Author-email: Amin Alaee <me@aminalaee.dev>
21
+ Requires-Python: >=3.8
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
+ which implements existing UUID versions like V4 in Rust
45
+ and also adds draft UUID versions like V6.
46
+
47
+ Avaialble UUID versions:
48
+
49
+ - `uuid1` - Version 1 UUIDs using a timestamp and monotonic counter.
50
+ - `uuid3` - Version 3 UUIDs based on the MD5 hash of some data.
51
+ - `uuid4` - Version 4 UUIDs with random data.
52
+ - `uuid5` - Version 5 UUIDs based on the SHA1 hash of some data.
53
+ - `uuid6` - Version 6 UUIDs using a timestamp and monotonic counter.
54
+ - `uuid7` - Version 7 UUIDs using a Unix timestamp ordered by time.
55
+ - `uuid8` - Version 8 UUIDs using user-defined data.
56
+
57
+ <sup>Please note that UUID versions 6, 7 and 8 are still in draft RFC.</sup><br>
58
+
59
+ ## Installation
60
+
61
+ ```shell
62
+ $ pip install uuid-utils
63
+ ```
64
+
65
+ ## Example
66
+
67
+ ```shell
68
+ >>> import uuid_utils as uuid
69
+
70
+ >>> # make a random UUID
71
+ >>> uuid.uuid4()
72
+ UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec')
73
+
74
+ >>> # make a random UUID using a Unix timestamp which is time-ordered.
75
+ >>> uuid.uuid7()
76
+ UUID('018afa4a-0d21-7e6c-b857-012bc678552b')
77
+
78
+ >>> # make a UUID using a SHA-1 hash of a namespace UUID and a name
79
+ >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
80
+ UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')
81
+
82
+ >>> # make a UUID using an MD5 hash of a namespace UUID and a name
83
+ >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
84
+ UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
85
+ ```
86
+
87
+ ## Compat module
88
+
89
+ In some cases you might need `UUID` instances to be returned
90
+ from the standrad-library `uuid`, not a custom `UUID` class.
91
+ In that case you can use the `uuid_utils.compat` which comes with a performance penalty
92
+ in comparison with the `uuid_utils` default behaviour, but still faster than the standard-library.
93
+
94
+ ```py
95
+ >>> import uuid_utils.compat as uuid
96
+
97
+ >>> # make a random UUID
98
+ >>> uuid.uuid4()
99
+ UUID('ffe95fcc-b818-4aca-a350-e0a35b9de6ec')
100
+ ```
101
+
102
+ ## Benchmarks
103
+
104
+ | Benchmark | Min | Max | Mean | Min (+) | Max (+) | Mean (+) |
105
+ |-----------------|---------|---------|---------|-----------------|-----------------|-----------------|
106
+ | UUID V1 | 0.058 | 0.059 | 0.058 | 0.005 (12.0x) | 0.005 (11.9x) | 0.005 (12.0x) |
107
+ | UUID V3 | 0.063 | 0.064 | 0.063 | 0.008 (7.9x) | 0.008 (8.1x) | 0.008 (8.0x) |
108
+ | UUID V4 | 0.041 | 0.041 | 0.041 | 0.004 (11.1x) | 0.004 (10.8x) | 0.004 (10.9x) |
109
+ | UUID V5 | 0.064 | 0.066 | 0.065 | 0.008 (8.1x) | 0.008 (8.1x) | 0.008 (8.1x) |
110
+ | UUID from hex | 0.024 | 0.025 | 0.024 | 0.004 (6.7x) | 0.004 (6.6x) | 0.004 (6.6x) |
111
+ | UUID from bytes | 0.024 | 0.025 | 0.024 | 0.004 (6.7x) | 0.004 (6.6x) | 0.004 (6.7x) |
112
+ | UUID from int | 0.024 | 0.025 | 0.024 | 0.004 (6.6x) | 0.004 (6.7x) | 0.004 (6.6x) |
113
+ | UUID from fields | 0.028 | 0.028 | 0.028 | 0.009 (3.1x) | 0.009 (3.1x) | 0.009 (3.1x) |
114
+
115
+ ## How to develop locally
116
+
117
+ ```shell
118
+ $ make build
119
+ $ make test
120
+ ```
121
+
122
+ Or:
123
+
124
+ ```shell
125
+ $ RUSTFLAGS="--cfg uuid_unstable" maturin develop --release
126
+ ```
127
+
@@ -0,0 +1,10 @@
1
+ uuid_utils-0.7.0.dist-info/METADATA,sha256=XpVI7UmfHTsaPEOz1jRzrKQs_8jnpcz8o6G0mRjX3h8,4625
2
+ uuid_utils-0.7.0.dist-info/WHEEL,sha256=mH_FwrJZY2b-VCw9zg2dflPWfDJs_OF2gu28f1UC4CQ,111
3
+ uuid_utils-0.7.0.dist-info/license_files/LICENSE.md,sha256=DEf1K0xIS9BMeOfJaVQu6jGv5kT1h_O4qMzOhjUsYEY,1487
4
+ uuid_utils/compat/__init__.pyi,sha256=msxBDRkxWjdSRFmCeP2O2J6pib2qkJoZEaoC5hcF8X8,1425
5
+ uuid_utils/compat/__init__.py,sha256=-pGwZJmEoRzNmqteXXtcbjzO7KO3-xekYT02GjImtmM,2071
6
+ uuid_utils/__init__.pyi,sha256=JNQmgdNecusC7zFZiZTosO9d08yGm3sOCITC6PHF2P4,6058
7
+ uuid_utils/__init__.py,sha256=teEvYB7oh34wISOjZYdA011-7VdeLKfQGjR615_-lCc,622
8
+ uuid_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ uuid_utils/_uuid_utils.pypy38-pp73-darwin.so,sha256=9MkN-wEwVKRFdnAfkOGsW7T4VE5WeE3XCrJadVILAQw,693296
10
+ uuid_utils-0.7.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.5.1)
3
+ Root-Is-Purelib: false
4
+ Tag: pp38-pypy38_pp73-macosx_10_12_x86_64
@@ -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.