lastuuid 0.1.2__cp310-cp310-win_amd64.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 lastuuid might be problematic. Click here for more details.

lastuuid/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .lastuuid import uuid7
2
+
3
+ __all__ = ["uuid7"]
lastuuid/dummies.py ADDED
@@ -0,0 +1,23 @@
1
+ """A dummy uuid usefull for unit testing purpose."""
2
+
3
+ from typing import Iterator
4
+ from uuid import UUID
5
+
6
+
7
+ def gen_id() -> Iterator[int]:
8
+ num = 0
9
+ while True:
10
+ num += 1
11
+ yield num
12
+
13
+
14
+ next_id = gen_id()
15
+
16
+
17
+ def uuidgen(i: int = 0, j: int = 0, k: int = 0, x: int = 0, y: int = 0) -> UUID:
18
+ """
19
+ A UUID generator that makes UUIDs more readable for humans.
20
+ """
21
+ if i == 0 and y == 0:
22
+ y = next(next_id)
23
+ return UUID(f"{i:0>8}-{j:0>4}-{k:0>4}-{x:0>4}-{y:0>12}")
Binary file
lastuuid/lastuuid.pyi ADDED
@@ -0,0 +1,9 @@
1
+ """Pyo3 binding interface definition."""
2
+
3
+ from uuid import UUID
4
+
5
+
6
+ def uuid7() -> UUID:
7
+ """
8
+ Generate an uuid using uuidv7 format, the best format that feet in a BTree.
9
+ """
lastuuid/py.typed ADDED
File without changes
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.4
2
+ Name: lastuuid
3
+ Version: 0.1.2
4
+ Classifier: License :: OSI Approved :: MIT License
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Programming Language :: Rust
7
+ Summary: UUID gen for the python standard library.
8
+ Keywords: environment,substitution,variables
9
+ Author: Guillaume Gauvrit <guillaume@gauvr.it>
10
+ Author-email: Guillaume Gauvrit <guillaume@gauvr.it>
11
+ License: MIT License
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
14
+ Project-URL: Homepage, https://github.com/mardiros/lastuuid
15
+ Project-URL: Documentation, https://github.com/mardiros/lastuuid/blob/main/README.md
16
+ Project-URL: Repository, https://github.com/mardiros/lastuuid.git
17
+ Project-URL: Issues, https://github.com/mardiros/lastuuid/issues
18
+ Project-URL: Changelog, https://github.com/mardiros/lastuuid/blob/main/CHANGELOG.md
19
+
20
+ # lastuuid - yet another uuid library
21
+
22
+ UUID type is awesome, but, at the moment, the UUID type in the standard library
23
+ does not support the uuid7 format.
24
+
25
+ This is where lastuuid library is usefull.
26
+
27
+ ## Usage
28
+
29
+ ### UUID7
30
+
31
+ ```python
32
+ >>> from lastuuid import uuid7
33
+ >>> uuid7()
34
+ UUID('019316cc-f99a-77b3-89d5-ed8c3cf1f50e')
35
+ ```
36
+
37
+ There is no parameter here, the uuid is generated from the current time.
38
+
39
+ The implementation of uuid7 algorithm is made in the uuid7 rust crate.
40
+
41
+ #### Pydantic
42
+
43
+ This lib has been created because all the other library that implement uuid7
44
+ create there own UUID type, so its not easy to use with pydantic.
45
+
46
+ ```python
47
+ from uuid import UUID
48
+ from pydantic import BaseModel, Field
49
+
50
+ from lastuuid import uuid7
51
+
52
+
53
+ class Dummy(BaseModel):
54
+ id: UUID = Field(default_factory=uuid7)
55
+
56
+ ```
57
+
58
+ #### Performance
59
+
60
+ On my machine the uuid7 is as fast (or slow) as the native uuid4.
61
+
62
+ ```bash
63
+ $ python -m timeit "from lastuuid import uuid7; uuid7()"
64
+ 200000 loops, best of 5: 1.8 usec per loop
65
+
66
+ $ python -m timeit "from uuid import uuid4; uuid4()"
67
+ 200000 loops, best of 5: 1.82 usec per loop
68
+ ```
69
+
70
+ ### Testing with uuid without a brain
71
+
72
+ The uuidgen method is not made for production code, it is not suited to be
73
+ fast, it is here to generate uuid has autoincrement or as redictable ids,
74
+ because UUID are made to create an identifier before it's saved into a
75
+ database.
76
+
77
+
78
+ Autoincrement your uuid in a test suite avoid some brain pain:
79
+
80
+ ```python
81
+ >>> from lastuuid.dummies import uuidgen
82
+ >>> uuidgen()
83
+ UUID('00000000-0000-0000-0000-000000000001')
84
+ >>> uuidgen()
85
+ UUID('00000000-0000-0000-0000-000000000002')
86
+ ```
87
+
88
+ Or even more usefull:
89
+
90
+ UUID predicted, where only the first bunch of bytes needs to be read; or a few,
91
+ to arrange some object ids.
92
+
93
+
94
+ ```python
95
+ >>> from lastuuid.dummies import uuidgen
96
+ >>> uuidgen(1)
97
+ UUID('00000001-0000-0000-0000-000000000000')
98
+ >>> uuidgen(1, 2, 3, 4, 5)
99
+ UUID('00000001-0002-0003-0004-000000000005')
100
+ ```
101
+
@@ -0,0 +1,8 @@
1
+ lastuuid-0.1.2.dist-info/METADATA,sha256=rvx50UZUSvA6VpX5t24NKyMcqjh9uHu9LI6LVg-uDsI,2870
2
+ lastuuid-0.1.2.dist-info/WHEEL,sha256=ieLtPNGsC7xoJjcmwA6ZxvTXpcxDlcXaGCM87uD_Bf0,96
3
+ lastuuid/dummies.py,sha256=appIhKdQLL_8Mo5Xb0fzYjBV6w3iJrHZzgk-JNAnej0,520
4
+ lastuuid/lastuuid.pyi,sha256=UWNZIdqlzkbln21QRVGqfOX8sn6FLJUjbG3jlAT22O4,192
5
+ lastuuid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ lastuuid/__init__.py,sha256=GwcZ4cGLHj95prUoK_-Te0TY3gxoLguXp-OEMIJNJzo,52
7
+ lastuuid/lastuuid.cp310-win_amd64.pyd,sha256=Yi_ibq20DG8mJfHr39jg7qvg5aEIM6QhhCsvNWbxL1s,202240
8
+ lastuuid-0.1.2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.7.8)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-win_amd64