typeid-python 0.2.2__tar.gz → 0.3.0__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.2 → typeid_python-0.3.0}/PKG-INFO +2 -1
- {typeid_python-0.2.2 → typeid_python-0.3.0}/pyproject.toml +2 -1
- {typeid_python-0.2.2 → typeid_python-0.3.0}/typeid/typeid.py +27 -13
- {typeid_python-0.2.2 → typeid_python-0.3.0}/typeid/validation.py +5 -2
- {typeid_python-0.2.2 → typeid_python-0.3.0}/LICENSE +0 -0
- {typeid_python-0.2.2 → typeid_python-0.3.0}/README.md +0 -0
- {typeid_python-0.2.2 → typeid_python-0.3.0}/typeid/__init__.py +0 -0
- {typeid_python-0.2.2 → typeid_python-0.3.0}/typeid/base32.py +0 -0
- {typeid_python-0.2.2 → typeid_python-0.3.0}/typeid/cli.py +0 -0
- {typeid_python-0.2.2 → typeid_python-0.3.0}/typeid/constants.py +0 -0
- {typeid_python-0.2.2 → typeid_python-0.3.0}/typeid/errors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: typeid-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "typeid-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
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,7 +1,7 @@
|
|
|
1
|
+
import warnings
|
|
1
2
|
from typing import Optional
|
|
2
|
-
from uuid import UUID
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import uuid6
|
|
5
5
|
|
|
6
6
|
from typeid import base32
|
|
7
7
|
from typeid.errors import InvalidTypeIDStringException
|
|
@@ -10,7 +10,7 @@ from typeid.validation import validate_prefix, validate_suffix
|
|
|
10
10
|
|
|
11
11
|
class TypeID:
|
|
12
12
|
def __init__(self, prefix: Optional[str] = None, suffix: Optional[str] = None) -> None:
|
|
13
|
-
suffix = _convert_uuid_to_b32(uuid7()) if not suffix else suffix
|
|
13
|
+
suffix = _convert_uuid_to_b32(uuid6.uuid7()) if not suffix else suffix
|
|
14
14
|
validate_suffix(suffix=suffix)
|
|
15
15
|
if prefix:
|
|
16
16
|
validate_prefix(prefix=prefix)
|
|
@@ -24,9 +24,9 @@ class TypeID:
|
|
|
24
24
|
return cls(suffix=suffix, prefix=prefix)
|
|
25
25
|
|
|
26
26
|
@classmethod
|
|
27
|
-
def from_uuid(cls, suffix: UUID, prefix: Optional[str] = None):
|
|
27
|
+
def from_uuid(cls, suffix: uuid6.UUID, prefix: Optional[str] = None):
|
|
28
28
|
suffix_str = _convert_uuid_to_b32(suffix)
|
|
29
|
-
return
|
|
29
|
+
return cls(suffix=suffix_str, prefix=prefix)
|
|
30
30
|
|
|
31
31
|
@property
|
|
32
32
|
def suffix(self) -> str:
|
|
@@ -37,7 +37,7 @@ class TypeID:
|
|
|
37
37
|
return self._prefix
|
|
38
38
|
|
|
39
39
|
@property
|
|
40
|
-
def uuid(self) -> UUID:
|
|
40
|
+
def uuid(self) -> uuid6.UUID:
|
|
41
41
|
return _convert_b32_to_uuid(self.suffix)
|
|
42
42
|
|
|
43
43
|
def __str__(self) -> str:
|
|
@@ -47,28 +47,40 @@ class TypeID:
|
|
|
47
47
|
value += self.suffix
|
|
48
48
|
return value
|
|
49
49
|
|
|
50
|
+
def __repr__(self):
|
|
51
|
+
return "%s(%r)" % (self.__class__.__name__, str(self))
|
|
52
|
+
|
|
50
53
|
def __eq__(self, value: object) -> bool:
|
|
51
54
|
if not isinstance(value, TypeID):
|
|
52
55
|
return False
|
|
53
56
|
return value.prefix == self.prefix and value.suffix == self.suffix
|
|
54
57
|
|
|
58
|
+
def __gt__(self, other):
|
|
59
|
+
if isinstance(other, TypeID):
|
|
60
|
+
return str(self) > str(other)
|
|
61
|
+
return NotImplemented
|
|
62
|
+
|
|
63
|
+
def __ge__(self, other):
|
|
64
|
+
if isinstance(other, TypeID):
|
|
65
|
+
return str(self) >= str(other)
|
|
66
|
+
return NotImplemented
|
|
67
|
+
|
|
55
68
|
def __hash__(self) -> int:
|
|
56
69
|
return hash((self.prefix, self.suffix))
|
|
57
70
|
|
|
58
71
|
|
|
59
72
|
def from_string(string: str) -> TypeID:
|
|
60
|
-
"
|
|
73
|
+
warnings.warn("Consider TypeID.from_string instead.", DeprecationWarning)
|
|
61
74
|
return TypeID.from_string(string=string)
|
|
62
75
|
|
|
63
76
|
|
|
64
|
-
def from_uuid(suffix: UUID, prefix: Optional[str] = None) -> TypeID:
|
|
65
|
-
"
|
|
77
|
+
def from_uuid(suffix: uuid6.UUID, prefix: Optional[str] = None) -> TypeID:
|
|
78
|
+
warnings.warn("Consider TypeID.from_uuid instead.", DeprecationWarning)
|
|
66
79
|
return TypeID.from_uuid(suffix=suffix, prefix=prefix)
|
|
67
80
|
|
|
68
81
|
|
|
69
82
|
def get_prefix_and_suffix(string: str) -> tuple:
|
|
70
83
|
parts = string.split("_")
|
|
71
|
-
suffix = None
|
|
72
84
|
prefix = None
|
|
73
85
|
if len(parts) == 1:
|
|
74
86
|
suffix = parts[0]
|
|
@@ -81,9 +93,11 @@ def get_prefix_and_suffix(string: str) -> tuple:
|
|
|
81
93
|
return prefix, suffix
|
|
82
94
|
|
|
83
95
|
|
|
84
|
-
def _convert_uuid_to_b32(uuid_instance: UUID) -> str:
|
|
96
|
+
def _convert_uuid_to_b32(uuid_instance: uuid6.UUID) -> str:
|
|
85
97
|
return base32.encode(list(uuid_instance.bytes))
|
|
86
98
|
|
|
87
99
|
|
|
88
|
-
def _convert_b32_to_uuid(b32: str) -> UUID:
|
|
89
|
-
|
|
100
|
+
def _convert_b32_to_uuid(b32: str) -> uuid6.UUID:
|
|
101
|
+
uuid_bytes = bytes(base32.decode(b32))
|
|
102
|
+
uuid_int = int.from_bytes(uuid_bytes, byteorder="big")
|
|
103
|
+
return uuid6.UUID(int=uuid_int, version=7)
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
1
3
|
from typeid import base32
|
|
2
|
-
from typeid.constants import
|
|
4
|
+
from typeid.constants import SUFFIX_LEN
|
|
3
5
|
from typeid.errors import PrefixValidationException, SuffixValidationException
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
def validate_prefix(prefix: str) -> None:
|
|
7
|
-
|
|
9
|
+
# See https://github.com/jetify-com/typeid/tree/main/spec
|
|
10
|
+
if not re.match("^([a-z]([a-z_]{0,61}[a-z])?)?$", prefix):
|
|
8
11
|
raise PrefixValidationException(f"Invalid prefix: {prefix}.")
|
|
9
12
|
|
|
10
13
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|