typeid-python 0.2.1__tar.gz → 0.2.3__tar.gz
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_python-0.2.1 → typeid_python-0.2.3}/PKG-INFO +6 -5
- {typeid_python-0.2.1 → typeid_python-0.2.3}/README.md +4 -4
- {typeid_python-0.2.1 → typeid_python-0.2.3}/pyproject.toml +2 -1
- {typeid_python-0.2.1 → typeid_python-0.2.3}/typeid/typeid.py +39 -4
- {typeid_python-0.2.1 → typeid_python-0.2.3}/LICENSE +0 -0
- {typeid_python-0.2.1 → typeid_python-0.2.3}/typeid/__init__.py +0 -0
- {typeid_python-0.2.1 → typeid_python-0.2.3}/typeid/base32.py +0 -0
- {typeid_python-0.2.1 → typeid_python-0.2.3}/typeid/cli.py +0 -0
- {typeid_python-0.2.1 → typeid_python-0.2.3}/typeid/constants.py +0 -0
- {typeid_python-0.2.1 → typeid_python-0.2.3}/typeid/errors.py +0 -0
- {typeid_python-0.2.1 → typeid_python-0.2.3}/typeid/validation.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: typeid-python
|
|
3
|
-
Version: 0.2.
|
|
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
|
|
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
|
|
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
|
```
|
|
@@ -59,9 +59,9 @@ This particular implementation provides an pip package that can be used by any P
|
|
|
59
59
|
- Create TypeID from string:
|
|
60
60
|
|
|
61
61
|
```python
|
|
62
|
-
from typeid import
|
|
62
|
+
from typeid import TypeID
|
|
63
63
|
|
|
64
|
-
typeid = from_string("user_01h45ytscbebyvny4gc8cr8ma2")
|
|
64
|
+
typeid = TypeID.from_string("user_01h45ytscbebyvny4gc8cr8ma2")
|
|
65
65
|
|
|
66
66
|
print(str(typeid)) # "user_01h45ytscbebyvny4gc8cr8ma2"
|
|
67
67
|
```
|
|
@@ -69,13 +69,13 @@ This particular implementation provides an pip package that can be used by any P
|
|
|
69
69
|
- Create TypeID from uuid7:
|
|
70
70
|
|
|
71
71
|
```python
|
|
72
|
-
from typeid import
|
|
72
|
+
from typeid import TypeID
|
|
73
73
|
from uuid6 import uuid7
|
|
74
74
|
|
|
75
75
|
uuid = uuid7() # UUID('01890bf0-846f-7762-8605-5a3abb40e0e5')
|
|
76
76
|
prefix = "user"
|
|
77
77
|
|
|
78
|
-
typeid = from_uuid(prefix=prefix, suffix=uuid)
|
|
78
|
+
typeid = TypeID.from_uuid(prefix=prefix, suffix=uuid)
|
|
79
79
|
|
|
80
80
|
print(str(typeid)) # "user_01h45z113fexh8c1at7axm1r75"
|
|
81
81
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "typeid-python"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.3"
|
|
4
4
|
description = "Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs"
|
|
5
5
|
authors = ["Murad Akhundov <akhundov1murad@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -13,6 +13,7 @@ classifiers = [
|
|
|
13
13
|
"Programming Language :: Python :: 3.9",
|
|
14
14
|
"Programming Language :: Python :: 3.10",
|
|
15
15
|
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
16
17
|
"Operating System :: OS Independent",
|
|
17
18
|
]
|
|
18
19
|
keywords = ["typeid", "uuid", "uuid6", "guid"]
|
|
@@ -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
|
-
|
|
44
|
-
return TypeID(
|
|
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
|
-
|
|
49
|
-
return TypeID(suffix=
|
|
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)))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|