pytrosna 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.
Files changed (68) hide show
  1. pytrosna-0.1.0/CHANGELOG.md +28 -0
  2. pytrosna-0.1.0/LICENSE-APACHE +176 -0
  3. pytrosna-0.1.0/LICENSE-MIT +21 -0
  4. pytrosna-0.1.0/PKG-INFO +267 -0
  5. pytrosna-0.1.0/README.md +218 -0
  6. pytrosna-0.1.0/README.ru.md +220 -0
  7. pytrosna-0.1.0/docs/api.md +306 -0
  8. pytrosna-0.1.0/docs/api.ru.md +309 -0
  9. pytrosna-0.1.0/docs/guide.md +525 -0
  10. pytrosna-0.1.0/docs/guide.ru.md +532 -0
  11. pytrosna-0.1.0/docs/publishing.md +17 -0
  12. pytrosna-0.1.0/docs/publishing.ru.md +89 -0
  13. pytrosna-0.1.0/examples/01_quickstart.py +53 -0
  14. pytrosna-0.1.0/examples/02_editing_and_history.py +64 -0
  15. pytrosna-0.1.0/examples/03_low_level.py +73 -0
  16. pytrosna-0.1.0/examples/04_collector_and_recovery.py +38 -0
  17. pytrosna-0.1.0/examples/05_annotations_as_labels.py +36 -0
  18. pytrosna-0.1.0/examples/cli_demo.sh +22 -0
  19. pytrosna-0.1.0/pyproject.toml +169 -0
  20. pytrosna-0.1.0/src/pytrosna/__init__.py +165 -0
  21. pytrosna-0.1.0/src/pytrosna/__main__.py +8 -0
  22. pytrosna-0.1.0/src/pytrosna/_bits.py +178 -0
  23. pytrosna-0.1.0/src/pytrosna/_bytes.py +228 -0
  24. pytrosna-0.1.0/src/pytrosna/_catalog.py +330 -0
  25. pytrosna-0.1.0/src/pytrosna/_checksum.py +53 -0
  26. pytrosna-0.1.0/src/pytrosna/_format.py +571 -0
  27. pytrosna-0.1.0/src/pytrosna/_read.py +245 -0
  28. pytrosna-0.1.0/src/pytrosna/_scan.py +266 -0
  29. pytrosna-0.1.0/src/pytrosna/_segment.py +263 -0
  30. pytrosna-0.1.0/src/pytrosna/adapters.py +952 -0
  31. pytrosna-0.1.0/src/pytrosna/api.py +577 -0
  32. pytrosna-0.1.0/src/pytrosna/cli.py +814 -0
  33. pytrosna-0.1.0/src/pytrosna/codecs.py +154 -0
  34. pytrosna-0.1.0/src/pytrosna/column.py +386 -0
  35. pytrosna-0.1.0/src/pytrosna/encodings.py +717 -0
  36. pytrosna-0.1.0/src/pytrosna/errors.py +182 -0
  37. pytrosna-0.1.0/src/pytrosna/history.py +270 -0
  38. pytrosna-0.1.0/src/pytrosna/py.typed +0 -0
  39. pytrosna-0.1.0/src/pytrosna/reader.py +352 -0
  40. pytrosna-0.1.0/src/pytrosna/timeconv.py +172 -0
  41. pytrosna-0.1.0/src/pytrosna/tools.py +243 -0
  42. pytrosna-0.1.0/src/pytrosna/types.py +299 -0
  43. pytrosna-0.1.0/src/pytrosna/writer.py +958 -0
  44. pytrosna-0.1.0/tests/conftest.py +92 -0
  45. pytrosna-0.1.0/tests/data/golden_v1.trosna +0 -0
  46. pytrosna-0.1.0/tests/test_adapters.py +516 -0
  47. pytrosna-0.1.0/tests/test_api.py +269 -0
  48. pytrosna-0.1.0/tests/test_bits.py +128 -0
  49. pytrosna-0.1.0/tests/test_bytes.py +158 -0
  50. pytrosna-0.1.0/tests/test_checksum.py +27 -0
  51. pytrosna-0.1.0/tests/test_cli.py +289 -0
  52. pytrosna-0.1.0/tests/test_codecs.py +119 -0
  53. pytrosna-0.1.0/tests/test_column.py +162 -0
  54. pytrosna-0.1.0/tests/test_docs.py +42 -0
  55. pytrosna-0.1.0/tests/test_e2e.py +356 -0
  56. pytrosna-0.1.0/tests/test_encodings.py +403 -0
  57. pytrosna-0.1.0/tests/test_examples.py +45 -0
  58. pytrosna-0.1.0/tests/test_format.py +259 -0
  59. pytrosna-0.1.0/tests/test_golden.py +73 -0
  60. pytrosna-0.1.0/tests/test_history.py +101 -0
  61. pytrosna-0.1.0/tests/test_interop.py +175 -0
  62. pytrosna-0.1.0/tests/test_reader.py +173 -0
  63. pytrosna-0.1.0/tests/test_scan.py +183 -0
  64. pytrosna-0.1.0/tests/test_segment.py +196 -0
  65. pytrosna-0.1.0/tests/test_timeconv.py +112 -0
  66. pytrosna-0.1.0/tests/test_tools.py +170 -0
  67. pytrosna-0.1.0/tests/test_types.py +109 -0
  68. pytrosna-0.1.0/tests/test_writer.py +432 -0
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ All notable changes of pytrosna are documented here. The project follows
4
+ [Semantic Versioning](https://semver.org).
5
+
6
+ ## 0.1.0 — 2026-10-09
7
+
8
+ First release: a pure-Python implementation of the Trosna file format,
9
+ version 1.0.
10
+
11
+ * Reading and writing of `.trosna` files, byte-compatible with the reference
12
+ Rust implementation (the golden file is reproduced byte for byte).
13
+ * All encodings of the format (plain, delta-bitpack, delta-of-delta, RLE,
14
+ Gorilla XOR, dictionary) with adaptive per-segment selection, and the
15
+ codecs none, LZ4 and Zstandard.
16
+ * Editing: inserts, updates, deletions of points and ranges, interval
17
+ annotations, file and device metadata; atomic, SHA-256 hash-chained
18
+ commits; rollback; time travel (`as_of`) and differences between versions.
19
+ * Crash safety: recovery of unfinished files, refusal to truncate files
20
+ damaged in the middle, `verify`, `recover` and `compact`.
21
+ * High-level API (`pytrosna.open`, `read_*`, `write`, `create`, transactions)
22
+ with adapters for pandas, Polars and PyArrow; a NumPy-only low-level API
23
+ (`Writer`, `Reader`, `Batch`).
24
+ * The `pytrosna` command-line tool (CSV import and export, inspection,
25
+ editing, history, maintenance).
26
+ * Documentation in English and Russian; about 400 tests including
27
+ property-based, model-based, crash-simulation, corruption and
28
+ interoperability tests.
@@ -0,0 +1,176 @@
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
95
+ Derivative 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,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative 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
111
+ of the following places: within a NOTICE text file distributed
112
+ as 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
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying 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
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrey Ferubko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,267 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytrosna
3
+ Version: 0.1.0
4
+ Summary: Read, write and edit Trosna time-series files (.trosna) in pure Python: columnar, compressed, versioned, with pandas, Polars and PyArrow adapters
5
+ Keywords: time-series,file-format,trosna,columnar,compression,gorilla,versioning,pandas,polars,arrow
6
+ Author: Andrey Ferubko
7
+ Author-email: Andrey Ferubko <ferubko1999@yandex.ru>
8
+ License-Expression: MIT OR Apache-2.0
9
+ License-File: LICENSE-APACHE
10
+ License-File: LICENSE-MIT
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Database
22
+ Classifier: Topic :: Scientific/Engineering
23
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
24
+ Classifier: Topic :: System :: Archiving :: Compression
25
+ Classifier: Typing :: Typed
26
+ Requires-Dist: crc32c>=2.4
27
+ Requires-Dist: lz4>=4.3
28
+ Requires-Dist: numpy>=1.26
29
+ Requires-Dist: tzdata ; sys_platform == 'win32'
30
+ Requires-Dist: zstandard>=0.22 ; python_full_version < '3.14'
31
+ Requires-Dist: pyarrow>=15 ; extra == 'all'
32
+ Requires-Dist: pandas>=2.1 ; extra == 'all'
33
+ Requires-Dist: polars>=1.0 ; extra == 'all'
34
+ Requires-Dist: pyarrow>=15 ; extra == 'arrow'
35
+ Requires-Dist: pandas>=2.1 ; extra == 'pandas'
36
+ Requires-Dist: polars>=1.0 ; extra == 'polars'
37
+ Requires-Python: >=3.11
38
+ Project-URL: Homepage, https://github.com/89605502155/pytrosna
39
+ Project-URL: Documentation, https://github.com/89605502155/pytrosna/tree/main/docs
40
+ Project-URL: Repository, https://github.com/89605502155/pytrosna
41
+ Project-URL: Issues, https://github.com/89605502155/pytrosna/issues
42
+ Project-URL: Format specification, https://github.com/89605502155/trosna-file/blob/main/docs/SPEC.md
43
+ Project-URL: Rust implementation, https://github.com/89605502155/trosna-file
44
+ Provides-Extra: all
45
+ Provides-Extra: arrow
46
+ Provides-Extra: pandas
47
+ Provides-Extra: polars
48
+ Description-Content-Type: text/markdown
49
+
50
+ # pytrosna
51
+
52
+ **Read, write and edit Trosna time-series files (`.trosna`) in pure Python.**
53
+
54
+ [Русская версия](https://github.com/89605502155/pytrosna/blob/main/README.ru.md) ·
55
+ [User guide](https://github.com/89605502155/pytrosna/blob/main/docs/guide.md) ·
56
+ [API reference](https://github.com/89605502155/pytrosna/blob/main/docs/api.md) ·
57
+ [Examples](https://github.com/89605502155/pytrosna/tree/main/examples) ·
58
+ [Format specification](https://github.com/89605502155/trosna-file/blob/main/docs/SPEC.md)
59
+
60
+ Trosna is a file format for time series. A `.trosna` file is as easy to
61
+ create and read as CSV, but stores data the way time-series databases do:
62
+ column by column, with encodings designed for time stamps and measurements,
63
+ and with a verifiable history of every change.
64
+
65
+ `pytrosna` is a pure-Python implementation of format version 1.0, fully
66
+ compatible with the reference Rust implementation
67
+ ([trosna-file](https://github.com/89605502155/trosna-file)): files written by
68
+ either one are read, edited and verified by the other. The writer uses the
69
+ same algorithms, down to the choice of encodings, and reproduces the golden
70
+ file of the Rust implementation byte for byte. (Where a segment is
71
+ compressed with Zstandard, the two libraries may produce different but
72
+ equivalent compressed bytes.)
73
+
74
+ * **Compact.** Every column segment is encoded with the smallest of
75
+ delta-of-delta, TS_2DIFF-style bit packing, Gorilla XOR, run-length and
76
+ dictionary encodings, then compressed with Zstandard or LZ4. A sensor
77
+ series takes **1.5 bytes per point** (CSV: 16.9, Parquet + zstd: 2.6).
78
+ * **Editable, with history.** Insert, change and delete points anywhere on
79
+ the time axis and label time intervals. Every change is an atomic commit;
80
+ every earlier version stays readable (`as_of=`). Commits form a SHA-256 hash
81
+ chain, so the history is tamper-evident.
82
+ * **Crash-safe.** The file is an append-only log of checksummed frames. After
83
+ a crash it reads as of its last commit; the next writer removes the
84
+ unfinished tail.
85
+ * **Several devices per file**, each a table with its own columns, time unit
86
+ (s, ms, us, ns) and time zone.
87
+ * **Works with the Python data stack.** Read into and write from pandas,
88
+ Polars and PyArrow, or use NumPy-backed batches without any of them.
89
+ * **Pure Python.** No compiler needed: the dependencies are NumPy, `lz4`,
90
+ `crc32c` and, before Python 3.14, `zstandard`.
91
+
92
+ ## Installation
93
+
94
+ ```sh
95
+ pip install pytrosna # NumPy-backed core
96
+ pip install "pytrosna[pandas]" # + pandas
97
+ pip install "pytrosna[polars]" # + Polars
98
+ pip install "pytrosna[arrow]" # + PyArrow
99
+ pip install "pytrosna[all]" # everything
100
+
101
+ uv add "pytrosna[all]" # with uv
102
+ ```
103
+
104
+ Python 3.11 or newer is required.
105
+
106
+ ## Quick start
107
+
108
+ ```python
109
+ import pandas as pd
110
+ import pytrosna
111
+
112
+ df = pd.DataFrame(
113
+ {
114
+ "time": pd.date_range("2026-10-08 10:00", periods=5, freq="10s", tz="Europe/Moscow"),
115
+ "temperature": [21.5, 21.6, 21.7, 21.6, 21.8],
116
+ "humidity": [40, 41, 41, 42, 42],
117
+ }
118
+ )
119
+
120
+ pytrosna.write("room.trosna", df, device="room1") # create the file (one commit)
121
+
122
+ pytrosna.read_pandas("room.trosna") # everything, as pandas
123
+ # a time range and a column, as Polars:
124
+ pytrosna.read_polars("room.trosna", start="2026-10-08 10:00:10", columns=["temperature"])
125
+ pytrosna.read_arrow("room.trosna") # a pyarrow.Table
126
+ pytrosna.read("room.trosna") # a NumPy-backed pytrosna.Batch
127
+ ```
128
+
129
+ Times can be `datetime`, `pandas.Timestamp`, `numpy.datetime64`, ISO 8601 text
130
+ or raw integers. Text without a UTC offset is a wall-clock time of the
131
+ device's time zone.
132
+
133
+ ## Editing, annotations and time travel
134
+
135
+ ```python
136
+ f = pytrosna.open("room.trosna")
137
+
138
+ with f.edit(message="sensor check", author="me") as tx: # one atomic commit
139
+ tx.update("room1", "2026-10-08 10:00:20", temperature=21.65)
140
+ tx.delete("room1", "2026-10-08 10:00:10")
141
+ tx.insert("room1", "2026-10-08 10:01:00", temperature=22.0)
142
+ tx.annotate("room1", "2026-10-08 10:00:15", "2026-10-08 10:00:25", "door open")
143
+ # if the block raises, nothing is written
144
+
145
+ f.read_pandas() # the current data
146
+ f.read_pandas(as_of=1) # the data as first imported
147
+ f.diff(1).points # what changed since commit 1
148
+ f.annotations() # labelled intervals
149
+ f.commits() # the hash-chained history
150
+ f.verify().ok # checksums, hash chain, decoding of all data
151
+ f.compact("small.trosna") # a copy without history that links to it
152
+ ```
153
+
154
+ Appending is just as simple:
155
+
156
+ ```python
157
+ more_rows = df.assign(time=df["time"] + pd.Timedelta("1h"))
158
+ pytrosna.write("room.trosna", more_rows, device="room1", mode="a")
159
+ ```
160
+
161
+ ## Low-level API
162
+
163
+ `Writer` and `Reader` work with raw integer time stamps and NumPy arrays and
164
+ need no other libraries:
165
+
166
+ ```python
167
+ import numpy as np
168
+ from pytrosna import DeviceSchema, Reader, Writer
169
+
170
+ with Writer.create("vms.trosna") as w: # closing commits
171
+ w.create_device(DeviceSchema.build("vm01", "ms", {"cpu": "float64", "ram_mb": "int64"}))
172
+ w.write(
173
+ "vm01",
174
+ {
175
+ "time": np.arange(0, 10_000, 1000),
176
+ "cpu": np.random.rand(10),
177
+ "ram_mb": np.full(10, 2048),
178
+ },
179
+ )
180
+ w.commit(message="first measurements")
181
+ w.update("vm01", 3000, cpu=0.99)
182
+ w.delete_range("vm01", 7000, 9000)
183
+
184
+ with Reader("vms.trosna") as r:
185
+ batch = r.query("vm01").columns(["cpu"]).time_range(0, 5000).collect()
186
+ batch.time, batch["cpu"].values # NumPy arrays
187
+ r.query("vm01").as_of(1).count() # 10 points in version 1
188
+ ```
189
+
190
+ ## Command line
191
+
192
+ The package installs a `pytrosna` command:
193
+
194
+ ```sh
195
+ pytrosna convert room.csv room.trosna --device room1 # CSV → Trosna (types are detected)
196
+ pytrosna info room.trosna # devices, history, storage per column
197
+ pytrosna cat room.trosna --from "2026-10-08 10:00" --format table
198
+ pytrosna update room.trosna --time "2026-10-08 10:00:20" temperature=21.65 -m "sensor check"
199
+ pytrosna annotate room.trosna --start "2026-10-08 10:00:15" --end "2026-10-08 10:00:25" --label "door open"
200
+ pytrosna log room.trosna
201
+ pytrosna diff room.trosna --from 1
202
+ pytrosna verify room.trosna
203
+ pytrosna convert room.trosna back.csv # Trosna → CSV
204
+ ```
205
+
206
+ `pytrosna --help` lists all commands: `info`, `cat`, `convert`, `insert`,
207
+ `update`, `delete`, `annotate`, `unannotate`, `annotations`, `log`, `diff`,
208
+ `verify`, `recover`, `compact`.
209
+
210
+ ## Size and speed
211
+
212
+ One million readings of a slowly varying sensor (values rounded to 0.01, one
213
+ per second), with Zstandard:
214
+
215
+ | Format | Bytes per point |
216
+ |-----------------------------|-----------------|
217
+ | **Trosna (pytrosna)** | **1.49** |
218
+ | Arrow IPC (Feather), zstd | 2.18 |
219
+ | Parquet, zstd | 2.56 |
220
+ | CSV, gzip | 3.14 |
221
+ | CSV | 16.90 |
222
+
223
+ pytrosna writes about 0.8 and reads about 0.6 million points per second on a
224
+ laptop: its encoders and decoders are vectorized with NumPy where the format
225
+ allows it. When speed matters more than having no compiled dependencies, the
226
+ Rust implementation is faster; the files are the same.
227
+
228
+ ## Compatibility and testing
229
+
230
+ * Format version 1.0, as specified in
231
+ [SPEC.md](https://github.com/89605502155/trosna-file/blob/main/docs/SPEC.md).
232
+ * The writer reproduces the golden file of the Rust implementation **byte for
233
+ byte**, and the test suite (about 400 tests, 98 % line coverage) includes
234
+ interoperability tests that run the reference `trosna` tool on files written
235
+ by pytrosna and vice versa. The code examples of this README and of the
236
+ guides are executed by the tests as well.
237
+ * Property-based tests compare every encoder with a reference implementation
238
+ written directly from the specification; a model-based test checks the
239
+ editing semantics at every version; files are truncated at every byte
240
+ offset and corrupted with random bit flips to check recovery and error
241
+ handling.
242
+
243
+ ## Development
244
+
245
+ ```sh
246
+ uv sync # create the environment with all extras and tools
247
+ uv run pytest # the test suite (TROSNA_CLI=/path/to/trosna enables interop tests)
248
+ uv run ruff check . && uv run ruff format --check .
249
+ uv run mypy
250
+ uv build # sdist and wheel in dist/
251
+ ```
252
+
253
+ Publishing to PyPI is described in
254
+ [docs/publishing.md](https://github.com/89605502155/pytrosna/blob/main/docs/publishing.md).
255
+
256
+ ## Citation
257
+
258
+ If you use Trosna in research, please cite the review that motivated it:
259
+
260
+ > Ferubko A. O., Kazakov O. D. Review of data structures and file formats for
261
+ > storage and transfer of time series with regard to their support in the
262
+ > Python and Rust ecosystems. 2026.
263
+
264
+ ## License
265
+
266
+ Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
267
+ [MIT license](LICENSE-MIT) at your option.