lastuuid 0.1.1__cp310-cp310-macosx_10_12_x86_64.whl → 0.2.1__cp310-cp310-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 lastuuid might be problematic. Click here for more details.

lastuuid/__init__.py CHANGED
@@ -1,3 +1,9 @@
1
- from .lastuuid import uuid7
1
+ """
2
+ lastuuid API.
3
+ """
4
+ from .lastuuid import uuid7, uuid7_to_datetime
2
5
 
3
- __all__ = ["uuid7"]
6
+ __all__ = [
7
+ "uuid7",
8
+ "uuid7_to_datetime",
9
+ ]
lastuuid/dummies.py CHANGED
@@ -3,6 +3,8 @@
3
3
  from typing import Iterator
4
4
  from uuid import UUID
5
5
 
6
+ __all__ = ["uuidgen"]
7
+
6
8
 
7
9
  def gen_id() -> Iterator[int]:
8
10
  num = 0
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
+ [![Documentation](https://github.com/mardiros/lastuuid/actions/workflows/publish-doc.yml/badge.svg)](https://mardiros.github.io/lastuuid/)
32
+ [![Continuous Integration](https://github.com/mardiros/lastuuid/actions/workflows/tests.yml/badge.svg)](https://github.com/mardiros/lastuuid/actions/workflows/tests.yml)
33
+ [![Maintainability](https://api.codeclimate.com/v1/badges/8e7293fabe7508b2ec6c/maintainability)](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,9 @@
1
+ lastuuid-0.2.1.dist-info/METADATA,sha256=L3PIVuRQrjOFjyF-JbNsSRYNYAWdEn49d72veTLBOyY,3363
2
+ lastuuid-0.2.1.dist-info/WHEEL,sha256=Nvf9uS0ipTkasVzlCrL-zmcxhW_z3aj8r383FZQZHis,106
3
+ lastuuid/lastuuid.pyi,sha256=s-ll8KBbUeUUqQz087pADg3Y3HLnOikty6dpmYC8fMs,340
4
+ lastuuid/__init__.py,sha256=QwhIMAj4P8cB98_6Qj3mUceQXkHtS9G3bNfGrgb-R1w,122
5
+ lastuuid/utils.py,sha256=PPxM7WYP_Bjy1uXn_dg6rc1GMVEkleh2Z0vjb91XXUo,2538
6
+ lastuuid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ lastuuid/dummies.py,sha256=0YcdycGKVya59RUnBZSlJg49WeYwjxBcVZKEwuflu4E,520
8
+ lastuuid/lastuuid.cpython-310-darwin.so,sha256=bvkBLrkHFKrq2myAr9xd8h5nRU3XYwVtTK7GqUE9U2g,479640
9
+ lastuuid-0.2.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (1.7.4)
2
+ Generator: maturin (1.8.2)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp310-cp310-macosx_10_12_x86_64
@@ -1,90 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: lastuuid
3
- Version: 0.1.1
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
- ## Usage
26
-
27
- ### UUID7
28
-
29
- ```python
30
- >>> from lastuuid import uuid7
31
- >>> uuid7()
32
- UUID('019316cc-f99a-77b3-89d5-ed8c3cf1f50e')
33
- ```
34
-
35
- There is no parameter here, the uuid is generated from the current time.
36
-
37
- The implementation of uuid7 algorithm is made in the uuid7 rust crate.
38
-
39
- #### Pydantic
40
-
41
- This lib has been created because all the other library that implement uuid7
42
- create there own UUID type, so its not easy to use with pydantic.
43
-
44
- ```python
45
- from uuid import UUID
46
- from pydantic import BaseModel, Field
47
-
48
- from lastuuid import uuid7
49
-
50
-
51
- class Dummy(BaseModel):
52
- id: UUID = Field(default_factory=uuid7)
53
-
54
- ```
55
-
56
- #### Performance
57
-
58
- On my machine the uuid7 is as fast (or slow) as the native uuid4.
59
-
60
- ```bash
61
- $ python -m timeit "from lastuuid import uuid7; uuid7()"
62
- 200000 loops, best of 5: 1.8 usec per loop
63
-
64
- $ python -m timeit "from uuid import uuid4; uuid4()"
65
- 200000 loops, best of 5: 1.82 usec per loop
66
- ```
67
-
68
- ### Testing with uuid without brain
69
-
70
- Autoincrement your uuid in a test suite avoid some brain pain.
71
-
72
- ```python
73
- >>> from lastuuid.dummies import uuidgen
74
- >>> uuidgen()
75
- UUID('00000000-0000-0000-0000-000000000001')
76
- >>> uuidgen()
77
- UUID('00000000-0000-0000-0000-000000000002')
78
- ```
79
-
80
- Or event more readable;
81
- UUID predicted, where only the first bytes needs to be read.
82
-
83
- ```python
84
- >>> from lastuuid.dummies import uuidgen
85
- >>> uuidgen(1)
86
- UUID('00000001-0000-0000-0000-000000000000')
87
- >>> uuidgen(1,2,3,4,5)
88
- UUID('00000001-0002-0003-0004-000000000005')
89
- ```
90
-
@@ -1,8 +0,0 @@
1
- lastuuid-0.1.1.dist-info/METADATA,sha256=aNObGTSbwFTdlW45XWcGMmRGMnK_5FsEwwHqJEk27kc,2460
2
- lastuuid-0.1.1.dist-info/WHEEL,sha256=LVI1AVbYRTYC5adM2lSivmcJtOl9s941xFznjYMT5P8,106
3
- lastuuid/lastuuid.pyi,sha256=PJe_XMTEAMFtsfRfo4HNWHTwPdtMl_hSTQJU6jNIKfY,183
4
- lastuuid/__init__.py,sha256=J0y-_0o53066oeP1gXBC2MmmBFj0EeETiskPnY4SqKc,49
5
- lastuuid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- lastuuid/dummies.py,sha256=4ekFj4XZ3LsCUr7dxnnEoQUo8mydox8aso6Vp89V1is,497
7
- lastuuid/lastuuid.cpython-310-darwin.so,sha256=74X_DyACESG5-uijWoan9SU4Dglnrn4yQIamxTwbgL0,436376
8
- lastuuid-0.1.1.dist-info/RECORD,,