typeid-python 0.2.1__py3-none-any.whl → 0.2.3__py3-none-any.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 typeid-python might be problematic. Click here for more details.

typeid/typeid.py CHANGED
@@ -1,3 +1,4 @@
1
+ import warnings
1
2
  from typing import Optional
2
3
  from uuid import UUID
3
4
 
@@ -18,6 +19,16 @@ class TypeID:
18
19
  self._prefix = prefix or ""
19
20
  self._suffix = suffix
20
21
 
22
+ @classmethod
23
+ def from_string(cls, string: str):
24
+ prefix, suffix = get_prefix_and_suffix(string=string)
25
+ return cls(suffix=suffix, prefix=prefix)
26
+
27
+ @classmethod
28
+ def from_uuid(cls, suffix: UUID, prefix: Optional[str] = None):
29
+ suffix_str = _convert_uuid_to_b32(suffix)
30
+ return TypeID(suffix=suffix_str, prefix=prefix)
31
+
21
32
  @property
22
33
  def suffix(self) -> str:
23
34
  return self._suffix
@@ -26,6 +37,10 @@ class TypeID:
26
37
  def prefix(self) -> str:
27
38
  return self._prefix
28
39
 
40
+ @property
41
+ def uuid(self) -> UUID:
42
+ return _convert_b32_to_uuid(self.suffix)
43
+
29
44
  def __str__(self) -> str:
30
45
  value = ""
31
46
  if self.prefix:
@@ -33,20 +48,36 @@ class TypeID:
33
48
  value += self.suffix
34
49
  return value
35
50
 
51
+ def __repr__(self):
52
+ return "%s(%r)" % (self.__class__.__name__, str(self))
53
+
36
54
  def __eq__(self, value: object) -> bool:
37
55
  if not isinstance(value, TypeID):
38
56
  return False
39
57
  return value.prefix == self.prefix and value.suffix == self.suffix
40
58
 
59
+ def __gt__(self, other):
60
+ if isinstance(other, TypeID):
61
+ return str(self) > str(other)
62
+ return NotImplemented
63
+
64
+ def __ge__(self, other):
65
+ if isinstance(other, TypeID):
66
+ return str(self) >= str(other)
67
+ return NotImplemented
68
+
69
+ def __hash__(self) -> int:
70
+ return hash((self.prefix, self.suffix))
71
+
41
72
 
42
73
  def from_string(string: str) -> TypeID:
43
- prefix, suffix = get_prefix_and_suffix(string=string)
44
- return TypeID(suffix=suffix, prefix=prefix)
74
+ warnings.warn("Consider TypeID.from_string instead.", DeprecationWarning)
75
+ return TypeID.from_string(string=string)
45
76
 
46
77
 
47
78
  def from_uuid(suffix: UUID, prefix: Optional[str] = None) -> TypeID:
48
- suffix_str = _convert_uuid_to_b32(suffix)
49
- return TypeID(suffix=suffix_str, prefix=prefix)
79
+ warnings.warn("Consider TypeID.from_uuid instead.", DeprecationWarning)
80
+ return TypeID.from_uuid(suffix=suffix, prefix=prefix)
50
81
 
51
82
 
52
83
  def get_prefix_and_suffix(string: str) -> tuple:
@@ -66,3 +97,7 @@ def get_prefix_and_suffix(string: str) -> tuple:
66
97
 
67
98
  def _convert_uuid_to_b32(uuid_instance: UUID) -> str:
68
99
  return base32.encode(list(uuid_instance.bytes))
100
+
101
+
102
+ def _convert_b32_to_uuid(b32: str) -> UUID:
103
+ return UUID(bytes=bytes(base32.decode(b32)))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typeid-python
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
5
5
  Home-page: https://github.com/akhundMurad/typeid-python
6
6
  License: MIT
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3.8
16
16
  Classifier: Programming Language :: Python :: 3.9
17
17
  Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
19
20
  Provides-Extra: cli
20
21
  Requires-Dist: uuid6 (>=2023.5.2,<2024.0.0)
21
22
  Project-URL: Repository, https://github.com/akhundMurad/typeid-python
@@ -82,9 +83,9 @@ This particular implementation provides an pip package that can be used by any P
82
83
  - Create TypeID from string:
83
84
 
84
85
  ```python
85
- from typeid import from_string
86
+ from typeid import TypeID
86
87
 
87
- typeid = from_string("user_01h45ytscbebyvny4gc8cr8ma2")
88
+ typeid = TypeID.from_string("user_01h45ytscbebyvny4gc8cr8ma2")
88
89
 
89
90
  print(str(typeid)) # "user_01h45ytscbebyvny4gc8cr8ma2"
90
91
  ```
@@ -92,13 +93,13 @@ This particular implementation provides an pip package that can be used by any P
92
93
  - Create TypeID from uuid7:
93
94
 
94
95
  ```python
95
- from typeid import from_uuid
96
+ from typeid import TypeID
96
97
  from uuid6 import uuid7
97
98
 
98
99
  uuid = uuid7() # UUID('01890bf0-846f-7762-8605-5a3abb40e0e5')
99
100
  prefix = "user"
100
101
 
101
- typeid = from_uuid(prefix=prefix, suffix=uuid)
102
+ typeid = TypeID.from_uuid(prefix=prefix, suffix=uuid)
102
103
 
103
104
  print(str(typeid)) # "user_01h45z113fexh8c1at7axm1r75"
104
105
  ```
@@ -3,9 +3,9 @@ typeid/base32.py,sha256=UTYXJjb95_nn-vYIpw7nquguBac4GZ0TL0oE6BuujPg,6504
3
3
  typeid/cli.py,sha256=h93_EAOzWO3bqubgL83Q-smHp11lvxMjgAunwyTWwFM,872
4
4
  typeid/constants.py,sha256=2ApV0agNys2yI9NM8oQZbyTR2rgP-VtxXGrM6glBB2Q,37
5
5
  typeid/errors.py,sha256=QPHZ-DJg5OpPOHtuetsqMCYu-E_aHMJZTTeFqx9Gz_4,207
6
- typeid/typeid.py,sha256=Ia-hr1JpS0iB3i3Iqv9GlTmTRaQK0QEpjXn8SPxcPOc,1862
6
+ typeid/typeid.py,sha256=jGMZ3FZXSe6x8Ib6AQi5lVbmlb2PWJcwKhXDEScW_pU,2927
7
7
  typeid/validation.py,sha256=yvLO5lfMkJpduZzql_FJlj4hW6HcWURWYLRQvR92SSM,899
8
- typeid_python-0.2.1.dist-info/LICENSE,sha256=f98oZ9FId4i3835UJYGw066BU8PSc57L1utGWS1ypcs,1070
9
- typeid_python-0.2.1.dist-info/METADATA,sha256=w_gCm73577WtV9nzwb8wVHgjc47ZYi7umJa9gJBDyc0,4067
10
- typeid_python-0.2.1.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
11
- typeid_python-0.2.1.dist-info/RECORD,,
8
+ typeid_python-0.2.3.dist-info/LICENSE,sha256=f98oZ9FId4i3835UJYGw066BU8PSc57L1utGWS1ypcs,1070
9
+ typeid_python-0.2.3.dist-info/METADATA,sha256=HLC7cDDSYyth-xd1bRDxNeCLPAMI2Pa6jAhz9RzHkaE,4124
10
+ typeid_python-0.2.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
+ typeid_python-0.2.3.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.6.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any