turbodata 0.1.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.
- turbodata-0.1.0/LICENSE +201 -0
- turbodata-0.1.0/NOTICE +27 -0
- turbodata-0.1.0/PKG-INFO +361 -0
- turbodata-0.1.0/README.md +336 -0
- turbodata-0.1.0/pyproject.toml +36 -0
- turbodata-0.1.0/setup.cfg +4 -0
- turbodata-0.1.0/tests/test_codec.py +342 -0
- turbodata-0.1.0/tests/test_compress.py +69 -0
- turbodata-0.1.0/tests/test_cost_aware.py +250 -0
- turbodata-0.1.0/tests/test_cross_language.py +154 -0
- turbodata-0.1.0/tests/test_iorange.py +290 -0
- turbodata-0.1.0/tests/test_iterator.py +252 -0
- turbodata-0.1.0/tests/test_multi_reader.py +314 -0
- turbodata-0.1.0/tests/test_reader.py +214 -0
- turbodata-0.1.0/tests/test_remap.py +122 -0
- turbodata-0.1.0/tests/test_sample.py +331 -0
- turbodata-0.1.0/tests/test_source.py +135 -0
- turbodata-0.1.0/tests/test_strategy.py +94 -0
- turbodata-0.1.0/tests/test_video.py +520 -0
- turbodata-0.1.0/tests/test_writer.py +391 -0
- turbodata-0.1.0/turbodata/__init__.py +151 -0
- turbodata-0.1.0/turbodata/_codec.py +354 -0
- turbodata-0.1.0/turbodata/_compress.py +42 -0
- turbodata-0.1.0/turbodata/_iorange.py +205 -0
- turbodata-0.1.0/turbodata/_iter.py +348 -0
- turbodata-0.1.0/turbodata/_sample.py +503 -0
- turbodata-0.1.0/turbodata/chunk.py +39 -0
- turbodata-0.1.0/turbodata/errors.py +143 -0
- turbodata-0.1.0/turbodata/multi_reader.py +249 -0
- turbodata-0.1.0/turbodata/reader.py +643 -0
- turbodata-0.1.0/turbodata/source.py +140 -0
- turbodata-0.1.0/turbodata/strategy.py +87 -0
- turbodata-0.1.0/turbodata/writer.py +476 -0
- turbodata-0.1.0/turbodata.egg-info/PKG-INFO +361 -0
- turbodata-0.1.0/turbodata.egg-info/SOURCES.txt +36 -0
- turbodata-0.1.0/turbodata.egg-info/dependency_links.txt +1 -0
- turbodata-0.1.0/turbodata.egg-info/requires.txt +5 -0
- turbodata-0.1.0/turbodata.egg-info/top_level.txt +1 -0
turbodata-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one of
|
|
111
|
+
the following places: within a NOTICE text file distributed as
|
|
112
|
+
part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Wanjia He
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
turbodata-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
turbodata
|
|
2
|
+
Copyright 2026 Wanjia He
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Wanjia He and the turbodata
|
|
5
|
+
contributors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (see the LICENSE file).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
This software depends on third-party packages that are downloaded at build
|
|
12
|
+
time and are not redistributed as part of this source tree. Each remains
|
|
13
|
+
under its own license. Notable dependencies include:
|
|
14
|
+
|
|
15
|
+
Go SDK (go/):
|
|
16
|
+
- github.com/foxglove/mcap/go/mcap (MIT)
|
|
17
|
+
- github.com/klauspost/compress (BSD-3-Clause / Apache-2.0 / MIT)
|
|
18
|
+
- github.com/vmihailenco/msgpack/v5 (BSD-2-Clause)
|
|
19
|
+
- github.com/google/go-cmp (BSD-3-Clause)
|
|
20
|
+
|
|
21
|
+
Python SDK (py/):
|
|
22
|
+
- msgpack (Apache-2.0)
|
|
23
|
+
- zstandard (BSD-3-Clause)
|
|
24
|
+
|
|
25
|
+
TypeScript SDK (ts/):
|
|
26
|
+
- @msgpack/msgpack (ISC)
|
|
27
|
+
- fzstd (MIT)
|
turbodata-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: turbodata
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the turbodata (.td) container format. Read/write port of the Go reference implementation.
|
|
5
|
+
Author: Wanjia He
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/opheadacheh/turbodata
|
|
8
|
+
Project-URL: Repository, https://github.com/opheadacheh/turbodata
|
|
9
|
+
Project-URL: Issues, https://github.com/opheadacheh/turbodata/issues
|
|
10
|
+
Keywords: turbodata,container-format,timeseries,robotics,mcap,msgpack,zstd
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
License-File: NOTICE
|
|
20
|
+
Requires-Dist: msgpack>=1.0.5
|
|
21
|
+
Requires-Dist: zstandard>=0.22.0
|
|
22
|
+
Provides-Extra: test
|
|
23
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# turbodata (Python)
|
|
27
|
+
|
|
28
|
+
Python SDK for the turbodata `.td` container format. Read/write port of the
|
|
29
|
+
Go reference implementation in `../go`. The on-disk format is identical, so
|
|
30
|
+
files written by any SDK can be read by any other.
|
|
31
|
+
|
|
32
|
+
Built so model developers can directly manipulate `.td` files (read training
|
|
33
|
+
data, write preprocessed shards, sample at specific timestamps for multi-topic
|
|
34
|
+
alignment).
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install turbodata # or, for local dev: pip install -e ".[test]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Dependencies: `msgpack`, `zstandard`. See the
|
|
41
|
+
[top-level README](../README.md) for scope and the format overview. This guide
|
|
42
|
+
is API usage by feature: **write → read → sample → multi-file**. Runnable
|
|
43
|
+
versions of every snippet live in [`examples/`](./examples).
|
|
44
|
+
|
|
45
|
+
## Write
|
|
46
|
+
|
|
47
|
+
Open one or more topics as a group, append messages with non-decreasing
|
|
48
|
+
timestamps, then close the topic group. The `Writer` context manager finalizes
|
|
49
|
+
the file on exit.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from turbodata import Writer
|
|
53
|
+
|
|
54
|
+
with open("out.td", "wb") as f, Writer(f) as w:
|
|
55
|
+
w.open_topics(
|
|
56
|
+
["/imu", "/cam"],
|
|
57
|
+
[{"hz": 100}, {"hz": 10}],
|
|
58
|
+
compression=True,
|
|
59
|
+
)
|
|
60
|
+
w.write_message("/imu", b"...", timestamp=1_000)
|
|
61
|
+
w.write_message("/cam", b"...", timestamp=2_000)
|
|
62
|
+
w.close_topic()
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The writer enforces non-decreasing timestamps within an open topic group.
|
|
66
|
+
|
|
67
|
+
### Schema metadata
|
|
68
|
+
|
|
69
|
+
Supply `schema_name`, `schema_encoding`, and binary `schema_data` per topic
|
|
70
|
+
for downstream schema discovery. Missing, null, or empty values produce one
|
|
71
|
+
warning per topic when opening it; writing continues by default. The minimal
|
|
72
|
+
examples above omit these fields and therefore warn. Reading does not warn.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from turbodata import META_KEY_SCHEMA_NAME, META_KEY_SCHEMA_ENCODING, META_KEY_SCHEMA_DATA
|
|
76
|
+
|
|
77
|
+
metadata = {
|
|
78
|
+
META_KEY_SCHEMA_NAME: "Example",
|
|
79
|
+
META_KEY_SCHEMA_ENCODING: "jsonschema",
|
|
80
|
+
META_KEY_SCHEMA_DATA: b'{"type":"object"}',
|
|
81
|
+
}
|
|
82
|
+
# Pass metadata as the corresponding entry in open_topics' metadatas list.
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Chunk config
|
|
86
|
+
|
|
87
|
+
Chunks are the unit of indexing and I/O. By default the writer flushes a chunk
|
|
88
|
+
at a size threshold; `chunk_config` overrides the policy (by size, message
|
|
89
|
+
count, or time duration).
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from turbodata import ChunkConfig, ChunkThresholdMode
|
|
93
|
+
|
|
94
|
+
w.open_topics(
|
|
95
|
+
["/imu"],
|
|
96
|
+
[{"hz": 100}],
|
|
97
|
+
chunk_config=ChunkConfig(mode=ChunkThresholdMode.SIZE, size=1024 * 1024),
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Video
|
|
102
|
+
|
|
103
|
+
Mark a group as video with `video=True` and append frames with
|
|
104
|
+
`write_video_message` (which carries an `is_key_frame` flag). Chunk boundaries
|
|
105
|
+
are gated on key frames, so a GOP is never split across two chunks.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
w.open_topics(["/cam/h264"], [{"codec": "h264"}], video=True)
|
|
109
|
+
w.write_video_message("/cam/h264", key_frame_bytes, 1_000, True) # first frame must be a key frame
|
|
110
|
+
w.write_video_message("/cam/h264", delta_bytes, 2_000, False)
|
|
111
|
+
w.close_topic()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
A video group MUST contain exactly one topic and MUST NOT also be compressed
|
|
115
|
+
(the codec already compresses the bytes). The first frame MUST be a key frame.
|
|
116
|
+
|
|
117
|
+
## Read
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from turbodata import FileReadSource, Reader
|
|
121
|
+
|
|
122
|
+
with FileReadSource("data.td") as src:
|
|
123
|
+
reader = Reader(src)
|
|
124
|
+
for msg in reader.read_messages():
|
|
125
|
+
# msg.timestamp: int (unit set by the writer)
|
|
126
|
+
# msg.topic_name: str
|
|
127
|
+
# msg.data: bytes (aliases an internal buffer; copy if you need to keep it)
|
|
128
|
+
print(msg.timestamp, msg.topic_name, len(msg.data))
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
`msg.data` aliases an internal reusable buffer and is only valid until the
|
|
132
|
+
next iteration step. Pass `copy=True` for fresh bytes each iteration:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
for msg in reader.read_messages(copy=True):
|
|
136
|
+
... # msg.data is independent of subsequent pulls
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Order, time, and topic filters
|
|
140
|
+
|
|
141
|
+
Topics not listed are skipped; chunks fully outside the `[start, end]` window
|
|
142
|
+
are never fetched.
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from turbodata import Order
|
|
146
|
+
|
|
147
|
+
reader.read_messages(
|
|
148
|
+
order=Order.REVERSE_TIME, # default: Order.TIME
|
|
149
|
+
topic_names=["/imu", "/cam"], # default: all topics
|
|
150
|
+
start_timestamp=1_000_000_000, # inclusive lower bound
|
|
151
|
+
end_timestamp=2_000_000_000, # inclusive upper bound
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Cost-aware concurrent reads
|
|
156
|
+
|
|
157
|
+
For cloud object storage (S3 / GCS) or large local reads, pass a
|
|
158
|
+
`ReadStrategy`. The reader pre-plans every needed byte range, coalesces nearby
|
|
159
|
+
ranges, optionally splits large reads, and issues them concurrently via a
|
|
160
|
+
thread pool. Without a strategy it uses the memory-minimal lazy path.
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from turbodata import strategy_for_latency
|
|
164
|
+
|
|
165
|
+
reader.read_messages(
|
|
166
|
+
strategy=strategy_for_latency(
|
|
167
|
+
rtt_seconds=0.020,
|
|
168
|
+
per_stream_bw=125 * 1024 * 1024,
|
|
169
|
+
concurrency=16,
|
|
170
|
+
),
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Helper constructors mirror the Go SDK: `strategy_for_latency`,
|
|
175
|
+
`strategy_for_money`, `strategy_for_blended`. Pass a hand-tuned
|
|
176
|
+
`ReadStrategy(coalesce_gap=..., split_threshold=..., max_concurrency=...)`
|
|
177
|
+
when you know the right values for your storage backend.
|
|
178
|
+
|
|
179
|
+
### Video
|
|
180
|
+
|
|
181
|
+
A non-key frame is only decodable after its GOP's key frame, so a plain time
|
|
182
|
+
filter that starts mid-GOP yields bytes a decoder can't cold-start on.
|
|
183
|
+
`video_decodable=True` snaps the effective start back to the latest key frame
|
|
184
|
+
at or before it, so the emitted sequence starts decodable. Non-video topics
|
|
185
|
+
are unaffected.
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
reader.read_messages(
|
|
189
|
+
topic_names=["/cam/h264"],
|
|
190
|
+
start_timestamp=650, # mid-GOP
|
|
191
|
+
video_decodable=True, # snaps back to the key frame at/<=650
|
|
192
|
+
)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Sample (floor lookup at concrete timestamps)
|
|
196
|
+
|
|
197
|
+
`sample` returns the floor message per `(topic, timestamp)` pair: the
|
|
198
|
+
most-recent message at or before each requested timestamp. Use it for "the
|
|
199
|
+
state at time T" rather than "every message in `[t0, t1]`".
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from turbodata import FileReadSource, Reader, SampleQuery, lin_space_timestamps
|
|
203
|
+
|
|
204
|
+
with FileReadSource("data.td") as src:
|
|
205
|
+
reader = Reader(src)
|
|
206
|
+
out = reader.sample([
|
|
207
|
+
SampleQuery(topic="/imu", timestamps=lin_space_timestamps(0, 100_000_000, 10)),
|
|
208
|
+
SampleQuery(topic="/cam", timestamps=[1_000_000_000, 2_000_000_000]),
|
|
209
|
+
])
|
|
210
|
+
for q, row in zip(["/imu", "/cam"], out):
|
|
211
|
+
for r in row:
|
|
212
|
+
if r.found:
|
|
213
|
+
print(q, r.timestamp, len(r.data))
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`out[i][j]` corresponds to `queries[i].timestamps[j]`. The same topic must not
|
|
217
|
+
appear in more than one `SampleQuery`; timestamps within one query must be
|
|
218
|
+
strictly increasing.
|
|
219
|
+
|
|
220
|
+
### Strategy
|
|
221
|
+
|
|
222
|
+
Pass `strategy=...` to override the default sample strategy for your backend:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
from turbodata import ReadStrategy
|
|
226
|
+
|
|
227
|
+
reader.sample(
|
|
228
|
+
queries,
|
|
229
|
+
strategy=ReadStrategy(coalesce_gap=256 * 1024, split_threshold=2 * 1024 * 1024, max_concurrency=4),
|
|
230
|
+
)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Video
|
|
234
|
+
|
|
235
|
+
With `video_decodable=True`, results for a video topic carry a decoder-ready
|
|
236
|
+
GOP sequence in `frames` (and `data` is empty) instead of the single floor
|
|
237
|
+
frame. Within a row (one topic, strictly increasing timestamps), the first
|
|
238
|
+
result in each GOP sets `reset_decoder=True` with the full prefix
|
|
239
|
+
`[keyframe ... target]`; later results in the same GOP set
|
|
240
|
+
`reset_decoder=False` with only the new frames since the previous query.
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
out = reader.sample(
|
|
244
|
+
[SampleQuery(topic="/cam/h264", timestamps=[350, 650])],
|
|
245
|
+
video_decodable=True,
|
|
246
|
+
)
|
|
247
|
+
for r in out[0]:
|
|
248
|
+
if r.found:
|
|
249
|
+
# r.is_video is True; feed r.frames to a decoder,
|
|
250
|
+
# resetting it first when r.reset_decoder is True.
|
|
251
|
+
print(r.timestamp, r.reset_decoder, len(r.frames))
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Multi-file reading (MultiReader)
|
|
255
|
+
|
|
256
|
+
`MultiReader` presents several single-file `Reader`s as one time-ordered
|
|
257
|
+
stream. Read/sample options pass through to each underlying reader. Topic-name
|
|
258
|
+
collisions across files are resolved with per-`Reader` `topic_remap`: names
|
|
259
|
+
meant to union share an exposed name; names meant to stay distinct are remapped
|
|
260
|
+
apart.
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from turbodata import BytesReadSource, MultiReader, Reader, SampleQuery
|
|
264
|
+
|
|
265
|
+
mr = MultiReader(
|
|
266
|
+
Reader(BytesReadSource(file_a)),
|
|
267
|
+
# Keep file B's "/cam" distinct instead of unioning it with A's.
|
|
268
|
+
Reader(BytesReadSource(file_b), topic_remap={"/cam": "/cam_b"}),
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
for msg in mr.read_messages():
|
|
272
|
+
print(msg.timestamp, msg.topic_name)
|
|
273
|
+
|
|
274
|
+
# sample() returns, per cell, the latest floor across the union of files.
|
|
275
|
+
out = mr.sample([SampleQuery(topic="/cam", timestamps=[150, 350])])
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Topic remap
|
|
279
|
+
|
|
280
|
+
`topic_remap` is keyed by in-file name and valued by the exposed name reported
|
|
281
|
+
by `summary()`, emitted from `read_messages`, and accepted by `topic_names`
|
|
282
|
+
and `SampleQuery.topic`. Names absent from the map pass through unchanged. It
|
|
283
|
+
works on a single `Reader` too:
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
reader = Reader(src, topic_remap={"/cam": "/cam_v2"})
|
|
287
|
+
for msg in reader.read_messages(topic_names=["/cam_v2"]):
|
|
288
|
+
print(msg.topic_name) # "/cam_v2"
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
The remap is validated lazily against the file's summary on first use: it
|
|
292
|
+
raises `TopicRemapCollisionError` if two topics collapse onto the same exposed
|
|
293
|
+
name.
|
|
294
|
+
|
|
295
|
+
## ReadSource protocol
|
|
296
|
+
|
|
297
|
+
A `ReadSource` exposes two methods:
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
class ReadSource(Protocol):
|
|
301
|
+
def size(self) -> int: ...
|
|
302
|
+
def read_at(self, offset: int, n: int) -> bytes: ...
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
`read_at` MUST be safe to call from multiple threads concurrently when used
|
|
306
|
+
with the cost-aware path. Built-in sources:
|
|
307
|
+
|
|
308
|
+
- `FileReadSource(path_or_fd)` — local files, uses `os.pread` on POSIX
|
|
309
|
+
- `BytesReadSource(bytes)` — in-memory bytes for tests/small files
|
|
310
|
+
|
|
311
|
+
Roll your own for HTTP range reads, S3, GCS, etc.
|
|
312
|
+
|
|
313
|
+
## Mapping to the Go SDK
|
|
314
|
+
|
|
315
|
+
| Go | Python |
|
|
316
|
+
| ----------------------------------- | ----------------------------------- |
|
|
317
|
+
| `NewReader(rs)` | `Reader(source)` |
|
|
318
|
+
| `Summary()` | `reader.summary()` |
|
|
319
|
+
| `ReadMessages(opts...)` | `reader.read_messages(**kwargs)` |
|
|
320
|
+
| `Sample(queries, opts...)` | `reader.sample(queries, **kwargs)` |
|
|
321
|
+
| `WithTopicNames` | `topic_names=[...]` |
|
|
322
|
+
| `WithStartTimestamp` | `start_timestamp=...` |
|
|
323
|
+
| `WithEndTimestamp` | `end_timestamp=...` |
|
|
324
|
+
| `WithOrder(ReverseTimeOrder)` | `order=Order.REVERSE_TIME` |
|
|
325
|
+
| `WithReadStrategy(s)` | `strategy=...` |
|
|
326
|
+
| `WithTailPrefetch(n)` | `tail_prefetch=n` |
|
|
327
|
+
| `WithVideoDecodable()` | `video_decodable=True` |
|
|
328
|
+
| `WithSampleVideoDecodable()` | `video_decodable=True` (on sample) |
|
|
329
|
+
| `WithTopicRemap(m)` | `Reader(src, topic_remap={...})` |
|
|
330
|
+
| `NewWriter(f)` | `Writer(f)` |
|
|
331
|
+
| `OpenTopics(names, metas, opts...)` | `writer.open_topics(...)` |
|
|
332
|
+
| `WithChunkConfig(cc)` | `chunk_config=ChunkConfig(...)` |
|
|
333
|
+
| `WithCompression()` | `compression=True` |
|
|
334
|
+
| `WithVideoTopic()` | `video=True` |
|
|
335
|
+
| `WriteMessage(topic, data, ts)` | `writer.write_message(topic, data, ts)` |
|
|
336
|
+
| `WriteVideoMessage(topic, data, ts, kf)` | `writer.write_video_message(topic, data, ts, kf)` |
|
|
337
|
+
| `CloseTopic()` | `writer.close_topic()` |
|
|
338
|
+
| `Close()` | `writer.close()` (or `with`) |
|
|
339
|
+
|
|
340
|
+
## Run the examples
|
|
341
|
+
|
|
342
|
+
Run `write_demo.py` first; it produces `examples/demo.td`, which the read and
|
|
343
|
+
sample demos consume.
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
python examples/write_demo.py # produces examples/demo.td (incl. a video group)
|
|
347
|
+
python examples/read_demo.py # filters, order, strategy, video snap-back
|
|
348
|
+
python examples/sample_demo.py # floor lookup, strategy, video GOP-prefix
|
|
349
|
+
python examples/multiread_demo.py # union, split-via-remap, cross-file sample
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Run the tests
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
pip install -e ".[test]"
|
|
356
|
+
pytest tests/
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Cross-language tests run against the Go SDK's example fixtures
|
|
360
|
+
(`../ts/test/fixtures/*.td` and `../go/examples/demo.td`) when those files
|
|
361
|
+
are present.
|