ulid-transform 0.11.1__tar.gz → 0.12.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.
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/PKG-INFO +1 -1
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/pyproject.toml +1 -1
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/setup.py +1 -1
- ulid_transform-0.12.0/src/ulid_transform/__init__.py +38 -0
- ulid_transform-0.11.1/src/ulid_transform/ulid_impl.py → ulid_transform-0.12.0/src/ulid_transform/_py_ulid_impl.py +3 -32
- ulid_transform-0.12.0/src/ulid_transform/_ulid_impl.pyx +91 -0
- ulid_transform-0.11.1/src/ulid_transform/__init__.py +0 -25
- ulid_transform-0.11.1/src/ulid_transform/_ulid_impl.pyx +0 -46
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/LICENSE +0 -0
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/README.md +0 -0
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/build_ext.py +0 -0
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/src/ulid_transform/py.typed +0 -0
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/src/ulid_transform/ulid.hh +0 -0
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/src/ulid_transform/ulid_struct.hh +0 -0
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/src/ulid_transform/ulid_uint128.hh +0 -0
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/src/ulid_transform/ulid_wrapper.cpp +0 -0
- {ulid_transform-0.11.1 → ulid_transform-0.12.0}/src/ulid_transform/ulid_wrapper.h +0 -0
@@ -12,7 +12,7 @@ package_data = \
|
|
12
12
|
|
13
13
|
setup_kwargs = {
|
14
14
|
'name': 'ulid-transform',
|
15
|
-
'version': '0.
|
15
|
+
'version': '0.12.0',
|
16
16
|
'description': 'Create and transform ULIDs',
|
17
17
|
'long_description': '# Fast ULID transformations\n\n<p align="center">\n <a href="https://github.com/bdraco/ulid-transform/actions/workflows/ci.yml?query=branch%3Amain">\n <img src="https://img.shields.io/github/actions/workflow/status/bdraco/ulid-transform/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >\n </a>\n <a href="https://codecov.io/gh/bdraco/ulid-transform">\n <img src="https://img.shields.io/codecov/c/github/bdraco/ulid-transform.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">\n </a>\n</p>\n<p align="center">\n <a href="https://python-poetry.org/">\n <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=" alt="Poetry">\n </a>\n <a href="https://github.com/ambv/black">\n <img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square" alt="black">\n </a>\n <a href="https://github.com/pre-commit/pre-commit">\n <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">\n </a>\n</p>\n<p align="center">\n <a href="https://pypi.org/project/ulid-transform/">\n <img src="https://img.shields.io/pypi/v/ulid-transform.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">\n </a>\n <img src="https://img.shields.io/pypi/pyversions/ulid-transform.svg?style=flat-square&logo=python&logoColor=fff" alt="Supported Python versions">\n <img src="https://img.shields.io/pypi/l/ulid-transform.svg?style=flat-square" alt="License">\n</p>\n\nCreate and transform ULIDs\n\nThis library will use the CPP implementation from https://github.com/suyash/ulid if cython is available, and will fallback to pure python if it is not.\n\n## Example\n\n```python\n>>> import ulid_transform\n>>> ulid_transform.ulid_hex()\n\'01869a2ea5fb0b43aa056293e47c0a35\'\n>>> ulid_transform.ulid_now()\n\'0001HZX0NW00GW0X476W5TVBFE\'\n>>> ulid_transform.ulid_at_time(1234)\n\'000000016JC62D620DGYNG2R8H\'\n>>> ulid_transform.ulid_to_bytes(\'0001HZX0NW00GW0X476W5TVBFE\')\nb\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\'\n>> ulid_transform.bytes_to_ulid(b"\\x01\\x86\\x99?\\xe8\\xf3\\x11\\xbc\\xed\\xef\\x86U.9\\x03z")\n\'01GTCKZT7K26YEVVW6AMQ3J0VT\'\n>>> ulid_transform.ulid_to_bytes_or_none(\'0001HZX0NW00GW0X476W5TVBFE\')\nb\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\'\n>>> ulid_transform.ulid_to_bytes_or_none(None)\n>>> ulid_transform.bytes_to_ulid_or_none(b\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\')\n\'0001HZX0NW00GW0X476W5TVBFE\'\n>>> ulid_transform.bytes_to_ulid_or_none(None)\n```\n\n## Installation\n\nInstall this via pip (or your favourite package manager):\n\n`pip install ulid-transform`\n\n## Contributors ✨\n\nThanks to https://github.com/suyash/ulid which provides the cython implementation guts.\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- prettier-ignore-start -->\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- markdownlint-disable -->\n<!-- markdownlint-enable -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n<!-- prettier-ignore-end -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## Credits\n\nThis package was created with\n[Copier](https://copier.readthedocs.io/) and the\n[browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)\nproject template.\n',
|
18
18
|
'author': 'J. Nick Koston',
|
@@ -0,0 +1,38 @@
|
|
1
|
+
__version__ = "0.12.0"
|
2
|
+
|
3
|
+
try:
|
4
|
+
from ._ulid_impl import (
|
5
|
+
bytes_to_ulid,
|
6
|
+
bytes_to_ulid_or_none,
|
7
|
+
ulid_at_time,
|
8
|
+
ulid_at_time_bytes,
|
9
|
+
ulid_hex,
|
10
|
+
ulid_now,
|
11
|
+
ulid_now_bytes,
|
12
|
+
ulid_to_bytes,
|
13
|
+
ulid_to_bytes_or_none,
|
14
|
+
)
|
15
|
+
except ImportError:
|
16
|
+
from ._py_ulid_impl import (
|
17
|
+
bytes_to_ulid,
|
18
|
+
bytes_to_ulid_or_none,
|
19
|
+
ulid_at_time,
|
20
|
+
ulid_at_time_bytes,
|
21
|
+
ulid_hex,
|
22
|
+
ulid_now,
|
23
|
+
ulid_now_bytes,
|
24
|
+
ulid_to_bytes,
|
25
|
+
ulid_to_bytes_or_none,
|
26
|
+
)
|
27
|
+
|
28
|
+
__all__ = [
|
29
|
+
"bytes_to_ulid",
|
30
|
+
"bytes_to_ulid_or_none",
|
31
|
+
"ulid_at_time",
|
32
|
+
"ulid_at_time_bytes",
|
33
|
+
"ulid_hex",
|
34
|
+
"ulid_now",
|
35
|
+
"ulid_now_bytes",
|
36
|
+
"ulid_to_bytes",
|
37
|
+
"ulid_to_bytes_or_none",
|
38
|
+
]
|
@@ -432,40 +432,11 @@ def ulid_to_bytes_or_none(ulid: str | None) -> bytes | None:
|
|
432
432
|
return None
|
433
433
|
|
434
434
|
|
435
|
-
def bytes_to_ulid_or_none(
|
435
|
+
def bytes_to_ulid_or_none(ulid_bytes: bytes | None) -> str | None:
|
436
436
|
"""Convert bytes to a ulid."""
|
437
|
-
if
|
437
|
+
if ulid_bytes is None:
|
438
438
|
return None
|
439
439
|
try:
|
440
|
-
return bytes_to_ulid(
|
440
|
+
return bytes_to_ulid(ulid_bytes)
|
441
441
|
except ValueError:
|
442
442
|
return None
|
443
|
-
|
444
|
-
|
445
|
-
try:
|
446
|
-
from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
|
447
|
-
_bytes_to_ulid as bytes_to_ulid,
|
448
|
-
)
|
449
|
-
from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
|
450
|
-
_bytes_to_ulid_or_none as bytes_to_ulid_or_none,
|
451
|
-
)
|
452
|
-
from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
|
453
|
-
_ulid_at_time as ulid_at_time,
|
454
|
-
)
|
455
|
-
from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
|
456
|
-
_ulid_at_time_bytes as ulid_at_time_bytes,
|
457
|
-
)
|
458
|
-
from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
|
459
|
-
_ulid_now as ulid_now,
|
460
|
-
)
|
461
|
-
from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
|
462
|
-
_ulid_now_bytes as ulid_now_bytes,
|
463
|
-
)
|
464
|
-
from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
|
465
|
-
_ulid_to_bytes as ulid_to_bytes,
|
466
|
-
)
|
467
|
-
from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
|
468
|
-
_ulid_to_bytes_or_none as ulid_to_bytes_or_none,
|
469
|
-
)
|
470
|
-
except ImportError: # pragma: no cover
|
471
|
-
pass # pragma: no cover
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# distutils: language = c++
|
2
|
+
from libcpp.string cimport string
|
3
|
+
from libcpp.vector cimport vector
|
4
|
+
|
5
|
+
|
6
|
+
cdef extern from "ulid_wrapper.h":
|
7
|
+
string _cpp_ulid_at_time(double timestamp)
|
8
|
+
vector[unsigned char] _cpp_ulid_at_time_bytes(double timestamp)
|
9
|
+
string _cpp_ulid_to_bytes(const char * ulid_string)
|
10
|
+
string _cpp_ulid()
|
11
|
+
vector[unsigned char] _cpp_ulid_bytes()
|
12
|
+
string _cpp_bytes_to_ulid(string ulid_bytes)
|
13
|
+
|
14
|
+
|
15
|
+
def ulid_hex() -> str:
|
16
|
+
"""Generate a ULID in lowercase hex that will work for a UUID.
|
17
|
+
|
18
|
+
This ulid should not be used for cryptographically secure
|
19
|
+
operations.
|
20
|
+
|
21
|
+
This string can be converted with https://github.com/ahawker/ulid
|
22
|
+
|
23
|
+
ulid.from_uuid(uuid.UUID(ulid_hex))
|
24
|
+
"""
|
25
|
+
return bytes(_cpp_ulid_bytes()).hex()
|
26
|
+
|
27
|
+
|
28
|
+
def ulid_now_bytes() -> bytes:
|
29
|
+
"""Generate an ULID as 16 bytes that will work for a UUID."""
|
30
|
+
return bytes(_cpp_ulid_bytes())
|
31
|
+
|
32
|
+
|
33
|
+
def ulid_at_time_bytes(timestamp: float) -> bytes:
|
34
|
+
"""Generate an ULID as 16 bytes that will work for a UUID.
|
35
|
+
|
36
|
+
uuid.UUID(bytes=ulid_bytes)
|
37
|
+
"""
|
38
|
+
return bytes(_cpp_ulid_at_time_bytes(timestamp))
|
39
|
+
|
40
|
+
|
41
|
+
def ulid_now() -> str:
|
42
|
+
"""Generate a ULID."""
|
43
|
+
return _cpp_ulid().decode("ascii")
|
44
|
+
|
45
|
+
|
46
|
+
def ulid_at_time(timestamp: float) -> str:
|
47
|
+
"""Generate a ULID.
|
48
|
+
|
49
|
+
This ulid should not be used for cryptographically secure
|
50
|
+
operations.
|
51
|
+
|
52
|
+
01AN4Z07BY 79KA1307SR9X4MV3
|
53
|
+
|----------| |----------------|
|
54
|
+
Timestamp Randomness
|
55
|
+
48bits 80bits
|
56
|
+
|
57
|
+
This string can be loaded directly with https://github.com/ahawker/ulid
|
58
|
+
|
59
|
+
import ulid_transform as ulid_util
|
60
|
+
import ulid
|
61
|
+
ulid.parse(ulid_util.ulid())
|
62
|
+
"""
|
63
|
+
return _cpp_ulid_at_time(timestamp).decode("ascii")
|
64
|
+
|
65
|
+
|
66
|
+
def ulid_to_bytes(value: str) -> bytes:
|
67
|
+
"""Decode a ulid to bytes."""
|
68
|
+
if len(value) != 26:
|
69
|
+
raise ValueError(f"ULID must be a 26 character string: {value}")
|
70
|
+
return _cpp_ulid_to_bytes(value.encode("ascii"))
|
71
|
+
|
72
|
+
|
73
|
+
def bytes_to_ulid(value: bytes) -> str:
|
74
|
+
"""Encode bytes to a ulid."""
|
75
|
+
if len(value) != 16:
|
76
|
+
raise ValueError(f"ULID bytes must be 16 bytes: {value!r}")
|
77
|
+
return _cpp_bytes_to_ulid(value).decode("ascii")
|
78
|
+
|
79
|
+
|
80
|
+
def ulid_to_bytes_or_none(ulid: str | None) -> bytes | None:
|
81
|
+
"""Convert an ulid to bytes."""
|
82
|
+
if ulid is None or len(ulid) != 26:
|
83
|
+
return None
|
84
|
+
return _cpp_ulid_to_bytes(ulid.encode("ascii"))
|
85
|
+
|
86
|
+
|
87
|
+
def bytes_to_ulid_or_none(ulid_bytes: bytes | None) -> str | None:
|
88
|
+
"""Convert bytes to a ulid."""
|
89
|
+
if ulid_bytes is None or len(ulid_bytes) != 16:
|
90
|
+
return None
|
91
|
+
return _cpp_bytes_to_ulid(ulid_bytes).decode("ascii")
|
@@ -1,25 +0,0 @@
|
|
1
|
-
__version__ = "0.11.1"
|
2
|
-
|
3
|
-
from .ulid_impl import (
|
4
|
-
bytes_to_ulid,
|
5
|
-
bytes_to_ulid_or_none,
|
6
|
-
ulid_at_time,
|
7
|
-
ulid_at_time_bytes,
|
8
|
-
ulid_hex,
|
9
|
-
ulid_now,
|
10
|
-
ulid_now_bytes,
|
11
|
-
ulid_to_bytes,
|
12
|
-
ulid_to_bytes_or_none,
|
13
|
-
)
|
14
|
-
|
15
|
-
__all__ = [
|
16
|
-
"bytes_to_ulid",
|
17
|
-
"bytes_to_ulid_or_none",
|
18
|
-
"ulid_at_time",
|
19
|
-
"ulid_at_time_bytes",
|
20
|
-
"ulid_hex",
|
21
|
-
"ulid_now",
|
22
|
-
"ulid_now_bytes",
|
23
|
-
"ulid_to_bytes",
|
24
|
-
"ulid_to_bytes_or_none",
|
25
|
-
]
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# distutils: language = c++
|
2
|
-
from libcpp.string cimport string
|
3
|
-
from libcpp.vector cimport vector
|
4
|
-
|
5
|
-
from typing import Optional
|
6
|
-
|
7
|
-
|
8
|
-
cdef extern from "ulid_wrapper.h":
|
9
|
-
string _cpp_ulid_at_time(double timestamp)
|
10
|
-
vector[unsigned char] _cpp_ulid_at_time_bytes(double timestamp)
|
11
|
-
string _cpp_ulid_to_bytes(const char * ulid_string)
|
12
|
-
string _cpp_ulid()
|
13
|
-
vector[unsigned char] _cpp_ulid_bytes()
|
14
|
-
string _cpp_bytes_to_ulid(string ulid_bytes)
|
15
|
-
|
16
|
-
def _ulid_now_bytes() -> bytes:
|
17
|
-
return bytes(_cpp_ulid_bytes())
|
18
|
-
|
19
|
-
def _ulid_at_time_bytes(_time: float) -> bytes:
|
20
|
-
return bytes(_cpp_ulid_at_time_bytes(_time))
|
21
|
-
|
22
|
-
def _ulid_now() -> str:
|
23
|
-
return _cpp_ulid().decode("ascii")
|
24
|
-
|
25
|
-
def _ulid_at_time(_time: float) -> str:
|
26
|
-
return _cpp_ulid_at_time(_time).decode("ascii")
|
27
|
-
|
28
|
-
def _ulid_to_bytes(ulid_str: str) -> bytes:
|
29
|
-
if len(ulid_str) != 26:
|
30
|
-
raise ValueError(f"ULID must be a 26 character string: {ulid_str}")
|
31
|
-
return _cpp_ulid_to_bytes(ulid_str.encode("ascii"))
|
32
|
-
|
33
|
-
def _bytes_to_ulid(ulid_bytes: bytes) -> str:
|
34
|
-
if len(ulid_bytes) != 16:
|
35
|
-
raise ValueError(f"ULID bytes must be 16 bytes: {ulid_bytes!r}")
|
36
|
-
return _cpp_bytes_to_ulid(ulid_bytes).decode("ascii")
|
37
|
-
|
38
|
-
def _ulid_to_bytes_or_none(ulid_str: Optional[str]) -> Optional[bytes]:
|
39
|
-
if ulid_str is None or len(ulid_str) != 26:
|
40
|
-
return None
|
41
|
-
return _cpp_ulid_to_bytes(ulid_str.encode("ascii"))
|
42
|
-
|
43
|
-
def _bytes_to_ulid_or_none(ulid_bytes: Optional[bytes]) -> Optional[str]:
|
44
|
-
if ulid_bytes is None or len(ulid_bytes) != 16:
|
45
|
-
return None
|
46
|
-
return _cpp_bytes_to_ulid(ulid_bytes).decode("ascii")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|