statementkit 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.
@@ -0,0 +1,14 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "statementkit"
7
+ version = "0.1.0"
8
+
9
+ [[package]]
10
+ name = "statementkit-c"
11
+ version = "0.1.0"
12
+ dependencies = [
13
+ "statementkit",
14
+ ]
@@ -0,0 +1,9 @@
1
+ [workspace]
2
+ resolver = "2"
3
+ members = ["crates/statementkit", "crates/statementkit-c"]
4
+
5
+ [workspace.package]
6
+ version = "0.1.0"
7
+ edition = "2024"
8
+ license = "Apache-2.0"
9
+ rust-version = "1.85"
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,7 @@
1
+ graft crates
2
+ graft tests/vectors
3
+ graft bindings/python
4
+ include Cargo.toml
5
+ include Cargo.lock
6
+ include LICENSE
7
+ include README.md
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: statementkit
3
+ Version: 0.1.0
4
+ Summary: Parse brokerage statement content into actionable numbers. Independent tool. Not affiliated with or endorsed by Interactive Brokers LLC.
5
+ Author: heshiming
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/heshiming/statementkit
8
+ Project-URL: Repository, https://github.com/heshiming/statementkit
9
+ Keywords: brokerage,statements,parsing,finance
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Rust
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ # statementkit
21
+
22
+ Parse brokerage statement content into actionable knowledge and numbers.
23
+ A library for upper applications: a pure Rust core, a stable C ABI, and
24
+ thin bindings for other languages on top.
25
+
26
+ Independent tool. Not affiliated with or endorsed by Interactive Brokers
27
+ LLC.
28
+
29
+ ## Status
30
+
31
+ Skeleton. The demo API is a single float-literal parser proving every
32
+ layer: Rust core → Rust tests → C ABI → header → linked C consumer.
33
+ Semantics follow the documented characteristics of real statement
34
+ exports; expect additive APIs at `0.x`.
35
+
36
+ ## Layout
37
+
38
+ ```
39
+ crates/statementkit core: pure functions, no I/O, no FFI types
40
+ crates/statementkit-c C ABI: status codes, out-params, panic-proofed
41
+ include/statementkit.h hand-kept header; discriminants contractual
42
+ bindings/python ctypes shim over the C ABI (pyo3 wheels later)
43
+ bindings/node raw-WASM npm package, TypeScript types included
44
+ bindings/java Panama FFM (java.lang.foreign), JDK 22+, no JNI
45
+ bindings/go cgo over the static lib, plain `go test ./...`
46
+ tests/vectors/ shared ground-truth vectors every binding runs
47
+ scripts/c-smoke.sh links tests/smoke.c against the static lib, runs it
48
+ scripts/bindings-test.sh builds all targets, runs every binding suite
49
+ ```
50
+
51
+ All parsing logic lives in the core crate only. A binding that
52
+ re-implements logic, or behaves differently from another binding, is a bug.
53
+
54
+ ## Quickstart
55
+
56
+ ```sh
57
+ cargo test --workspace # core unit + integration + FFI tests
58
+ scripts/c-smoke.sh # builds release static lib, compiles and runs C smoke
59
+ scripts/bindings-test.sh # python + go + node + java suites vs shared vectors
60
+ ```
61
+
62
+ C usage:
63
+
64
+ ```c
65
+ #include "statementkit.h"
66
+ double v;
67
+ if (sk_parse_float("12.25", &v) == SK_OK) { /* v == 12.25 */ }
68
+ ```
69
+
70
+ ## Guarantees
71
+
72
+ - No network I/O, no credentials, no telemetry — checkable in a network
73
+ namespace.
74
+ - No Rust panic ever crosses the FFI boundary (`catch_unwind` at every
75
+ entry point; `SK_PANIC` as the last-resort status).
76
+ - All test fixtures are synthetic. The library has never seen a real
77
+ statement and ships none.
78
+ - Binary float is for demo only; money handling will be exact decimal.
79
+
80
+ ## License
81
+
82
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,63 @@
1
+ # statementkit
2
+
3
+ Parse brokerage statement content into actionable knowledge and numbers.
4
+ A library for upper applications: a pure Rust core, a stable C ABI, and
5
+ thin bindings for other languages on top.
6
+
7
+ Independent tool. Not affiliated with or endorsed by Interactive Brokers
8
+ LLC.
9
+
10
+ ## Status
11
+
12
+ Skeleton. The demo API is a single float-literal parser proving every
13
+ layer: Rust core → Rust tests → C ABI → header → linked C consumer.
14
+ Semantics follow the documented characteristics of real statement
15
+ exports; expect additive APIs at `0.x`.
16
+
17
+ ## Layout
18
+
19
+ ```
20
+ crates/statementkit core: pure functions, no I/O, no FFI types
21
+ crates/statementkit-c C ABI: status codes, out-params, panic-proofed
22
+ include/statementkit.h hand-kept header; discriminants contractual
23
+ bindings/python ctypes shim over the C ABI (pyo3 wheels later)
24
+ bindings/node raw-WASM npm package, TypeScript types included
25
+ bindings/java Panama FFM (java.lang.foreign), JDK 22+, no JNI
26
+ bindings/go cgo over the static lib, plain `go test ./...`
27
+ tests/vectors/ shared ground-truth vectors every binding runs
28
+ scripts/c-smoke.sh links tests/smoke.c against the static lib, runs it
29
+ scripts/bindings-test.sh builds all targets, runs every binding suite
30
+ ```
31
+
32
+ All parsing logic lives in the core crate only. A binding that
33
+ re-implements logic, or behaves differently from another binding, is a bug.
34
+
35
+ ## Quickstart
36
+
37
+ ```sh
38
+ cargo test --workspace # core unit + integration + FFI tests
39
+ scripts/c-smoke.sh # builds release static lib, compiles and runs C smoke
40
+ scripts/bindings-test.sh # python + go + node + java suites vs shared vectors
41
+ ```
42
+
43
+ C usage:
44
+
45
+ ```c
46
+ #include "statementkit.h"
47
+ double v;
48
+ if (sk_parse_float("12.25", &v) == SK_OK) { /* v == 12.25 */ }
49
+ ```
50
+
51
+ ## Guarantees
52
+
53
+ - No network I/O, no credentials, no telemetry — checkable in a network
54
+ namespace.
55
+ - No Rust panic ever crosses the FFI boundary (`catch_unwind` at every
56
+ entry point; `SK_PANIC` as the last-resort status).
57
+ - All test fixtures are synthetic. The library has never seen a real
58
+ statement and ships none.
59
+ - Binary float is for demo only; money handling will be exact decimal.
60
+
61
+ ## License
62
+
63
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,33 @@
1
+ # Python binding — implemented (ctypes)
2
+
3
+ `statementkit` is a zero-dependency ctypes shim over the C ABI. Published
4
+ on PyPI; `pip install statementkit`. Binary wheels ship the native library
5
+ bundled for Linux (x86_64, aarch64) and Windows (win_amd64); on macOS the
6
+ same install builds the library from the sdist, which needs a Rust
7
+ toolchain (`cargo`) and the Xcode command line tools on PATH. For in-repo
8
+ development: `cargo build --release -p statementkit-c` (auto-found in
9
+ `target/release`, override with `$STATEMENTKIT_LIB`).
10
+
11
+ Independent tool. Not affiliated with or endorsed by Interactive Brokers
12
+ LLC.
13
+
14
+ ```python
15
+ import statementkit
16
+ statementkit.parse_float("12.25") # 12.25
17
+ statementkit.parse_float("1,2") # raises InvalidInputError
18
+ statementkit.version() # "0.1.0"
19
+ ```
20
+
21
+ Errors mirror the ABI status codes: `NullInputError`, `EmptyInputError`,
22
+ `InvalidInputError`, `PanicError` (all `StatementKitError` subclasses with
23
+ `.code`).
24
+
25
+ Test: `python3 test_parse_float.py` (shared vectors from `tests/vectors/`).
26
+
27
+ Packaging: the Python distribution is declared in the repo-root
28
+ `pyproject.toml`; setuptools-rust (`NoBinding`) compiles
29
+ `crates/statementkit-c` and bundles the cdylib into the wheel. Build with
30
+ `python -m build` from the repo root.
31
+
32
+ Next stage when the API is real: `crates/statementkit-python` (pyo3 +
33
+ maturin, `.pyi` stubs); this shim keeps working meanwhile.
@@ -0,0 +1,97 @@
1
+ """statementkit — ctypes shim over the C ABI.
2
+
3
+ Interim binding, zero dependencies: dlopens the C ABI shared library.
4
+ pip wheels bundle the library next to this file; in-repo builds find it in
5
+ the workspace target/release dir. The pyo3 wheel crate supersedes this
6
+ when the API is real. Library discovery: $STATEMENTKIT_LIB, else the
7
+ package dir, else workspace target/release, else the loader path.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import ctypes
13
+ import ctypes.util
14
+ import glob
15
+ import os
16
+ import pathlib
17
+
18
+
19
+ class StatementKitError(Exception):
20
+ """Base for all statementkit failures, carrying the ABI status code."""
21
+
22
+ def __init__(self, code: int, message: str):
23
+ super().__init__(message)
24
+ self.code = code
25
+
26
+
27
+ class NullInputError(StatementKitError):
28
+ pass
29
+
30
+
31
+ class EmptyInputError(StatementKitError):
32
+ pass
33
+
34
+
35
+ class InvalidInputError(StatementKitError):
36
+ pass
37
+
38
+
39
+ class PanicError(StatementKitError):
40
+ pass
41
+
42
+
43
+ _ERRORS = {
44
+ 1: NullInputError,
45
+ 2: EmptyInputError,
46
+ 3: InvalidInputError,
47
+ 4: PanicError,
48
+ }
49
+
50
+
51
+ def _find_library() -> str:
52
+ env = os.environ.get("STATEMENTKIT_LIB")
53
+ if env:
54
+ return env
55
+ here = pathlib.Path(__file__).resolve().parent
56
+ for hit in glob.glob(str(here / "*statementkit_c*.so")) + \
57
+ glob.glob(str(here / "*statementkit_c*.dylib")) + \
58
+ glob.glob(str(here / "*statementkit_c*.dll")) + \
59
+ glob.glob(str(here / "*statementkit_c*.pyd")):
60
+ return hit
61
+ root = here.parents[2]
62
+ names = ("libstatementkit_c.so", "libstatementkit_c.dylib", "statementkit_c.dll")
63
+ for name in names:
64
+ candidate = root / "target" / "release" / name
65
+ if candidate.exists():
66
+ return str(candidate)
67
+ for name in names:
68
+ found = ctypes.util.find_library(name)
69
+ if found:
70
+ return found
71
+ raise ImportError(
72
+ "statementkit native library not found; install the statementkit "
73
+ "wheel, run `cargo build --release -p statementkit-c` in the "
74
+ "workspace, or set $STATEMENTKIT_LIB"
75
+ )
76
+
77
+
78
+ _lib = ctypes.CDLL(_find_library())
79
+ _lib.sk_parse_float.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_double)]
80
+ _lib.sk_parse_float.restype = ctypes.c_int
81
+ _lib.sk_version.restype = ctypes.c_char_p
82
+
83
+
84
+ def parse_float(text: str | None) -> float:
85
+ """Parse a bare float literal; raises a StatementKitError subclass."""
86
+ if text is None:
87
+ raise NullInputError(1, "input is None")
88
+ out = ctypes.c_double()
89
+ status = _lib.sk_parse_float(text.encode("utf-8"), ctypes.byref(out))
90
+ if status != 0:
91
+ error = _ERRORS.get(status, PanicError)
92
+ raise error(status, f"sk_parse_float failed with status {status}")
93
+ return out.value
94
+
95
+
96
+ def version() -> str:
97
+ return _lib.sk_version().decode()
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: statementkit
3
+ Version: 0.1.0
4
+ Summary: Parse brokerage statement content into actionable numbers. Independent tool. Not affiliated with or endorsed by Interactive Brokers LLC.
5
+ Author: heshiming
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/heshiming/statementkit
8
+ Project-URL: Repository, https://github.com/heshiming/statementkit
9
+ Keywords: brokerage,statements,parsing,finance
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Rust
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ # statementkit
21
+
22
+ Parse brokerage statement content into actionable knowledge and numbers.
23
+ A library for upper applications: a pure Rust core, a stable C ABI, and
24
+ thin bindings for other languages on top.
25
+
26
+ Independent tool. Not affiliated with or endorsed by Interactive Brokers
27
+ LLC.
28
+
29
+ ## Status
30
+
31
+ Skeleton. The demo API is a single float-literal parser proving every
32
+ layer: Rust core → Rust tests → C ABI → header → linked C consumer.
33
+ Semantics follow the documented characteristics of real statement
34
+ exports; expect additive APIs at `0.x`.
35
+
36
+ ## Layout
37
+
38
+ ```
39
+ crates/statementkit core: pure functions, no I/O, no FFI types
40
+ crates/statementkit-c C ABI: status codes, out-params, panic-proofed
41
+ include/statementkit.h hand-kept header; discriminants contractual
42
+ bindings/python ctypes shim over the C ABI (pyo3 wheels later)
43
+ bindings/node raw-WASM npm package, TypeScript types included
44
+ bindings/java Panama FFM (java.lang.foreign), JDK 22+, no JNI
45
+ bindings/go cgo over the static lib, plain `go test ./...`
46
+ tests/vectors/ shared ground-truth vectors every binding runs
47
+ scripts/c-smoke.sh links tests/smoke.c against the static lib, runs it
48
+ scripts/bindings-test.sh builds all targets, runs every binding suite
49
+ ```
50
+
51
+ All parsing logic lives in the core crate only. A binding that
52
+ re-implements logic, or behaves differently from another binding, is a bug.
53
+
54
+ ## Quickstart
55
+
56
+ ```sh
57
+ cargo test --workspace # core unit + integration + FFI tests
58
+ scripts/c-smoke.sh # builds release static lib, compiles and runs C smoke
59
+ scripts/bindings-test.sh # python + go + node + java suites vs shared vectors
60
+ ```
61
+
62
+ C usage:
63
+
64
+ ```c
65
+ #include "statementkit.h"
66
+ double v;
67
+ if (sk_parse_float("12.25", &v) == SK_OK) { /* v == 12.25 */ }
68
+ ```
69
+
70
+ ## Guarantees
71
+
72
+ - No network I/O, no credentials, no telemetry — checkable in a network
73
+ namespace.
74
+ - No Rust panic ever crosses the FFI boundary (`catch_unwind` at every
75
+ entry point; `SK_PANIC` as the last-resort status).
76
+ - All test fixtures are synthetic. The library has never seen a real
77
+ statement and ships none.
78
+ - Binary float is for demo only; money handling will be exact decimal.
79
+
80
+ ## License
81
+
82
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,21 @@
1
+ Cargo.lock
2
+ Cargo.toml
3
+ LICENSE
4
+ MANIFEST.in
5
+ README.md
6
+ pyproject.toml
7
+ bindings/python/README.md
8
+ bindings/python/test_parse_float.py
9
+ bindings/python/statementkit/__init__.py
10
+ bindings/python/statementkit.egg-info/PKG-INFO
11
+ bindings/python/statementkit.egg-info/SOURCES.txt
12
+ bindings/python/statementkit.egg-info/dependency_links.txt
13
+ bindings/python/statementkit.egg-info/top_level.txt
14
+ crates/statementkit/Cargo.toml
15
+ crates/statementkit-c/Cargo.toml
16
+ crates/statementkit-c/include/statementkit.h
17
+ crates/statementkit-c/src/lib.rs
18
+ crates/statementkit-c/tests/smoke.c
19
+ crates/statementkit/src/lib.rs
20
+ crates/statementkit/tests/parse_float.rs
21
+ tests/vectors/parse_float.tsv
@@ -0,0 +1,42 @@
1
+ """Shared-vector test: bindings/python must agree with tests/vectors."""
2
+
3
+ import pathlib
4
+ import sys
5
+ import unittest
6
+
7
+ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
8
+ import statementkit # noqa: E402
9
+
10
+ VECTORS = pathlib.Path(__file__).resolve().parents[2] / "tests" / "vectors" / "parse_float.tsv"
11
+
12
+ _EXPECTS = {
13
+ "ok": None,
14
+ "empty": statementkit.EmptyInputError,
15
+ "invalid": statementkit.InvalidInputError,
16
+ "null": statementkit.NullInputError,
17
+ }
18
+
19
+
20
+ class ParseFloatVectors(unittest.TestCase):
21
+ def test_vectors(self):
22
+ rows = 0
23
+ for line in VECTORS.read_text().splitlines():
24
+ if not line or line.startswith("#"):
25
+ continue
26
+ case, text, *rest = line.split("\t")
27
+ expect = rest[0] if rest else ""
28
+ rows += 1
29
+ with self.subTest(case=case, input=text):
30
+ if case == "ok":
31
+ self.assertEqual(statementkit.parse_float(text), float(expect))
32
+ else:
33
+ with self.assertRaises(_EXPECTS[case]):
34
+ statementkit.parse_float(None if case == "null" else text)
35
+ self.assertGreaterEqual(rows, 20)
36
+
37
+ def test_version(self):
38
+ self.assertRegex(statementkit.version(), r"^\d+\.\d+\.\d+")
39
+
40
+
41
+ if __name__ == "__main__":
42
+ unittest.main()
@@ -0,0 +1,11 @@
1
+ [package]
2
+ name = "statementkit"
3
+ description = "Parse brokerage statement content into actionable numbers"
4
+ version.workspace = true
5
+ edition.workspace = true
6
+ license.workspace = true
7
+ rust-version.workspace = true
8
+ repository = "https://github.com/heshiming/statementkit"
9
+ readme = "../../README.md"
10
+
11
+ [dependencies]
@@ -0,0 +1,77 @@
1
+ //! statementkit core: parsing brokerage statement content into numbers.
2
+ //!
3
+ //! Pure functions only — no I/O, no FFI types. All parsing and derivation
4
+ //! logic lives in this crate; bindings are thin shells over it.
5
+ //!
6
+ //! Independent tool. Not affiliated with or endorsed by Interactive
7
+ //! Brokers LLC.
8
+
9
+ /// Failure reasons for numeric parsing.
10
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11
+ pub enum Error {
12
+ /// Input was empty after trimming.
13
+ Empty,
14
+ /// Input was not a finite bare number.
15
+ Invalid,
16
+ }
17
+
18
+ /// Parse a bare decimal float literal into f64.
19
+ ///
20
+ /// Trims surrounding whitespace; rejects empty input, non-numeric text,
21
+ /// and non-finite values (`NaN` and infinities appear verbatim as cell
22
+ /// strings in real statement exports and must not enter arithmetic).
23
+ /// Separators, parentheses-negatives and percent forms are later
24
+ /// milestones; until then they parse as Invalid.
25
+ ///
26
+ /// This is a skeleton demo returning binary float. Money values will use
27
+ /// an exact decimal type; do not route money through this function.
28
+ pub fn parse_float(input: &str) -> Result<f64, Error> {
29
+ let text = input.trim();
30
+ if text.is_empty() {
31
+ return Err(Error::Empty);
32
+ }
33
+ let value = text.parse::<f64>().map_err(|_| Error::Invalid)?;
34
+ if value.is_finite() {
35
+ Ok(value)
36
+ } else {
37
+ Err(Error::Invalid)
38
+ }
39
+ }
40
+
41
+ #[cfg(test)]
42
+ mod tests {
43
+ use super::{Error, parse_float};
44
+
45
+ #[test]
46
+ fn parses_plain_literals() {
47
+ for (text, want) in [
48
+ ("0", 0.0),
49
+ ("8.5", 8.5),
50
+ ("-0.5", -0.5),
51
+ ("+2.5", 2.5),
52
+ ("1e3", 1000.0),
53
+ ("-2.5E-3", -0.0025),
54
+ ("7.", 7.0),
55
+ (".5", 0.5),
56
+ (" 42.0 ", 42.0),
57
+ ] {
58
+ assert_eq!(parse_float(text), Ok(want), "input: {text:?}");
59
+ }
60
+ }
61
+
62
+ #[test]
63
+ fn rejects_empty() {
64
+ assert_eq!(parse_float(""), Err(Error::Empty));
65
+ assert_eq!(parse_float(" "), Err(Error::Empty));
66
+ }
67
+
68
+ #[test]
69
+ fn rejects_invalid() {
70
+ for text in [
71
+ "abc", "1,234.56", "1.2.3", "0x10", "1 2", "(1.5)", "5%", "NaN", "nan", "inf", "-inf",
72
+ "infinity",
73
+ ] {
74
+ assert_eq!(parse_float(text), Err(Error::Invalid), "input: {text:?}");
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,26 @@
1
+ use statementkit::{Error, parse_float};
2
+
3
+ // Ground truth for the CSV extraction path, synthetic vectors only.
4
+
5
+ #[test]
6
+ fn float_vectors() {
7
+ let ok: &[(&str, f64)] = &[
8
+ ("12.25", 12.25),
9
+ ("-1040.02", -1040.02),
10
+ ("0.000001", 0.000001),
11
+ ("176.4", 176.4),
12
+ ];
13
+ for (text, want) in ok {
14
+ assert_eq!(parse_float(text), Ok(*want), "input: {text:?}");
15
+ }
16
+
17
+ let empty: &[&str] = &["", " \t "];
18
+ for text in empty {
19
+ assert_eq!(parse_float(text), Err(Error::Empty), "input: {text:?}");
20
+ }
21
+
22
+ let invalid: &[&str] = &["n/a", "1,234", "1..2", "NaN", "inf", "3.5x"];
23
+ for text in invalid {
24
+ assert_eq!(parse_float(text), Err(Error::Invalid), "input: {text:?}");
25
+ }
26
+ }
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "statementkit-c"
3
+ description = "C ABI for statementkit"
4
+ version.workspace = true
5
+ edition.workspace = true
6
+ license.workspace = true
7
+ rust-version.workspace = true
8
+ publish = false
9
+
10
+ [lib]
11
+ crate-type = ["cdylib", "staticlib", "rlib"]
12
+
13
+ [dependencies]
14
+ statementkit = { path = "../statementkit" }
@@ -0,0 +1,30 @@
1
+ /* Hand-maintained mirror of crates/statementkit-c/src/lib.rs.
2
+ Discriminant values are contractual — keep in sync.
3
+ Nothing returned by this library is to be freed by the caller. */
4
+ #ifndef STATEMENTKIT_H
5
+ #define STATEMENTKIT_H
6
+
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+
11
+ typedef enum SkStatus {
12
+ SK_OK = 0,
13
+ SK_NULL_INPUT = 1,
14
+ SK_EMPTY = 2,
15
+ SK_INVALID = 3,
16
+ SK_PANIC = 4
17
+ } SkStatus;
18
+
19
+ /* Parse a NUL-terminated float literal into *out.
20
+ Returns SK_OK on success; input/out may not be NULL. */
21
+ SkStatus sk_parse_float(const char *input, double *out);
22
+
23
+ /* Library version, static string. Do not free. */
24
+ const char *sk_version(void);
25
+
26
+ #ifdef __cplusplus
27
+ }
28
+ #endif
29
+
30
+ #endif /* STATEMENTKIT_H */
@@ -0,0 +1,129 @@
1
+ //! C ABI for statementkit.
2
+ //!
3
+ //! Contract (mirrored by hand in `include/statementkit.h` — the numeric
4
+ //! discriminants are contractual): status codes only, no Rust panic may
5
+ //! unwind into C, caller never frees anything this library returns.
6
+
7
+ use std::ffi::CStr;
8
+ use std::os::raw::c_char;
9
+ use std::panic::{AssertUnwindSafe, catch_unwind};
10
+
11
+ use statementkit::{Error, parse_float};
12
+
13
+ /// Result codes. Keep in sync with `SkStatus` in the header.
14
+ #[repr(C)]
15
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
16
+ pub enum SkStatus {
17
+ Ok = 0,
18
+ NullInput = 1,
19
+ Empty = 2,
20
+ Invalid = 3,
21
+ /// An internal Rust panic was caught at the boundary.
22
+ Panic = 4,
23
+ }
24
+
25
+ /// Parse a NUL-terminated float literal; writes the value to `out`.
26
+ ///
27
+ /// Returns `SK_OK` (0) on success. `input` or `out` null is `SK_NULL_INPUT`.
28
+ ///
29
+ /// # Safety
30
+ /// `input` must be null or a valid NUL-terminated C string; `out` must be
31
+ /// null or a writable `double`.
32
+ #[unsafe(no_mangle)]
33
+ pub unsafe extern "C" fn sk_parse_float(input: *const c_char, out: *mut f64) -> SkStatus {
34
+ let guarded = catch_unwind(AssertUnwindSafe(|| {
35
+ if input.is_null() || out.is_null() {
36
+ return SkStatus::NullInput;
37
+ }
38
+ let text = match unsafe { CStr::from_ptr(input) }.to_str() {
39
+ Ok(text) => text,
40
+ Err(_) => return SkStatus::Invalid,
41
+ };
42
+ match parse_float(text) {
43
+ Ok(value) => {
44
+ unsafe { *out = value };
45
+ SkStatus::Ok
46
+ }
47
+ Err(Error::Empty) => SkStatus::Empty,
48
+ Err(Error::Invalid) => SkStatus::Invalid,
49
+ }
50
+ }));
51
+ guarded.unwrap_or(SkStatus::Panic)
52
+ }
53
+
54
+ /// Library version as a static NUL-terminated string. Do not free.
55
+ static VERSION: &[u8] = concat!(env!("CARGO_PKG_VERSION"), "\0").as_bytes();
56
+
57
+ #[unsafe(no_mangle)]
58
+ pub extern "C" fn sk_version() -> *const c_char {
59
+ VERSION.as_ptr().cast()
60
+ }
61
+
62
+ // Raw-wasm callers (JS loader) need to place bytes in linear memory and
63
+ // cannot use libc malloc. Native targets are unaffected.
64
+ #[cfg(target_arch = "wasm32")]
65
+ #[unsafe(no_mangle)]
66
+ pub extern "C" fn sk_wasm_alloc(len: usize) -> *mut u8 {
67
+ match std::alloc::Layout::from_size_align(len, 8) {
68
+ Ok(layout) => unsafe { std::alloc::alloc(layout) },
69
+ Err(_) => std::ptr::null_mut(), // size overflow; caller checks null
70
+ }
71
+ }
72
+
73
+ #[cfg(target_arch = "wasm32")]
74
+ #[unsafe(no_mangle)]
75
+ pub extern "C" fn sk_wasm_free(ptr: *mut u8, len: usize) {
76
+ if !ptr.is_null() {
77
+ if let Ok(layout) = std::alloc::Layout::from_size_align(len, 8) {
78
+ unsafe { std::alloc::dealloc(ptr, layout) };
79
+ }
80
+ }
81
+ }
82
+
83
+ #[cfg(test)]
84
+ mod tests {
85
+ use super::*;
86
+
87
+ fn parse(input: *const c_char) -> (SkStatus, f64) {
88
+ let mut out = f64::NAN;
89
+ let status = unsafe { sk_parse_float(input, &mut out) };
90
+ (status, out)
91
+ }
92
+
93
+ #[test]
94
+ fn ffi_round_trip() {
95
+ let (status, value) = parse(c"-3.5e2".as_ptr());
96
+ assert_eq!((status, value), (SkStatus::Ok, -350.0));
97
+
98
+ assert_eq!(parse(c"".as_ptr()).0, SkStatus::Empty);
99
+ assert_eq!(parse(c"1,000".as_ptr()).0, SkStatus::Invalid);
100
+ assert_eq!(parse(c"NaN".as_ptr()).0, SkStatus::Invalid);
101
+ }
102
+
103
+ #[test]
104
+ fn ffi_null_inputs() {
105
+ let null = std::ptr::null();
106
+ let null_mut = std::ptr::null_mut();
107
+ unsafe {
108
+ assert_eq!(sk_parse_float(null, null_mut), SkStatus::NullInput);
109
+ let mut out = 0.0;
110
+ assert_eq!(sk_parse_float(null, &mut out), SkStatus::NullInput);
111
+ assert_eq!(
112
+ sk_parse_float(c"1.0".as_ptr(), null_mut),
113
+ SkStatus::NullInput
114
+ );
115
+ }
116
+ }
117
+
118
+ #[test]
119
+ fn ffi_rejects_non_utf8() {
120
+ let bad = [0xFFu8, 0x00];
121
+ assert_eq!(parse(bad.as_ptr().cast()).0, SkStatus::Invalid);
122
+ }
123
+
124
+ #[test]
125
+ fn version_is_set() {
126
+ let version = unsafe { CStr::from_ptr(sk_version()) };
127
+ assert_eq!(version.to_str().unwrap(), env!("CARGO_PKG_VERSION"));
128
+ }
129
+ }
@@ -0,0 +1,50 @@
1
+ /* End-to-end C consumer of the statementkit static library. */
2
+ #include <math.h>
3
+ #include <stdio.h>
4
+ #include <stdlib.h>
5
+ #include <string.h>
6
+
7
+ #include "statementkit.h"
8
+
9
+ static int failures = 0;
10
+
11
+ static void expect_ok(const char *in, double want) {
12
+ double got = NAN;
13
+ SkStatus st = sk_parse_float(in, &got);
14
+ if (st != SK_OK || got != want) {
15
+ printf("FAIL sk_parse_float(%s): status=%d got=%g want=%g\n", in, st, got, want);
16
+ failures++;
17
+ }
18
+ }
19
+
20
+ static void expect_status(const char *in, SkStatus want) {
21
+ double got = NAN;
22
+ SkStatus st = sk_parse_float(in, &got);
23
+ if (st != want) {
24
+ printf("FAIL sk_parse_float(%s): status=%d want=%d\n", in, st, want);
25
+ failures++;
26
+ }
27
+ }
28
+
29
+ int main(void) {
30
+ expect_ok("12.25", 12.25);
31
+ expect_ok("-0.5", -0.5);
32
+ expect_ok("1e3", 1000.0);
33
+ expect_ok(" 42 ", 42.0);
34
+ expect_status("", SK_EMPTY);
35
+ expect_status(" ", SK_EMPTY);
36
+ expect_status("1,234.56", SK_INVALID);
37
+ expect_status("NaN", SK_INVALID);
38
+ expect_status(NULL, SK_NULL_INPUT);
39
+
40
+ if (strlen(sk_version()) == 0) {
41
+ printf("FAIL sk_version empty\n");
42
+ failures++;
43
+ }
44
+ if (failures) {
45
+ printf("c-smoke: %d failure(s)\n", failures);
46
+ return 1;
47
+ }
48
+ printf("c-smoke: all assertions passed\n");
49
+ return 0;
50
+ }
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "setuptools-rust>=1.10"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "statementkit"
7
+ version = "0.1.0" # keep in step with the Cargo workspace version
8
+ description = "Parse brokerage statement content into actionable numbers. Independent tool. Not affiliated with or endorsed by Interactive Brokers LLC."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "heshiming" }]
13
+ keywords = ["brokerage", "statements", "parsing", "finance"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Rust",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Software Development :: Libraries",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/heshiming/statementkit"
24
+ Repository = "https://github.com/heshiming/statementkit"
25
+
26
+ # The ctypes shim lives in bindings/python; this root project only packages it.
27
+ [tool.setuptools]
28
+ package-dir = { "" = "bindings/python" }
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["bindings/python"]
32
+
33
+ # Bundles the C ABI cdylib into the package; the ctypes shim loads it from
34
+ # its own dir. NoBinding: no Python-API symbols, loaded only via ctypes.
35
+ [[tool.setuptools-rust.ext-modules]]
36
+ target = "statementkit._statementkit_c"
37
+ path = "crates/statementkit-c/Cargo.toml"
38
+ binding = "NoBinding"
39
+ cargo_manifest_args = ["--locked"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,30 @@
1
+ # Shared binding test vectors — synthetic only.
2
+ # Tab-separated, 3 columns: case \t input \t expect_value (value empty unless ok).
3
+ # case: ok | empty | invalid | null (null: input column unused; each
4
+ # binding maps null-ish input to NullInput/IllegalArgumentException per docs).
5
+ # Rows whose input is a lone backslash-u2026 aside, inputs contain no tabs.
6
+ # This file mirrors the Rust core vectors; a binding that disagrees has a bug.
7
+ ok 12.25 12.25
8
+ ok -0.5 -0.5
9
+ ok +2.5 2.5
10
+ ok 1e3 1000.0
11
+ ok 42.0 42.0
12
+ ok -2.5E-3 -0.0025
13
+ ok 7. 7.0
14
+ ok .5 0.5
15
+ empty
16
+ empty
17
+ invalid abc
18
+ invalid 1,234.56
19
+ invalid 1.2.3
20
+ invalid 0x10
21
+ invalid 1 2
22
+ invalid (1.5)
23
+ invalid 5%
24
+ invalid NaN
25
+ invalid nan
26
+ invalid inf
27
+ invalid -inf
28
+ invalid infinity
29
+ invalid 3.5x
30
+ null