ptars 0.0.1rc1__cp311-none-win32.whl → 0.0.2rc2__cp311-none-win32.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.
- ptars/_lib.cp311-win32.pyd +0 -0
- ptars/internal.py +29 -6
- {ptars-0.0.1rc1.dist-info → ptars-0.0.2rc2.dist-info}/METADATA +18 -7
- ptars-0.0.2rc2.dist-info/RECORD +7 -0
- {ptars-0.0.1rc1.dist-info → ptars-0.0.2rc2.dist-info}/WHEEL +1 -1
- ptars-0.0.1rc1.dist-info/RECORD +0 -7
- {ptars-0.0.1rc1.dist-info/license_files → ptars-0.0.2rc2.dist-info/licenses}/LICENSE +0 -0
ptars/_lib.cp311-win32.pyd
CHANGED
Binary file
|
ptars/internal.py
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
import warnings
|
2
|
+
|
3
|
+
import pyarrow as pa
|
4
|
+
from google._upb._message import Message, MessageMeta
|
1
5
|
from google.protobuf.descriptor import Descriptor, FileDescriptor
|
2
6
|
from google.protobuf.descriptor_pb2 import FileDescriptorProto
|
3
7
|
|
@@ -10,16 +14,21 @@ def _file_descriptor_to_bytes(fd: FileDescriptor) -> bytes:
|
|
10
14
|
return file_descriptor.SerializeToString()
|
11
15
|
|
12
16
|
|
13
|
-
def
|
17
|
+
def _get_dependencies(
|
14
18
|
file_descriptor: FileDescriptor, results: list[FileDescriptor] = None
|
15
19
|
) -> list[FileDescriptor]:
|
20
|
+
"""
|
21
|
+
Return list of FileDescriptor that this file depends on, including this one.
|
22
|
+
|
23
|
+
Results are in topological order (least dependent first).
|
24
|
+
"""
|
16
25
|
if results is None:
|
17
26
|
results = []
|
18
|
-
results.append(file_descriptor)
|
19
27
|
for dependency in file_descriptor.dependencies:
|
20
28
|
if dependency not in results:
|
21
|
-
|
22
|
-
|
29
|
+
_get_dependencies(dependency, results)
|
30
|
+
results.append(file_descriptor)
|
31
|
+
return results[::-1]
|
23
32
|
|
24
33
|
|
25
34
|
class HandlerPool:
|
@@ -28,16 +37,30 @@ class HandlerPool:
|
|
28
37
|
self._pool = {}
|
29
38
|
|
30
39
|
def get_for_message(self, descriptor: Descriptor) -> MessageHandler:
|
40
|
+
if isinstance(descriptor, MessageMeta):
|
41
|
+
warnings.warn(
|
42
|
+
f"Received {MessageMeta.__name__} instead of {Descriptor.__name__}"
|
43
|
+
)
|
44
|
+
descriptor = descriptor.DESCRIPTOR
|
45
|
+
if not isinstance(descriptor, Descriptor):
|
46
|
+
raise TypeError(f"Expecting {Descriptor.__name__}")
|
47
|
+
|
31
48
|
assert isinstance(descriptor, Descriptor)
|
32
49
|
try:
|
33
|
-
self._pool[descriptor.full_name]
|
50
|
+
return self._pool[descriptor.full_name]
|
34
51
|
except KeyError:
|
35
52
|
file_descriptor = descriptor.file
|
36
53
|
|
37
|
-
dependencies =
|
54
|
+
dependencies = _get_dependencies(file_descriptor)
|
38
55
|
payloads = [_file_descriptor_to_bytes(d) for d in dependencies]
|
39
56
|
message_handler = self._proto_cache.create_for_message(
|
40
57
|
"." + descriptor.full_name, payloads
|
41
58
|
)
|
42
59
|
self._pool[descriptor.full_name] = message_handler
|
43
60
|
return message_handler
|
61
|
+
|
62
|
+
def messages_to_record_batch(
|
63
|
+
self, messages: list[Message], descriptor: Descriptor
|
64
|
+
) -> pa.RecordBatch:
|
65
|
+
handler = self.get_for_message(descriptor)
|
66
|
+
return handler.list_to_record_batch([m.SerializeToString() for m in messages])
|
@@ -1,9 +1,14 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: ptars
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.2rc2
|
4
4
|
Classifier: Programming Language :: Rust
|
5
5
|
Classifier: Operating System :: POSIX :: Linux
|
6
|
+
Classifier: Natural Language :: English
|
7
|
+
Classifier: Programming Language :: Python :: 3.10
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
6
10
|
Requires-Dist: protobuf >3
|
11
|
+
Requires-Dist: pyarrow >15
|
7
12
|
License-File: LICENSE
|
8
13
|
Summary: Fast python conversion from protobuf to arrow using rust
|
9
14
|
Home-Page: https://github.com/0x26res/ptars
|
@@ -14,6 +19,8 @@ Requires-Python: >=3.8
|
|
14
19
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
15
20
|
Project-URL: Source Code, https://github.com/0x26res/ptars
|
16
21
|
|
22
|
+
# ptars
|
23
|
+
|
17
24
|
[![PyPI Version][pypi-image]][pypi-url]
|
18
25
|
[![Python Version][versions-image]][versions-url]
|
19
26
|
[![Github Stars][stars-image]][stars-url]
|
@@ -25,12 +32,8 @@ Project-URL: Source Code, https://github.com/0x26res/ptars
|
|
25
32
|
[![Code style: black][codestyle-image]][codestyle-url]
|
26
33
|
[![snyk][snyk-image]][snyk-url]
|
27
34
|
|
28
|
-
|
29
|
-
# ptars
|
30
|
-
|
31
35
|
Protobuf to Arrow, using Rust
|
32
36
|
|
33
|
-
|
34
37
|
## Example
|
35
38
|
|
36
39
|
Take a protobuf:
|
@@ -46,6 +49,9 @@ message SearchRequest {
|
|
46
49
|
And convert serialized messages directly to `pyarrow.RecordBatch`:
|
47
50
|
|
48
51
|
```python
|
52
|
+
from ptars import HandlerPool
|
53
|
+
|
54
|
+
|
49
55
|
messages = [
|
50
56
|
SearchRequest(
|
51
57
|
query="protobuf to arrow",
|
@@ -65,14 +71,19 @@ handler = pool.get_for_message(SearchRequest.DESCRIPTOR)
|
|
65
71
|
record_batch = handler.list_to_record_batch(payloads)
|
66
72
|
```
|
67
73
|
|
68
|
-
|
69
74
|
| query | page_number | result_per_page |
|
70
75
|
|:------------------|--------------:|------------------:|
|
71
76
|
| protobuf to arrow | 0 | 10 |
|
72
77
|
| protobuf to arrow | 1 | 10 |
|
73
78
|
|
79
|
+
You can also convert a `pyarrow.RecordBatch` back to serialized protobuf messages:
|
74
80
|
|
75
|
-
|
81
|
+
```python
|
82
|
+
array: pa.BinaryArray = handler.record_batch_to_array(record_batch)
|
83
|
+
messages_back: list[SearchRequest] = [
|
84
|
+
SearchRequest.FromString(s.as_py()) for s in array
|
85
|
+
]
|
86
|
+
```
|
76
87
|
|
77
88
|
[pypi-image]: https://img.shields.io/pypi/v/ptars
|
78
89
|
[pypi-url]: https://pypi.org/project/ptars/
|
@@ -0,0 +1,7 @@
|
|
1
|
+
ptars-0.0.2rc2.dist-info/METADATA,sha256=uHqhSI1o-n7EippAGjQN4O-x3NU12Twy6lBkJCncPnc,3764
|
2
|
+
ptars-0.0.2rc2.dist-info/WHEEL,sha256=6kWqen1S8CKCX4SrptZpM2ziEQyxctIyTkerFXXZTxU,91
|
3
|
+
ptars-0.0.2rc2.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
4
|
+
ptars/internal.py,sha256=u7ejNMNplBF3OsfqVyQ6wbAUor8fADnNt7avBJ44M6Q,2398
|
5
|
+
ptars/__init__.py,sha256=UjPOUn5TIGiA8Biu3AYjmjthZPdzTn72OIRvZYms5m0,69
|
6
|
+
ptars/_lib.cp311-win32.pyd,sha256=TptY59iMYpXy_RbnfnufRIvE1aLCiavkeqO9cD8XSyA,7102464
|
7
|
+
ptars-0.0.2rc2.dist-info/RECORD,,
|
ptars-0.0.1rc1.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
ptars-0.0.1rc1.dist-info/METADATA,sha256=7zvSNQPJahat8yG8HQUZwG8whdE3f-1ORaxRzeIRbpY,3249
|
2
|
-
ptars-0.0.1rc1.dist-info/WHEEL,sha256=QZenLo7OSmfwUW2c_Vk5qXEqXnDJnzKN3ugR5oy0OyI,91
|
3
|
-
ptars-0.0.1rc1.dist-info/license_files/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
4
|
-
ptars/internal.py,sha256=K3Uw_2Dv-pBfYwpSkD4vh5xf31kcBkRI1gcndC8NNIA,1511
|
5
|
-
ptars/__init__.py,sha256=UjPOUn5TIGiA8Biu3AYjmjthZPdzTn72OIRvZYms5m0,69
|
6
|
-
ptars/_lib.cp311-win32.pyd,sha256=BGflFAhK05b6gLnaItl5VV5ZqwIi-w-VGrWS_7spr34,6475264
|
7
|
-
ptars-0.0.1rc1.dist-info/RECORD,,
|
File without changes
|