stormedo 0.1.0rc1__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,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,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: stormedo
3
+ Version: 0.1.0rc1
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
+ Requires-Dist: cryptography>=50.0.0
10
+ Requires-Dist: httpx>=0.28.1
11
+ Requires-Dist: typing-extensions>=4.4
12
+ Requires-Python: >=3.10
13
+ Project-URL: Homepage, https://stormedo.com
14
+ Project-URL: Documentation, https://stormedo.com/docs/sdks/python/
15
+ Project-URL: Source, https://github.com/stormedo/sdk/tree/main/python
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Stormedo Python SDK
19
+
20
+ This package sends durable HTTP requests through Stormedo and authenticates or
21
+ verifies signed deliveries from Stormedo. It supports Python 3.10 and newer.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ uv add stormedo
27
+ ```
28
+
29
+ ## Send requests
30
+
31
+ Use `Stormedo` in synchronous applications:
32
+
33
+ ```python
34
+ import os
35
+ from datetime import timedelta
36
+
37
+ from stormedo import Stormedo
38
+
39
+ stormedo = Stormedo(os.environ["STORMEDO_TOKEN"])
40
+ request = stormedo.send(
41
+ "https://example.com/webhook",
42
+ body={"message": "hello from Stormedo"},
43
+ delay=timedelta(minutes=5),
44
+ max_attempts=5,
45
+ )
46
+ ```
47
+
48
+ Use `AsyncStormedo` when the application already runs an event loop:
49
+
50
+ ```python
51
+ import os
52
+
53
+ from stormedo import AsyncStormedo
54
+
55
+ async_stormedo = AsyncStormedo(os.environ["STORMEDO_TOKEN"])
56
+ request = await async_stormedo.send(
57
+ "https://example.com/webhook",
58
+ body={"message": "hello from Stormedo"},
59
+ )
60
+ ```
61
+
62
+ Create one client, reuse it, and call `close()` or `aclose()` during application
63
+ shutdown.
64
+
65
+ Use `raw_body` when bytes must be sent unchanged. Headers supplied in `headers`
66
+ are sent to the destination. Stormedo never forwards the project API key.
67
+
68
+ ```python
69
+ request = stormedo.send(
70
+ "https://example.com/events",
71
+ raw_body=b"event=created",
72
+ content_type="application/x-www-form-urlencoded",
73
+ headers={"Authorization": "Bearer destination-token"},
74
+ )
75
+ ```
76
+
77
+ Batch items use `BatchRequest` values instead of dictionaries:
78
+
79
+ ```python
80
+ from datetime import timedelta
81
+
82
+ from stormedo import BatchRequest
83
+
84
+ requests = stormedo.send_batch(
85
+ [
86
+ BatchRequest(
87
+ url="https://example.com/orders",
88
+ body={"order_id": "ord_123"},
89
+ ),
90
+ BatchRequest(
91
+ url="https://example.com/inventory",
92
+ body={"warehouse_id": "wh_7"},
93
+ delay=timedelta(hours=1),
94
+ ),
95
+ ]
96
+ )
97
+ ```
98
+
99
+ `delay` and `timeout` accept `timedelta`. `deliver_at` accepts a timezone-aware
100
+ `datetime`.
101
+
102
+ The synchronous and asynchronous clients expose the same operations:
103
+
104
+ - `send` and `send_batch`
105
+ - `list_requests`, `get_request`, `list_request_attempts`, `cancel_request`,
106
+ and `replay_request`
107
+ - `create_schedule`, `list_schedules`, `get_schedule`, `update_schedule`,
108
+ `pause_schedule`, `resume_schedule`, and `delete_schedule`
109
+
110
+ Create schedules with a timing helper instead of constructing the API payload:
111
+
112
+ ```python
113
+ from datetime import timedelta
114
+
115
+ from stormedo import cron_timing, interval_timing
116
+
117
+ schedule = stormedo.create_schedule(
118
+ name="sync-inventory",
119
+ timing=cron_timing("0 */6 * * *", "Asia/Kolkata"),
120
+ url="https://example.com/inventory/sync",
121
+ body={"full_sync": True},
122
+ max_attempts=4,
123
+ )
124
+
125
+ stormedo.update_schedule(
126
+ schedule.id,
127
+ timing=interval_timing(timedelta(hours=4)),
128
+ )
129
+ ```
130
+
131
+ `cron_timing` accepts a five-field cron expression and an IANA timezone.
132
+ `interval_timing` accepts a `timedelta` containing a whole number of minutes
133
+ from one minute through 30 days. Pass a future timezone-aware `datetime` as
134
+ `starts_at` to choose the first run time.
135
+
136
+ ## Configure delivery verification
137
+
138
+ Create one verifier with the project ID and reuse it across requests:
139
+
140
+ ```python
141
+ import os
142
+
143
+ from stormedo import DeliveryVerifier
144
+
145
+ project_id = os.environ["STORMEDO_PROJECT_ID"]
146
+ verifier = DeliveryVerifier(project_id)
147
+ ```
148
+
149
+ For asynchronous applications:
150
+
151
+ ```python
152
+ from stormedo import AsyncDeliveryVerifier
153
+
154
+ async_verifier = AsyncDeliveryVerifier(project_id)
155
+ ```
156
+
157
+ ## Authenticate without checking the body
158
+
159
+ Use `authenticate_delivery` when the platform cannot provide the raw body. It
160
+ authenticates Stormedo and the request context but does not prove payload
161
+ integrity.
162
+
163
+ ```python
164
+ delivery = verifier.authenticate_delivery(
165
+ signature=signature,
166
+ request_id=request_id,
167
+ expected_url="https://example.com/webhooks/stormedo",
168
+ method="POST",
169
+ )
170
+
171
+ assert delivery.payload_integrity == "unchecked"
172
+ ```
173
+
174
+ ## Verify the exact body
175
+
176
+ Use `verify_delivery` when the receiver can capture the exact raw bytes before
177
+ a JSON or form parser changes them:
178
+
179
+ ```python
180
+ delivery = verifier.verify_delivery(
181
+ signature=signature,
182
+ request_id=request_id,
183
+ expected_url="https://example.com/webhooks/stormedo",
184
+ method="POST",
185
+ raw_body=raw_body,
186
+ )
187
+
188
+ assert delivery.payload_integrity == "verified"
189
+ ```
190
+
191
+ ## Receiver responsibilities
192
+
193
+ - Reject missing or duplicated `Stormedo-Signature` and
194
+ `Stormedo-Request-Id` headers before calling the core verifier.
195
+ - Supply the complete public destination URL from trusted configuration. Do not
196
+ trust forwarded request headers unless the application has an explicit proxy
197
+ trust boundary.
198
+ - Authenticate or verify at ingress while the delivery token is current.
199
+ - Parse the application body only after `verify_delivery` succeeds when payload
200
+ integrity is required.
201
+
202
+ ## Errors
203
+
204
+ Stormedo API and network failures raise `StormedoError`. Use `code` for program
205
+ logic and `request_id` when contacting Stormedo support.
206
+
207
+ Verification failures raise `DeliveryVerificationError`. Use its `code` to
208
+ handle the failure.
@@ -0,0 +1,191 @@
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
+ - Supply the complete public destination URL from trusted configuration. Do not
179
+ trust forwarded request headers unless the application has an explicit proxy
180
+ trust boundary.
181
+ - Authenticate or verify at ingress while the delivery token is current.
182
+ - Parse the application body only after `verify_delivery` succeeds when payload
183
+ integrity is required.
184
+
185
+ ## Errors
186
+
187
+ Stormedo API and network failures raise `StormedoError`. Use `code` for program
188
+ logic and `request_id` when contacting Stormedo support.
189
+
190
+ Verification failures raise `DeliveryVerificationError`. Use its `code` to
191
+ handle the failure.
@@ -0,0 +1,29 @@
1
+ [project]
2
+ name = "stormedo"
3
+ version = "0.1.0rc1"
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
+ dependencies = [
10
+ "cryptography>=50.0.0",
11
+ "httpx>=0.28.1",
12
+ "typing-extensions>=4.4",
13
+ ]
14
+
15
+ [[project.authors]]
16
+ name = "Stormedo"
17
+ email = "dev@stormedo.com"
18
+
19
+ [project.urls]
20
+ Homepage = "https://stormedo.com"
21
+ Documentation = "https://stormedo.com/docs/sdks/python/"
22
+ Source = "https://github.com/stormedo/sdk/tree/main/python"
23
+
24
+ [build-system]
25
+ requires = ["uv_build>=0.12.1,<0.13.0"]
26
+ build-backend = "uv_build"
27
+
28
+ [dependency-groups]
29
+ dev = ["pytest>=9.1.1"]
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name = "stormedo"
3
+ version = "0.1.0rc1"
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
+ dependencies = [
13
+ "cryptography>=50.0.0",
14
+ "httpx>=0.28.1",
15
+ "typing-extensions>=4.4",
16
+ ]
17
+
18
+ [project.urls]
19
+ Homepage = "https://stormedo.com"
20
+ Documentation = "https://stormedo.com/docs/sdks/python/"
21
+ Source = "https://github.com/stormedo/sdk/tree/main/python"
22
+
23
+ [build-system]
24
+ requires = ["uv_build>=0.12.1,<0.13.0"]
25
+ build-backend = "uv_build"
26
+
27
+ [dependency-groups]
28
+ dev = [
29
+ "pytest>=9.1.1",
30
+ ]
@@ -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