lastuuid 0.1.2__cp311-cp311-musllinux_1_1_armv7l.whl → 0.2.1__cp311-cp311-musllinux_1_1_armv7l.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 +8 -2
- lastuuid/dummies.py +2 -0
- lastuuid/lastuuid.cpython-311-arm-linux-musleabihf.so +0 -0
- lastuuid/lastuuid.pyi +5 -0
- lastuuid/utils.py +72 -0
- lastuuid-0.2.1.dist-info/METADATA +96 -0
- lastuuid-0.2.1.dist-info/RECORD +10 -0
- {lastuuid-0.1.2.dist-info → lastuuid-0.2.1.dist-info}/WHEEL +1 -1
- lastuuid-0.1.2.dist-info/METADATA +0 -101
- lastuuid-0.1.2.dist-info/RECORD +0 -9
lastuuid/__init__.py
CHANGED
lastuuid/dummies.py
CHANGED
|
Binary file
|
lastuuid/lastuuid.pyi
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"""Pyo3 binding interface definition."""
|
|
2
2
|
|
|
3
3
|
from uuid import UUID
|
|
4
|
+
from datetime import datetime, timezone
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
def uuid7() -> UUID:
|
|
7
8
|
"""
|
|
8
9
|
Generate an uuid using uuidv7 format, the best format that feet in a BTree.
|
|
9
10
|
"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def uuid7_to_datetime(uuid7: UUID, tz=timezone.utc) -> datetime:
|
|
14
|
+
"""Extract the datetime part of an uuid 7."""
|
lastuuid/utils.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utilities methods that may be used for database querying purpose.
|
|
3
|
+
|
|
4
|
+
uuid7 are timestamped sorted, so there are a good solution for generating
|
|
5
|
+
primary keys. Because they contains a date time, a UUID range can be compute
|
|
6
|
+
in order to retrieve UUIDs generated at a given time.
|
|
7
|
+
|
|
8
|
+
Note that in any distribyted system, only using a datetime, or an uuid
|
|
9
|
+
has its limit to properly sort items. This documentation does not cover
|
|
10
|
+
the design data intensive application book ;).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from datetime import UTC, date, datetime, time, timedelta
|
|
14
|
+
from typing_extensions import Tuple
|
|
15
|
+
from uuid import UUID
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"uuid7_bounds_from_datetime",
|
|
19
|
+
"uuid7_bounds_from_date",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _datetime_to_uuid7_lowest(dt: datetime) -> UUID:
|
|
24
|
+
unix_ts_ms = int(dt.timestamp() * 1000)
|
|
25
|
+
version = 0x07
|
|
26
|
+
var = 2
|
|
27
|
+
final_bytes = unix_ts_ms.to_bytes(6)
|
|
28
|
+
final_bytes += (version << 12).to_bytes(2)
|
|
29
|
+
final_bytes += ((var << 62) + 0x3000000000000000).to_bytes(8)
|
|
30
|
+
return UUID(bytes=final_bytes)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def uuid7_bounds_from_datetime(
|
|
34
|
+
dt_lower: datetime,
|
|
35
|
+
dt_upper: datetime | None = None,
|
|
36
|
+
) -> Tuple[UUID, UUID]:
|
|
37
|
+
"""
|
|
38
|
+
Get uuid bound for a half-open interval.
|
|
39
|
+
|
|
40
|
+
This function can be usefull to search for any rows based on a uuid7 in a sql query.
|
|
41
|
+
If one parameter is set, then the search is based on a millisecond, because uuid7
|
|
42
|
+
are only millisecond precision.
|
|
43
|
+
|
|
44
|
+
The returned bound are half open, so the upper bound, from the ``dt_upper`` will
|
|
45
|
+
not include in the result, only the first value to be excluded.
|
|
46
|
+
|
|
47
|
+
If the the second parameter is ommited, then the bound only contains a millisecond,
|
|
48
|
+
of dt_lower.
|
|
49
|
+
|
|
50
|
+
:param dt_lower: the included left bound of the range.
|
|
51
|
+
:param dt_upper: the excluded right bound of the range.
|
|
52
|
+
"""
|
|
53
|
+
return _datetime_to_uuid7_lowest(dt_lower), _datetime_to_uuid7_lowest(
|
|
54
|
+
dt_upper or (dt_lower + timedelta(milliseconds=1))
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def uuid7_bounds_from_date(dt: date, tz=UTC) -> Tuple[UUID, UUID]:
|
|
59
|
+
"""
|
|
60
|
+
Get uuid bound for a particular day.
|
|
61
|
+
|
|
62
|
+
This function can be usefull to search for any rows based on a uuid7 in a sql query.
|
|
63
|
+
The right bound return is the first uuid of the next day that should be excluded.
|
|
64
|
+
|
|
65
|
+
:param dt: the included left bound of the range.
|
|
66
|
+
:param tz: the timezone used to compute the UUID, it should always be ommited.
|
|
67
|
+
"""
|
|
68
|
+
return _datetime_to_uuid7_lowest(
|
|
69
|
+
datetime.combine(dt, time=time(tzinfo=tz))
|
|
70
|
+
), _datetime_to_uuid7_lowest(
|
|
71
|
+
datetime.combine(dt + timedelta(days=1), time=time(tzinfo=tz))
|
|
72
|
+
)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lastuuid
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: Programming Language :: Rust
|
|
7
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
8
|
+
Classifier: Typing :: Typed
|
|
9
|
+
Requires-Dist: furo>=2024.5.6 ; extra == 'docs'
|
|
10
|
+
Requires-Dist: linkify-it-py>=2.0.3,<3 ; extra == 'docs'
|
|
11
|
+
Requires-Dist: myst-parser>=3.0.0,<4 ; python_full_version < '3.10' and extra == 'docs'
|
|
12
|
+
Requires-Dist: myst-parser>=4.0.0,<5 ; python_full_version >= '3.10' and extra == 'docs'
|
|
13
|
+
Requires-Dist: sphinx>=7.0.1,<8 ; extra == 'docs'
|
|
14
|
+
Requires-Dist: sphinx-autodoc2>=0.5.0,<1 ; extra == 'docs'
|
|
15
|
+
Provides-Extra: docs
|
|
16
|
+
Summary: Fast UUIDv7 Compatible with standard library type, and utils.
|
|
17
|
+
Keywords: uuid,UUIDv7
|
|
18
|
+
Author: Guillaume Gauvrit <guillaume@gauvr.it>
|
|
19
|
+
Author-email: Guillaume Gauvrit <guillaume@gauvr.it>
|
|
20
|
+
License: MIT License
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
23
|
+
Project-URL: Homepage, https://github.com/mardiros/lastuuid
|
|
24
|
+
Project-URL: Documentation, https://mardiros.github.io/lastuuid/
|
|
25
|
+
Project-URL: Repository, https://github.com/mardiros/lastuuid.git
|
|
26
|
+
Project-URL: Issues, https://github.com/mardiros/lastuuid/issues
|
|
27
|
+
Project-URL: Changelog, https://mardiros.github.io/lastuuid/changelog.html
|
|
28
|
+
|
|
29
|
+
# lastuuid - yet another uuid library
|
|
30
|
+
|
|
31
|
+
[](https://mardiros.github.io/lastuuid/)
|
|
32
|
+
[](https://github.com/mardiros/lastuuid/actions/workflows/tests.yml)
|
|
33
|
+
[](https://codeclimate.com/github/mardiros/lastuuid/maintainability)
|
|
34
|
+
|
|
35
|
+
UUID type is awesome, but, at the moment, the UUID type in the standard library
|
|
36
|
+
does not support the uuid7 format.
|
|
37
|
+
|
|
38
|
+
You may find plenty of library that implement uuid7, but they have downside,
|
|
39
|
+
such has ignoring pull request to fix issues, or not compatible with Pydantic.
|
|
40
|
+
|
|
41
|
+
```{note}
|
|
42
|
+
lastuuid is a developer joke based on the nature of UUIDv7,
|
|
43
|
+
|
|
44
|
+
where the most recently generated UUID is always the last one when sorted.
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### UUID7
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
>>> from lastuuid import uuid7
|
|
53
|
+
>>> uuid7()
|
|
54
|
+
UUID('019316cc-f99a-77b3-89d5-ed8c3cf1f50e')
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
There is no parameter here, the uuid is generated from the current time.
|
|
58
|
+
|
|
59
|
+
The implementation of uuid7 algorithm is made in the uuid7 rust crate.
|
|
60
|
+
|
|
61
|
+
#### Pydantic
|
|
62
|
+
|
|
63
|
+
This lib has been created because all the other library that implement uuid7
|
|
64
|
+
create there own UUID type, so its not easy to use with pydantic.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from uuid import UUID
|
|
68
|
+
from pydantic import BaseModel, Field
|
|
69
|
+
|
|
70
|
+
from lastuuid import uuid7
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class Dummy(BaseModel):
|
|
74
|
+
id: UUID = Field(default_factory=uuid7)
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Performance
|
|
79
|
+
|
|
80
|
+
On my machine the uuid7 is as fast (or slow) as the native uuid4.
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
$ python -m timeit "from lastuuid import uuid7; uuid7()"
|
|
84
|
+
200000 loops, best of 5: 1.8 usec per loop
|
|
85
|
+
|
|
86
|
+
$ python -m timeit "from uuid import uuid4; uuid4()"
|
|
87
|
+
200000 loops, best of 5: 1.82 usec per loop
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Read More
|
|
91
|
+
|
|
92
|
+
There are other usefull function in the library that cab be found in the
|
|
93
|
+
[API documentation](https://mardiros.github.io/lastuuid/).
|
|
94
|
+
|
|
95
|
+
https://mardiros.github.io/lastuuid/
|
|
96
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
lastuuid-0.2.1.dist-info/METADATA,sha256=L3PIVuRQrjOFjyF-JbNsSRYNYAWdEn49d72veTLBOyY,3363
|
|
2
|
+
lastuuid-0.2.1.dist-info/WHEEL,sha256=eEW9sgHmcTI6Fb06Gw8Kq0OtzGWje-kTS8SYdczPyFo,107
|
|
3
|
+
lastuuid.libs/libgcc_s-5b5488a6.so.1,sha256=HGKUsVmTeNAxEdSy7Ua5Vh_I9FN3RCbPWzvZ7H_TrwE,2749061
|
|
4
|
+
lastuuid/__init__.py,sha256=QwhIMAj4P8cB98_6Qj3mUceQXkHtS9G3bNfGrgb-R1w,122
|
|
5
|
+
lastuuid/lastuuid.pyi,sha256=s-ll8KBbUeUUqQz087pADg3Y3HLnOikty6dpmYC8fMs,340
|
|
6
|
+
lastuuid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
lastuuid/dummies.py,sha256=0YcdycGKVya59RUnBZSlJg49WeYwjxBcVZKEwuflu4E,520
|
|
8
|
+
lastuuid/utils.py,sha256=PPxM7WYP_Bjy1uXn_dg6rc1GMVEkleh2Z0vjb91XXUo,2538
|
|
9
|
+
lastuuid/lastuuid.cpython-311-arm-linux-musleabihf.so,sha256=YZD5rB_rHKeOZTdRWKO3sutiJQtc31RJWF1iILbdjtI,551077
|
|
10
|
+
lastuuid-0.2.1.dist-info/RECORD,,
|
|
@@ -1,101 +0,0 @@
|
|
|
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
|
-
|
lastuuid-0.1.2.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
lastuuid-0.1.2.dist-info/METADATA,sha256=_TXvSJNDq2ZdkWZgY8WYwU5PZJKFxK--2ZlPROyLE54,2789
|
|
2
|
-
lastuuid-0.1.2.dist-info/WHEEL,sha256=9YaEG-6KZzBhbug_Yvxime2h3q3JbcjzXcLmHXUM6EM,107
|
|
3
|
-
lastuuid.libs/libgcc_s-5b5488a6.so.1,sha256=HGKUsVmTeNAxEdSy7Ua5Vh_I9FN3RCbPWzvZ7H_TrwE,2749061
|
|
4
|
-
lastuuid/__init__.py,sha256=J0y-_0o53066oeP1gXBC2MmmBFj0EeETiskPnY4SqKc,49
|
|
5
|
-
lastuuid/dummies.py,sha256=4ekFj4XZ3LsCUr7dxnnEoQUo8mydox8aso6Vp89V1is,497
|
|
6
|
-
lastuuid/lastuuid.pyi,sha256=PJe_XMTEAMFtsfRfo4HNWHTwPdtMl_hSTQJU6jNIKfY,183
|
|
7
|
-
lastuuid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
lastuuid/lastuuid.cpython-311-arm-linux-musleabihf.so,sha256=0w-MclxwOAqIHQfjjlLNfiKlCtkN21Y4QCyNACHjERM,509921
|
|
9
|
-
lastuuid-0.1.2.dist-info/RECORD,,
|