rosenbound 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,20 @@
1
+ # Build + packaging artifacts
2
+ build/
3
+ dist/
4
+ *.egg-info/
5
+ *.egg
6
+
7
+ # Bytecode + caches
8
+ __pycache__/
9
+ *.py[cod]
10
+ .pytest_cache/
11
+ .mypy_cache/
12
+ .ruff_cache/
13
+ .coverage
14
+ htmlcov/
15
+
16
+ # The repo-root code/.gitignore ignores all *.csv. Re-include the committed
17
+ # test fixture (leading slash anchors the negation to this directory so it
18
+ # does not over-match nested paths). Parent dirs are not excluded, so the
19
+ # re-inclusion takes effect.
20
+ !/tests/fixtures/cohort_5k_pv.csv
@@ -0,0 +1,204 @@
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.
203
+
204
+ Copyright 2026 Harsh Singh / Rosenbound
@@ -0,0 +1,314 @@
1
+ Metadata-Version: 2.4
2
+ Name: rosenbound
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for the Rosenbound clinical-AI platform
5
+ Project-URL: Homepage, https://rosenbound.com
6
+ Project-URL: Documentation, https://rosenbound.com/docs/sdk/python
7
+ Author-email: Harsh Singh <harshrajput618@gmail.com>
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: causal-inference,clinical-ai,pharmacovigilance,rosenbound,sdk
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Healthcare Industry
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: httpx>=0.26
21
+ Requires-Dist: pydantic>=2.5
22
+ Requires-Dist: typing-extensions>=4.8
23
+ Provides-Extra: dev
24
+ Requires-Dist: mypy>=1.9; extra == 'dev'
25
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
26
+ Requires-Dist: pytest>=8.0; extra == 'dev'
27
+ Requires-Dist: ruff>=0.6; extra == 'dev'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # rosenbound
31
+
32
+ Official Python SDK for the **Rosenbound** clinical-AI platform — a causal,
33
+ auditable clinical decision-support platform for structured medical and
34
+ pharmacological data.
35
+
36
+ The SDK is a typed, Pydantic-based wrapper over the platform's REST API
37
+ (platform API **v1**). It is sync-first; an asynchronous client is reserved for
38
+ a future release.
39
+
40
+ > **Status — v0.1.0 (alpha).** This release implements the **Cohorts**
41
+ > (list / get / create), **Studies** (list / get / create / run / results), and
42
+ > **Certificates** (reproducibility certificate + methodology PDF) surfaces —
43
+ > the full cohort → study → run → result → certificate loop. An asynchronous
44
+ > client, SSO auth, certificate-chain `verify()`, and per-feature resources
45
+ > (MedDRA, E2B, drug-coder, …) are reserved for a future release.
46
+
47
+ ---
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install rosenbound
53
+ ```
54
+
55
+ Requires Python ≥ 3.10. Runtime dependencies: `httpx`, `pydantic` (v2),
56
+ `typing-extensions`.
57
+
58
+ During pre-release the package installs from a local checkout:
59
+
60
+ ```bash
61
+ cd code/sdk/python
62
+ pip install -e ".[dev]"
63
+ ```
64
+
65
+ ## Authentication
66
+
67
+ The SDK authenticates with a platform **API token**, sent on every request as
68
+ `Authorization: Bearer <token>`. Tokens are issued from the in-product API-key
69
+ management surface (which requires an admin role). The token is opaque to the
70
+ SDK; the platform validates it and resolves your tenant + role from it.
71
+
72
+ ```python
73
+ from rosenbound import Client
74
+
75
+ client = Client(api_key="rk_your_token_here")
76
+ ```
77
+
78
+ By default the client talks to `https://api.rosenbound.com`. Point it elsewhere
79
+ (e.g. a staging host) with `base_url`:
80
+
81
+ ```python
82
+ client = Client(api_key="rk_...", base_url="https://staging.api.rosenbound.com")
83
+ ```
84
+
85
+ ## Quick start — cohorts
86
+
87
+ ```python
88
+ from rosenbound import Client
89
+
90
+ with Client(api_key="rk_...") as client:
91
+ # Create a cohort from a CSV file plus a cohort-definition DSL.
92
+ cohort = client.cohorts.create(
93
+ name="metformin_t2dm_2026",
94
+ archetype="treatment_policy",
95
+ dsl_yaml="path/to/definition.yaml", # YAML text or a Path to a file
96
+ csv_path="my_cohort.csv",
97
+ )
98
+ print(cohort.id, cohort.status)
99
+
100
+ # List cohorts (paginated, filterable by archetype + name search).
101
+ page = client.cohorts.list(archetype="treatment_policy", page=1, page_size=50)
102
+ print(f"{len(page.items)} of {page.total} cohorts")
103
+ for c in page.items:
104
+ print(c.id, c.name, c.archetype)
105
+
106
+ # Fetch one cohort by id.
107
+ detail = client.cohorts.get(cohort.id)
108
+ print(detail.cohort_def_hash, detail.data_hash)
109
+ ```
110
+
111
+ ### Cohort archetypes
112
+
113
+ `archetype` is one of:
114
+
115
+ | value | meaning |
116
+ |---|---|
117
+ | `pv` | pharmacovigilance pentagon cohort |
118
+ | `longitudinal` | repeated-measures / longitudinal cohort |
119
+ | `treatment_policy` | treatment-policy (A-vs-B) cohort |
120
+ | `time_to_event` | survival / time-to-event cohort |
121
+
122
+ The `dsl_yaml` cohort definition must validate against the chosen archetype,
123
+ and every column it references must exist in the uploaded CSV header — the
124
+ platform rejects a mismatch with a `ValidationError` at upload time.
125
+
126
+ ## Studies
127
+
128
+ A study runs a causal protocol against a cohort and produces a 5-method
129
+ (Pentagon) estimate set. The workflow is **create → run → fetch results**:
130
+
131
+ ```python
132
+ with Client(api_key="rk_...") as client:
133
+ study = client.studies.create(
134
+ cohort_id=cohort.id,
135
+ protocol_id="pv_pentagon",
136
+ estimator_selection={}, # per-protocol config; {} = protocol defaults
137
+ )
138
+ print(study.id, study.status) # -> "draft"
139
+
140
+ # run() executes synchronously: it returns once the Pentagon run reaches a
141
+ # terminal state, so the returned study is normally status="complete".
142
+ completed = client.studies.run(study.id, seed=17) # seed pins reproducibility
143
+ print(completed.status) # -> "complete"
144
+
145
+ result = client.studies.get_results(study.id)
146
+ print(result.pentagon_result_payload) # the full 5-method estimate set
147
+
148
+ # List + filter (single status value, optional cohort filter, paginated).
149
+ page = client.studies.list(cohort_id=cohort.id, status="complete")
150
+ print(f"{len(page.items)} of {page.total} studies")
151
+ ```
152
+
153
+ `protocol_id` is one of:
154
+
155
+ | value | meaning |
156
+ |---|---|
157
+ | `pv_pentagon` | pharmacovigilance 5-method Pentagon |
158
+ | `cr_longitudinal` | clinical-research longitudinal protocol |
159
+ | `cr_treatment_policy` | treatment-policy (A-vs-B) protocol |
160
+ | `cr_tte` | time-to-event / survival protocol |
161
+
162
+ `run()` is synchronous today. If a run is already in progress it raises
163
+ `ConflictError` (409); a server-side run failure raises `ServerError` (500).
164
+ When the platform later adds an asynchronous job model, a blocking
165
+ `wait_for_completion` poller will land alongside the async client (v0.2).
166
+
167
+ ## Certificates
168
+
169
+ Every completed run mints a **reproducibility certificate** — the hashes and
170
+ environment pins an external auditor re-derives the result from. The
171
+ certificate is embedded in the study response; `certificates.get()` surfaces it:
172
+
173
+ ```python
174
+ with Client(api_key="rk_...") as client:
175
+ cert = client.certificates.get(study.id)
176
+ print(cert.code_version) # the code version that produced the result
177
+ print(cert.cohort_def_yaml_hash, cert.cohort_data_hash)
178
+ print(cert.library_versions) # {package: version} pin map
179
+ print(cert.generated_at)
180
+
181
+ # Download the human-readable methodology PDF.
182
+ client.certificates.download_pdf(study.id, output_path="methodology.pdf")
183
+ ```
184
+
185
+ | field | meaning |
186
+ |---|---|
187
+ | `cohort_def_yaml_hash` | SHA-256 of the cohort-definition YAML |
188
+ | `cohort_data_hash` | SHA-256 of the input cohort data |
189
+ | `code_version` | resolved code version (git SHA) that produced the result |
190
+ | `library_versions` | `{package: version}` environment pin map |
191
+ | `generated_at` | server-side timestamp the certificate was minted |
192
+
193
+ `certificates.get()` raises `NotFoundError` if the study has no completed run
194
+ yet. `download_pdf()` raises `ServerError` if the methodology PDF has not been
195
+ materialized for the latest run (the platform returns 503 until the generator
196
+ has produced the artifact). Re-validating the certificate chain against the
197
+ platform's authoritative ledger — `certificates.verify()` — is a v0.2 stub that
198
+ currently raises `NotImplementedError`.
199
+
200
+ ## End-to-end example
201
+
202
+ The full loop in one block — upload a cohort, define and run a study, read the
203
+ result, and fetch its reproducibility certificate:
204
+
205
+ ```python
206
+ from rosenbound import Client
207
+
208
+ with Client(api_key="rk_...") as client:
209
+ cohort = client.cohorts.create(
210
+ name="metformin_t2dm_2026",
211
+ archetype="treatment_policy",
212
+ dsl_yaml="definition.yaml",
213
+ csv_path="my_cohort.csv",
214
+ )
215
+ study = client.studies.create(
216
+ cohort_id=cohort.id,
217
+ protocol_id="pv_pentagon",
218
+ )
219
+ client.studies.run(study.id, seed=17)
220
+ result = client.studies.get_results(study.id)
221
+ cert = client.certificates.get(study.id)
222
+
223
+ print("estimates:", result.pentagon_result_payload)
224
+ print("reproducible under code version:", cert.code_version)
225
+ ```
226
+
227
+ ## Error handling
228
+
229
+ Every SDK error derives from `RosenboundError`. The HTTP layer maps response
230
+ status codes to specific subclasses:
231
+
232
+ ```python
233
+ from rosenbound import (
234
+ Client,
235
+ AuthenticationError, # 401 — invalid / missing API key
236
+ NotFoundError, # 404 — absent, or not visible to your tenant
237
+ ValidationError, # 422 — payload rejected (carries .errors)
238
+ ConflictError, # 409 — state conflict (e.g. study already running)
239
+ RateLimitError, # 429 — rate limit (carries .retry_after_seconds)
240
+ ServerError, # 5xx — platform fault, after retries are exhausted
241
+ RosenboundError, # base class — catch-all
242
+ )
243
+
244
+ with Client(api_key="rk_...") as client:
245
+ try:
246
+ client.cohorts.create(
247
+ name="bad",
248
+ archetype="pv",
249
+ dsl_yaml=open("definition.yaml").read(),
250
+ csv_path="cohort.csv",
251
+ )
252
+ except ValidationError as exc:
253
+ for err in exc.errors: # the platform's structured error body
254
+ print(err)
255
+ except RateLimitError as exc:
256
+ print("retry after", exc.retry_after_seconds, "s")
257
+ ```
258
+
259
+ A 404 means "not found *for you*" — the platform returns 404 (never 403) for
260
+ cross-tenant reads so resource existence never leaks across tenants.
261
+
262
+ ## Retries and timeouts
263
+
264
+ The client retries transient failures (HTTP **429** and **5xx**) up to
265
+ `max_retries` times with deterministic exponential backoff
266
+ (`0.5 * 2 ** attempt` seconds). A `429` carrying a numeric `Retry-After` header
267
+ honors that value instead. Non-retryable errors (4xx other than 429) raise
268
+ immediately.
269
+
270
+ ```python
271
+ client = Client(
272
+ api_key="rk_...",
273
+ timeout=30.0, # per-request timeout, seconds (default 30)
274
+ max_retries=3, # additional attempts on 429 / 5xx (default 3)
275
+ )
276
+ ```
277
+
278
+ Network-layer failures (connection refused, DNS, read timeout) propagate as the
279
+ underlying `httpx` transport exceptions and are not wrapped.
280
+
281
+ ## Resource management
282
+
283
+ `Client` owns a connection pool. Use it as a context manager, or call
284
+ `close()` explicitly:
285
+
286
+ ```python
287
+ with Client(api_key="rk_...") as client:
288
+ ... # pool is released on exit
289
+
290
+ # or
291
+ client = Client(api_key="rk_...")
292
+ try:
293
+ ...
294
+ finally:
295
+ client.close()
296
+ ```
297
+
298
+ A single client is safe for serial use from one thread; construct one client
299
+ per thread for concurrent use.
300
+
301
+ ## Compatibility
302
+
303
+ - Python: ≥ 3.10
304
+ - Platform API: v1
305
+ - Concurrency: synchronous client only (async reserved for v0.2)
306
+ - SDK version: see `rosenbound.__version__`
307
+
308
+ ## License
309
+
310
+ Apache-2.0. See [LICENSE](./LICENSE).
311
+
312
+ ## Contact
313
+
314
+ Issues and questions: the Rosenbound platform team.