stormedo 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.
stormedo-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stormedo contributors
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,220 @@
1
+ Metadata-Version: 2.4
2
+ Name: stormedo
3
+ Version: 0.1.0
4
+ Summary: Send durable HTTP requests and verify Stormedo deliveries
5
+ Author: Stormedo
6
+ Author-email: Stormedo <dev@stormedo.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Requires-Dist: cryptography>=50.0.0
11
+ Requires-Dist: httpx>=0.28.1
12
+ Requires-Dist: typing-extensions>=4.4
13
+ Requires-Python: >=3.10
14
+ Project-URL: Homepage, https://stormedo.com
15
+ Project-URL: Documentation, https://stormedo.com/docs/sdks/python/
16
+ Project-URL: Source, https://github.com/stormedo/sdk/tree/main/python
17
+ Description-Content-Type: text/markdown
18
+
19
+ # Stormedo Python SDK
20
+
21
+ This package sends durable HTTP requests through Stormedo and authenticates or
22
+ verifies signed deliveries from Stormedo. It supports Python 3.10 and newer.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ uv add stormedo
28
+ ```
29
+
30
+ ## Send requests
31
+
32
+ Use `Stormedo` in synchronous applications:
33
+
34
+ ```python
35
+ import os
36
+ from datetime import timedelta
37
+
38
+ from stormedo import Stormedo
39
+
40
+ stormedo = Stormedo(os.environ["STORMEDO_TOKEN"])
41
+ request = stormedo.send(
42
+ "https://example.com/webhook",
43
+ body={"message": "hello from Stormedo"},
44
+ delay=timedelta(minutes=5),
45
+ max_attempts=5,
46
+ )
47
+ ```
48
+
49
+ Use `AsyncStormedo` when the application already runs an event loop:
50
+
51
+ ```python
52
+ import os
53
+
54
+ from stormedo import AsyncStormedo
55
+
56
+ async_stormedo = AsyncStormedo(os.environ["STORMEDO_TOKEN"])
57
+ request = await async_stormedo.send(
58
+ "https://example.com/webhook",
59
+ body={"message": "hello from Stormedo"},
60
+ )
61
+ ```
62
+
63
+ Create one client, reuse it, and call `close()` or `aclose()` during application
64
+ shutdown.
65
+
66
+ Use `raw_body` when bytes must be sent unchanged. Headers supplied in `headers`
67
+ are sent to the destination. Stormedo never forwards the project API key.
68
+
69
+ ```python
70
+ request = stormedo.send(
71
+ "https://example.com/events",
72
+ raw_body=b"event=created",
73
+ content_type="application/x-www-form-urlencoded",
74
+ headers={"Authorization": "Bearer destination-token"},
75
+ )
76
+ ```
77
+
78
+ Batch items use `BatchRequest` values instead of dictionaries:
79
+
80
+ ```python
81
+ from datetime import timedelta
82
+
83
+ from stormedo import BatchRequest
84
+
85
+ requests = stormedo.send_batch(
86
+ [
87
+ BatchRequest(
88
+ url="https://example.com/orders",
89
+ body={"order_id": "ord_123"},
90
+ ),
91
+ BatchRequest(
92
+ url="https://example.com/inventory",
93
+ body={"warehouse_id": "wh_7"},
94
+ delay=timedelta(hours=1),
95
+ ),
96
+ ]
97
+ )
98
+ ```
99
+
100
+ `delay` and `timeout` accept `timedelta`. `deliver_at` accepts a timezone-aware
101
+ `datetime`.
102
+
103
+ The synchronous and asynchronous clients expose the same operations:
104
+
105
+ - `send` and `send_batch`
106
+ - `list_requests`, `get_request`, `list_request_attempts`, `cancel_request`,
107
+ and `replay_request`
108
+ - `create_schedule`, `list_schedules`, `get_schedule`, `update_schedule`,
109
+ `pause_schedule`, `resume_schedule`, and `delete_schedule`
110
+
111
+ Create schedules with a timing helper instead of constructing the API payload:
112
+
113
+ ```python
114
+ from datetime import timedelta
115
+
116
+ from stormedo import cron_timing, interval_timing
117
+
118
+ schedule = stormedo.create_schedule(
119
+ name="sync-inventory",
120
+ timing=cron_timing("0 */6 * * *", "Asia/Kolkata"),
121
+ url="https://example.com/inventory/sync",
122
+ body={"full_sync": True},
123
+ max_attempts=4,
124
+ )
125
+
126
+ stormedo.update_schedule(
127
+ schedule.id,
128
+ timing=interval_timing(timedelta(hours=4)),
129
+ )
130
+ ```
131
+
132
+ `cron_timing` accepts a five-field cron expression and an IANA timezone.
133
+ `interval_timing` accepts a `timedelta` containing a whole number of minutes
134
+ from one minute through 30 days. Pass a future timezone-aware `datetime` as
135
+ `starts_at` to choose the first run time.
136
+
137
+ ## Configure delivery verification
138
+
139
+ Create one verifier with the project ID and reuse it across requests:
140
+
141
+ ```python
142
+ import os
143
+
144
+ from stormedo import DeliveryVerifier
145
+
146
+ project_id = os.environ["STORMEDO_PROJECT_ID"]
147
+ verifier = DeliveryVerifier(project_id)
148
+ ```
149
+
150
+ For asynchronous applications:
151
+
152
+ ```python
153
+ from stormedo import AsyncDeliveryVerifier
154
+
155
+ async_verifier = AsyncDeliveryVerifier(project_id)
156
+ ```
157
+
158
+ ## Authenticate without checking the body
159
+
160
+ Use `authenticate_delivery` when the platform cannot provide the raw body. It
161
+ authenticates Stormedo and the request context but does not prove payload
162
+ integrity.
163
+
164
+ ```python
165
+ delivery = verifier.authenticate_delivery(
166
+ signature=signature,
167
+ request_id=request_id,
168
+ expected_url="https://example.com/webhooks/stormedo",
169
+ method="POST",
170
+ )
171
+
172
+ assert delivery.payload_integrity == "unchecked"
173
+ ```
174
+
175
+ ## Verify the exact body
176
+
177
+ Use `verify_delivery` when the receiver can capture the exact raw bytes before
178
+ a JSON or form parser changes them:
179
+
180
+ ```python
181
+ delivery = verifier.verify_delivery(
182
+ signature=signature,
183
+ request_id=request_id,
184
+ expected_url="https://example.com/webhooks/stormedo",
185
+ method="POST",
186
+ raw_body=raw_body,
187
+ )
188
+
189
+ assert delivery.payload_integrity == "verified"
190
+ ```
191
+
192
+ ## Receiver responsibilities
193
+
194
+ - Reject missing or duplicated `Stormedo-Signature` and
195
+ `Stormedo-Request-Id` headers before calling the core verifier.
196
+ - Treat `Stormedo-Attempt` and `Stormedo-Max-Attempts` as unsigned hints.
197
+ The signature does not cover them, so do not rely on them for security
198
+ decisions.
199
+ - Supply the complete public destination URL from trusted configuration. Do not
200
+ trust forwarded request headers unless the application has an explicit proxy
201
+ trust boundary.
202
+ - Authenticate or verify at ingress while the delivery token is current.
203
+ - Parse the application body only after `verify_delivery` succeeds when payload
204
+ integrity is required.
205
+
206
+ ## Errors
207
+
208
+ Stormedo API and network failures raise `StormedoError`. Use `code` for program
209
+ logic and `request_id` when contacting Stormedo support. A response that does
210
+ not match the expected shape raises `StormedoError` with code
211
+ `invalid_response`.
212
+
213
+ New values may appear in enum fields such as `status`, `method`, and
214
+ `retry.reason`. Their types list the known values, but handle unknown values,
215
+ for example with a fallback branch.
216
+ A schedule timing type that this SDK version does not know keeps its raw
217
+ `timing.type` string, with the cron and interval fields set to `None`.
218
+
219
+ Verification failures raise `DeliveryVerificationError`. Use its `code` to
220
+ handle the failure.
@@ -0,0 +1,202 @@
1
+ # Stormedo Python SDK
2
+
3
+ This package sends durable HTTP requests through Stormedo and authenticates or
4
+ verifies signed deliveries from Stormedo. It supports Python 3.10 and newer.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ uv add stormedo
10
+ ```
11
+
12
+ ## Send requests
13
+
14
+ Use `Stormedo` in synchronous applications:
15
+
16
+ ```python
17
+ import os
18
+ from datetime import timedelta
19
+
20
+ from stormedo import Stormedo
21
+
22
+ stormedo = Stormedo(os.environ["STORMEDO_TOKEN"])
23
+ request = stormedo.send(
24
+ "https://example.com/webhook",
25
+ body={"message": "hello from Stormedo"},
26
+ delay=timedelta(minutes=5),
27
+ max_attempts=5,
28
+ )
29
+ ```
30
+
31
+ Use `AsyncStormedo` when the application already runs an event loop:
32
+
33
+ ```python
34
+ import os
35
+
36
+ from stormedo import AsyncStormedo
37
+
38
+ async_stormedo = AsyncStormedo(os.environ["STORMEDO_TOKEN"])
39
+ request = await async_stormedo.send(
40
+ "https://example.com/webhook",
41
+ body={"message": "hello from Stormedo"},
42
+ )
43
+ ```
44
+
45
+ Create one client, reuse it, and call `close()` or `aclose()` during application
46
+ shutdown.
47
+
48
+ Use `raw_body` when bytes must be sent unchanged. Headers supplied in `headers`
49
+ are sent to the destination. Stormedo never forwards the project API key.
50
+
51
+ ```python
52
+ request = stormedo.send(
53
+ "https://example.com/events",
54
+ raw_body=b"event=created",
55
+ content_type="application/x-www-form-urlencoded",
56
+ headers={"Authorization": "Bearer destination-token"},
57
+ )
58
+ ```
59
+
60
+ Batch items use `BatchRequest` values instead of dictionaries:
61
+
62
+ ```python
63
+ from datetime import timedelta
64
+
65
+ from stormedo import BatchRequest
66
+
67
+ requests = stormedo.send_batch(
68
+ [
69
+ BatchRequest(
70
+ url="https://example.com/orders",
71
+ body={"order_id": "ord_123"},
72
+ ),
73
+ BatchRequest(
74
+ url="https://example.com/inventory",
75
+ body={"warehouse_id": "wh_7"},
76
+ delay=timedelta(hours=1),
77
+ ),
78
+ ]
79
+ )
80
+ ```
81
+
82
+ `delay` and `timeout` accept `timedelta`. `deliver_at` accepts a timezone-aware
83
+ `datetime`.
84
+
85
+ The synchronous and asynchronous clients expose the same operations:
86
+
87
+ - `send` and `send_batch`
88
+ - `list_requests`, `get_request`, `list_request_attempts`, `cancel_request`,
89
+ and `replay_request`
90
+ - `create_schedule`, `list_schedules`, `get_schedule`, `update_schedule`,
91
+ `pause_schedule`, `resume_schedule`, and `delete_schedule`
92
+
93
+ Create schedules with a timing helper instead of constructing the API payload:
94
+
95
+ ```python
96
+ from datetime import timedelta
97
+
98
+ from stormedo import cron_timing, interval_timing
99
+
100
+ schedule = stormedo.create_schedule(
101
+ name="sync-inventory",
102
+ timing=cron_timing("0 */6 * * *", "Asia/Kolkata"),
103
+ url="https://example.com/inventory/sync",
104
+ body={"full_sync": True},
105
+ max_attempts=4,
106
+ )
107
+
108
+ stormedo.update_schedule(
109
+ schedule.id,
110
+ timing=interval_timing(timedelta(hours=4)),
111
+ )
112
+ ```
113
+
114
+ `cron_timing` accepts a five-field cron expression and an IANA timezone.
115
+ `interval_timing` accepts a `timedelta` containing a whole number of minutes
116
+ from one minute through 30 days. Pass a future timezone-aware `datetime` as
117
+ `starts_at` to choose the first run time.
118
+
119
+ ## Configure delivery verification
120
+
121
+ Create one verifier with the project ID and reuse it across requests:
122
+
123
+ ```python
124
+ import os
125
+
126
+ from stormedo import DeliveryVerifier
127
+
128
+ project_id = os.environ["STORMEDO_PROJECT_ID"]
129
+ verifier = DeliveryVerifier(project_id)
130
+ ```
131
+
132
+ For asynchronous applications:
133
+
134
+ ```python
135
+ from stormedo import AsyncDeliveryVerifier
136
+
137
+ async_verifier = AsyncDeliveryVerifier(project_id)
138
+ ```
139
+
140
+ ## Authenticate without checking the body
141
+
142
+ Use `authenticate_delivery` when the platform cannot provide the raw body. It
143
+ authenticates Stormedo and the request context but does not prove payload
144
+ integrity.
145
+
146
+ ```python
147
+ delivery = verifier.authenticate_delivery(
148
+ signature=signature,
149
+ request_id=request_id,
150
+ expected_url="https://example.com/webhooks/stormedo",
151
+ method="POST",
152
+ )
153
+
154
+ assert delivery.payload_integrity == "unchecked"
155
+ ```
156
+
157
+ ## Verify the exact body
158
+
159
+ Use `verify_delivery` when the receiver can capture the exact raw bytes before
160
+ a JSON or form parser changes them:
161
+
162
+ ```python
163
+ delivery = verifier.verify_delivery(
164
+ signature=signature,
165
+ request_id=request_id,
166
+ expected_url="https://example.com/webhooks/stormedo",
167
+ method="POST",
168
+ raw_body=raw_body,
169
+ )
170
+
171
+ assert delivery.payload_integrity == "verified"
172
+ ```
173
+
174
+ ## Receiver responsibilities
175
+
176
+ - Reject missing or duplicated `Stormedo-Signature` and
177
+ `Stormedo-Request-Id` headers before calling the core verifier.
178
+ - Treat `Stormedo-Attempt` and `Stormedo-Max-Attempts` as unsigned hints.
179
+ The signature does not cover them, so do not rely on them for security
180
+ decisions.
181
+ - Supply the complete public destination URL from trusted configuration. Do not
182
+ trust forwarded request headers unless the application has an explicit proxy
183
+ trust boundary.
184
+ - Authenticate or verify at ingress while the delivery token is current.
185
+ - Parse the application body only after `verify_delivery` succeeds when payload
186
+ integrity is required.
187
+
188
+ ## Errors
189
+
190
+ Stormedo API and network failures raise `StormedoError`. Use `code` for program
191
+ logic and `request_id` when contacting Stormedo support. A response that does
192
+ not match the expected shape raises `StormedoError` with code
193
+ `invalid_response`.
194
+
195
+ New values may appear in enum fields such as `status`, `method`, and
196
+ `retry.reason`. Their types list the known values, but handle unknown values,
197
+ for example with a fallback branch.
198
+ A schedule timing type that this SDK version does not know keeps its raw
199
+ `timing.type` string, with the cron and interval fields set to `None`.
200
+
201
+ Verification failures raise `DeliveryVerificationError`. Use its `code` to
202
+ handle the failure.
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name = "stormedo"
3
+ version = "0.1.0"
4
+ description = "Send durable HTTP requests and verify Stormedo deliveries"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.10"
9
+ classifiers = ["Development Status :: 4 - Beta"]
10
+ dependencies = [
11
+ "cryptography>=50.0.0",
12
+ "httpx>=0.28.1",
13
+ "typing-extensions>=4.4",
14
+ ]
15
+
16
+ [[project.authors]]
17
+ name = "Stormedo"
18
+ email = "dev@stormedo.com"
19
+
20
+ [project.urls]
21
+ Homepage = "https://stormedo.com"
22
+ Documentation = "https://stormedo.com/docs/sdks/python/"
23
+ Source = "https://github.com/stormedo/sdk/tree/main/python"
24
+
25
+ [build-system]
26
+ requires = ["uv_build>=0.12.1,<0.13.0"]
27
+ build-backend = "uv_build"
28
+
29
+ [dependency-groups]
30
+ dev = ["pytest>=9.1.1"]
@@ -0,0 +1,33 @@
1
+ [project]
2
+ name = "stormedo"
3
+ version = "0.1.0"
4
+ description = "Send durable HTTP requests and verify Stormedo deliveries"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [
9
+ { name = "Stormedo", email = "dev@stormedo.com" }
10
+ ]
11
+ requires-python = ">=3.10"
12
+ classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ ]
15
+ dependencies = [
16
+ "cryptography>=50.0.0",
17
+ "httpx>=0.28.1",
18
+ "typing-extensions>=4.4",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://stormedo.com"
23
+ Documentation = "https://stormedo.com/docs/sdks/python/"
24
+ Source = "https://github.com/stormedo/sdk/tree/main/python"
25
+
26
+ [build-system]
27
+ requires = ["uv_build>=0.12.1,<0.13.0"]
28
+ build-backend = "uv_build"
29
+
30
+ [dependency-groups]
31
+ dev = [
32
+ "pytest>=9.1.1",
33
+ ]
@@ -0,0 +1,74 @@
1
+ from .client import AsyncStormedo, Stormedo
2
+ from .errors import (
3
+ DeliveryVerificationError,
4
+ DeliveryVerificationErrorCode,
5
+ StormedoError,
6
+ )
7
+ from .types import (
8
+ AuthenticatedDelivery,
9
+ BatchRequest,
10
+ CronTiming,
11
+ EnqueuedRequest,
12
+ IntervalTiming,
13
+ JsonValue,
14
+ RequestAttempt,
15
+ RequestCancellation,
16
+ RequestDetail,
17
+ RequestListPage,
18
+ RequestMethod,
19
+ RequestRetryDecision,
20
+ RequestSource,
21
+ RequestStatus,
22
+ RequestSummary,
23
+ ScheduleDetail,
24
+ ScheduleRequest,
25
+ ScheduleRequestDefinition,
26
+ ScheduleRunOutcome,
27
+ ScheduleStatus,
28
+ ScheduleSummary,
29
+ ScheduleTiming,
30
+ ScheduleTimingDefinition,
31
+ VerifiedDelivery,
32
+ cron_timing,
33
+ interval_timing,
34
+ )
35
+ from .verifier import (
36
+ AsyncDeliveryVerifier,
37
+ DeliveryVerifier,
38
+ )
39
+
40
+ __all__ = [
41
+ "AsyncDeliveryVerifier",
42
+ "AsyncStormedo",
43
+ "AuthenticatedDelivery",
44
+ "BatchRequest",
45
+ "CronTiming",
46
+ "DeliveryVerificationError",
47
+ "DeliveryVerificationErrorCode",
48
+ "DeliveryVerifier",
49
+ "EnqueuedRequest",
50
+ "IntervalTiming",
51
+ "JsonValue",
52
+ "RequestAttempt",
53
+ "RequestCancellation",
54
+ "RequestDetail",
55
+ "RequestListPage",
56
+ "RequestMethod",
57
+ "RequestRetryDecision",
58
+ "RequestSource",
59
+ "RequestStatus",
60
+ "RequestSummary",
61
+ "ScheduleDetail",
62
+ "ScheduleRequest",
63
+ "ScheduleRequestDefinition",
64
+ "ScheduleRunOutcome",
65
+ "ScheduleStatus",
66
+ "ScheduleSummary",
67
+ "ScheduleTiming",
68
+ "ScheduleTimingDefinition",
69
+ "Stormedo",
70
+ "StormedoError",
71
+ "VerifiedDelivery",
72
+ "cron_timing",
73
+ "interval_timing",
74
+ ]
@@ -0,0 +1,25 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ from .errors import verification_error
6
+
7
+
8
+ def parse_token_json(value: bytes) -> dict[str, object]:
9
+ try:
10
+ source = value.decode("utf-8", errors="strict")
11
+ parsed = json.loads(source, object_pairs_hook=_unique_object)
12
+ except (UnicodeDecodeError, ValueError, RecursionError) as error:
13
+ raise verification_error("malformed_token") from error
14
+ if not isinstance(parsed, dict):
15
+ raise verification_error("malformed_token")
16
+ return parsed
17
+
18
+
19
+ def _unique_object(pairs: list[tuple[str, object]]) -> dict[str, object]:
20
+ result: dict[str, object] = {}
21
+ for key, value in pairs:
22
+ if key in result:
23
+ raise ValueError("duplicate JSON key")
24
+ result[key] = value
25
+ return result