ulid-transform 0.2.1__tar.gz → 0.3.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ulid-transform
3
- Version: 0.2.1
3
+ Version: 0.3.1
4
4
  Summary: Create and transform ULIDs
5
5
  Home-page: https://github.com/bdraco/ulid-transform
6
6
  License: MIT
@@ -52,6 +52,22 @@ Description-Content-Type: text/markdown
52
52
 
53
53
  Create and transform ULIDs
54
54
 
55
+ This 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.
56
+
57
+ ## Example
58
+
59
+ ```python
60
+ >>> import ulid_transform
61
+ >>> ulid_transform.ulid_hex()
62
+ '01869a2ea5fb0b43aa056293e47c0a35'
63
+ >>> ulid_transform.ulid_now()
64
+ '0001HZX0NW00GW0X476W5TVBFE'
65
+ >>> ulid_transform.ulid_at_time(1234)
66
+ '000000016JC62D620DGYNG2R8H'
67
+ >>> ulid_transform.ulid_to_bytes('0001HZX0NW00GW0X476W5TVBFE')
68
+ b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'
69
+ ```
70
+
55
71
  ## Installation
56
72
 
57
73
  Install this via pip (or your favourite package manager):
@@ -29,6 +29,22 @@
29
29
 
30
30
  Create and transform ULIDs
31
31
 
32
+ This 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.
33
+
34
+ ## Example
35
+
36
+ ```python
37
+ >>> import ulid_transform
38
+ >>> ulid_transform.ulid_hex()
39
+ '01869a2ea5fb0b43aa056293e47c0a35'
40
+ >>> ulid_transform.ulid_now()
41
+ '0001HZX0NW00GW0X476W5TVBFE'
42
+ >>> ulid_transform.ulid_at_time(1234)
43
+ '000000016JC62D620DGYNG2R8H'
44
+ >>> ulid_transform.ulid_to_bytes('0001HZX0NW00GW0X476W5TVBFE')
45
+ b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'
46
+ ```
47
+
32
48
  ## Installation
33
49
 
34
50
  Install this via pip (or your favourite package manager):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ulid-transform"
3
- version = "0.2.1"
3
+ version = "0.3.1"
4
4
  description = "Create and transform ULIDs"
5
5
  authors = ["J. Nick Koston <nick@koston.org>"]
6
6
  license = "MIT"
@@ -31,6 +31,8 @@ python = "^3.10"
31
31
  [tool.poetry.group.dev.dependencies]
32
32
  pytest = "^7.0"
33
33
  pytest-cov = "^3.0"
34
+ Cython = "^0.29.32"
35
+ setuptools = "^65.4.1"
34
36
 
35
37
  [tool.semantic_release]
36
38
  branch = "main"
@@ -12,9 +12,9 @@ package_data = \
12
12
 
13
13
  setup_kwargs = {
14
14
  'name': 'ulid-transform',
15
- 'version': '0.2.1',
15
+ 'version': '0.3.1',
16
16
  'description': 'Create and transform ULIDs',
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&amp;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\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',
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&amp;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```\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',
19
19
  'author_email': 'nick@koston.org',
20
20
  'maintainer': 'None',
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.1"
1
+ __version__ = "0.3.1"
2
2
 
3
3
  from .ulid_impl import ulid_at_time, ulid_hex, ulid_now, ulid_to_bytes
4
4
 
@@ -17,4 +17,6 @@ def _ulid_at_time(time: float) -> str:
17
17
  return _cpp_ulid_at_time(time).decode("ascii")
18
18
 
19
19
  def _ulid_to_bytes(ulid_str: str) -> bytes:
20
+ if len(ulid_str) != 26:
21
+ raise ValueError("ULID must be 26 characters")
20
22
  return _cpp_ulid_to_bytes(ulid_str.encode("ascii"))
@@ -4,7 +4,7 @@ from time import time
4
4
 
5
5
  # From https://github.com/ahawker/ulid/blob/06289583e9de4286b4d80b4ad000d137816502ca/ulid/base32.py#L102
6
6
  #: Array that maps encoded string char byte values to enable O(1) lookups.
7
- DECODE = array.array(
7
+ _DECODE = array.array(
8
8
  "B",
9
9
  (
10
10
  0xFF,
@@ -347,7 +347,7 @@ def ulid_to_bytes(value: str) -> bytes:
347
347
  if len(value) != 26:
348
348
  raise ValueError("ULID must be 26 characters")
349
349
  encoded = value.encode("ascii")
350
- decoding = DECODE
350
+ decoding = _DECODE
351
351
  return bytes(
352
352
  (
353
353
  ((decoding[encoded[0]] << 5) | decoding[encoded[1]]) & 0xFF,
@@ -0,0 +1,25 @@
1
+ #include "ulid_wrapper.h"
2
+ #include "ulid.hh"
3
+
4
+ using namespace std;
5
+
6
+ std::string _cpp_ulid() {
7
+ ulid::ULID ulid;
8
+ ulid::EncodeNowRand(ulid);
9
+ return ulid::Marshal(ulid);
10
+ }
11
+
12
+ std::string _cpp_ulid_at_time(double epoch_time) {
13
+ time_t encoded_time = static_cast<time_t>(epoch_time*1000);
14
+ ulid::ULID ulid;
15
+ ulid::EncodeTime(encoded_time, ulid);
16
+ ulid::EncodeEntropyRand(ulid);
17
+ return ulid::Marshal(ulid);
18
+ }
19
+
20
+ std::string _cpp_ulid_to_bytes(std::string ulid_string) {
21
+ ulid::ULID ulid = ulid::Unmarshal(ulid_string.c_str());
22
+ std::vector<uint8_t> data = ulid::MarshalBinary(ulid);
23
+ std::string str(reinterpret_cast<char *>(data.data()), data.size());
24
+ return str;
25
+ }
@@ -1,27 +0,0 @@
1
- #include "ulid.hh"
2
- #include "ulid_wrapper.h"
3
- #include <chrono>
4
-
5
- using namespace std;
6
-
7
-
8
- std::string _cpp_ulid() {
9
- ulid::ULID ulid;
10
- ulid::EncodeNowRand(ulid);
11
- return ulid::Marshal(ulid);
12
- }
13
-
14
- std::string _cpp_ulid_at_time(double timestamp) {
15
- const auto encoded_time = chrono::system_clock::to_time_t(chrono::system_clock::time_point(chrono::duration_cast<chrono::seconds>(chrono::duration<double>(timestamp))));
16
- ulid::ULID ulid;
17
- ulid::EncodeTime(encoded_time, ulid);
18
- ulid::EncodeEntropyRand(ulid);
19
- return ulid::Marshal(ulid);
20
- }
21
-
22
- std::string _cpp_ulid_to_bytes(std::string ulid_string) {
23
- ulid::ULID ulid = ulid::Unmarshal(ulid_string.c_str());
24
- std::vector<uint8_t> data = ulid::MarshalBinary(ulid);
25
- std::string str(reinterpret_cast<char*>(data.data()), data.size());
26
- return str;
27
- }
File without changes