smswire 0.2.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,6 @@
1
+ .venv/
2
+ dist/
3
+ __pycache__/
4
+ *.egg-info/
5
+ .pytest_cache/
6
+ .mypy_cache/
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 (2026-11-25)
4
+
5
+ - **Contact groups**: `sms.groups` with `create`, `list`, `get`, `update`, `delete`, `list_members`,
6
+ `list_all_members`, `add_members` and `remove_member`, on both clients. A group can have join keywords: people text one to your phone to
7
+ join, and you get a `group.joined`
8
+ webhook event.
9
+ - **Campaigns**: `sms.campaigns` with `create`, `list`, `get`, `update`, `delete`, `preview`,
10
+ `results`, `send`, `control` (pause or resume) and `cancel`.
11
+ - **Languages**: `language` on a send, a bulk send and a one-time code. A template with a text per
12
+ language picks the recipient's language (from their contact) unless you name one.
13
+ - **Choosing the sender**: `phone` sends from one phone only; `from_` (sent as `from`) asks for a SIM by the
14
+ name or number you gave it on the dashboard; `sim` alone now picks only the project's phones that have
15
+ that slot.
16
+ - **Bulk sends to groups**: `group_ids` on a bulk send.
17
+
18
+ ## 0.1.0 (2026-11-10)
19
+
20
+ - First version: messages, one-time codes, recurring schedules and webhook verification, sync and async clients.
21
+ Tagged but never reached PyPI (the publish step failed); 0.2.0 is the first release there.
smswire-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SMSWire
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.
smswire-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,206 @@
1
+ Metadata-Version: 2.5
2
+ Name: smswire
3
+ Version: 0.2.0
4
+ Summary: Official Python SDK for SMSWire: send SMS and one-time codes through your own Android phones.
5
+ Project-URL: Homepage, https://smswire.app
6
+ Project-URL: Documentation, https://smswire.app/docs#sdks
7
+ Project-URL: Source, https://github.com/jolabs-io/smswire-python
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: android,gateway,otp,sms,smswire
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.10
16
+ Requires-Dist: httpx<1,>=0.25
17
+ Provides-Extra: dev
18
+ Requires-Dist: mypy>=1.10; extra == 'dev'
19
+ Requires-Dist: pytest>=8; extra == 'dev'
20
+ Description-Content-Type: text/markdown
21
+
22
+ # SMSWire for Python
23
+
24
+ Send SMS and one-time codes from your app through your own Android phones with [SMSWire](https://smswire.app).
25
+
26
+ ```sh
27
+ pip install smswire
28
+ ```
29
+
30
+ Python 3.10+. Sync and async clients, built on httpx.
31
+
32
+ ## Set up
33
+
34
+ Each project on the dashboard has an API key and a slug (the part after `/p/` in its endpoint). Keep them in the environment:
35
+
36
+ ```sh
37
+ SMSWIRE_KEY="smswire_live_…"
38
+ SMSWIRE_PROJECT="prj_…"
39
+ SMSWIRE_WEBHOOK_SECRET="whsec_…" # only if you receive webhooks
40
+ # SMSWIRE_URL="https://api.smswire.app" # your server, if you host SMSWire yourself
41
+ ```
42
+
43
+ ```python
44
+ from smswire import SMSWire
45
+
46
+ sms = SMSWire() # or SMSWire(api_key=..., project=..., base_url=...)
47
+ ```
48
+
49
+ ## Send
50
+
51
+ ```python
52
+ message = sms.messages.send(
53
+ "+251911234567",
54
+ "Your order {{order}} shipped",
55
+ variables={"order": "A-1042"},
56
+ type="transactional", # otp | transactional | notification | marketing
57
+ tags=["orders"],
58
+ metadata={"user_id": 42}, # echoed back in webhooks
59
+ )
60
+ # → {"id": "msg_…", "status": "queued", "segments": 1, …}
61
+
62
+ # Your own idempotency key makes your retries safe too (the SDK adds a random one otherwise).
63
+ sms.messages.send(to, body, idempotency_key=f"order-{order.id}")
64
+
65
+ sms.messages.get(message["id"])
66
+ sms.messages.cancel(message["id"]) # before it reaches a phone
67
+
68
+ page = sms.messages.list(status="failed", limit=50)
69
+ for m in sms.messages.list_all(tag="orders"):
70
+ print(m["id"], m["status"])
71
+
72
+ batch = sms.messages.send_bulk(
73
+ [{"to": "+251911234567", "variables": {"name": "Abebe"}}, {"to": "+251922345678", "variables": {"name": "Sara"}}],
74
+ name="Weekend sale",
75
+ body="Hi {{name}}, 20% off this weekend",
76
+ rate=30, # per minute
77
+ )
78
+ # → {"batch_id": …, "accepted": 2, "rejected": [{"index", "to", "reason"}]}
79
+ ```
80
+
81
+ ## Templates in more than one language
82
+
83
+ A template saved on the dashboard can hold a text per language. Send it by name and each recipient
84
+ gets the one they read — the `language` on their contact — while everyone else gets the default text.
85
+ A message says which language it went out in (`language`; `null` is the default text), and `pt-BR`
86
+ matches a text written in `pt`.
87
+
88
+ ```python
89
+ sms.messages.send_bulk(
90
+ [
91
+ {"to": "+251911234567", "variables": {"name": "Abebe"}}, # reads am → the Amharic text
92
+ {"to": "+14155550123", "variables": {"name": "Alex"}}, # no language → the default text
93
+ {"to": "+5511999990000", "language": "pt-BR", "variables": {"name": "Bruna"}},
94
+ ],
95
+ template="order-shipped",
96
+ )
97
+
98
+ # One language for everybody, whatever they read:
99
+ sms.messages.send("+251911234567", template="order-shipped", language="am", variables={"name": "Abebe"})
100
+ ```
101
+
102
+ ## One-time codes
103
+
104
+ ```python
105
+ otp = sms.otp.send("+251911234567", length=6, ttl=300)
106
+ # later, with what the user typed:
107
+ result = sms.otp.verify(otp["id"], code)
108
+ if not result["valid"]:
109
+ print(result["reason"]) # invalid | expired | too_many_attempts | already_used
110
+ ```
111
+
112
+ ## Recurring sends
113
+
114
+ ```python
115
+ schedule = sms.schedules.create(
116
+ "0 9 * * 1",
117
+ name="Weekly report",
118
+ timezone="Africa/Addis_Ababa",
119
+ to="+251911234567",
120
+ body="Your weekly report is ready",
121
+ )
122
+ sms.schedules.update(schedule["id"], enabled=False)
123
+ sms.schedules.list()
124
+ sms.schedules.delete(schedule["id"])
125
+ ```
126
+
127
+ ## Contact groups
128
+
129
+ Groups belong to the workspace, so every project's key sees the same ones. With `keywords`, someone who texts exactly one of them to a workspace phone joins the group (and gets `join_reply` once); your webhook hears `group.joined`.
130
+
131
+ ```python
132
+ group = sms.groups.create("Promo", keywords=["A2"], join_reply="You're in! Reply STOP to opt out.")
133
+ sms.groups.add_members(group["id"], [{"phone": "+251911234567", "name": "Abebe"}])
134
+ for member in sms.groups.list_all_members(group["id"]):
135
+ print(member["phone"], member["source"])
136
+ sms.messages.send_bulk(group_ids=[group["id"]], body="Hi {{name|there}}, 20% off today")
137
+ sms.groups.remove_member(group["id"], "+251911234567")
138
+ ```
139
+
140
+ ## Async
141
+
142
+ ```python
143
+ from smswire import AsyncSMSWire
144
+
145
+ async with AsyncSMSWire() as sms:
146
+ await sms.messages.send("+251911234567", "Hello")
147
+ async for m in sms.messages.list_all(status="failed"):
148
+ ...
149
+ ```
150
+
151
+ ## Campaigns
152
+
153
+ A campaign is a send with a name: a message, who it goes to, who to leave out, and when. It is made as a
154
+ draft and nothing goes out until you start it, so you can check who it reaches first. Each run is an
155
+ ordinary batch. `marketing` needs `consent` -- that the recipients agreed to hear from you -- and
156
+ `stop_footer` ends every marketing message with your opt-out line, counted in its SMS parts.
157
+
158
+ ```python
159
+ campaign = sms.campaigns.create(
160
+ "Weekend sale",
161
+ body="Hi {{name|there}}, 20% off this weekend",
162
+ type="marketing",
163
+ consent=True,
164
+ audience={"group_ids": [group["id"]]},
165
+ exclude={"recent_days": 7},
166
+ stop_footer="Reply STOP to opt out",
167
+ )
168
+ print(sms.campaigns.preview(campaign["id"]))
169
+ sms.campaigns.send(campaign["id"])
170
+ results = sms.campaigns.results(campaign["id"])
171
+ print(results["delivered"], results["replies"], results["opt_outs"], results["parts"])
172
+ ```
173
+
174
+ ## Webhooks
175
+
176
+ Status updates (`message.status`) and replies (`message.received`) are POSTed to the project's webhook URL, signed with `X-SMSWire-Signature`. Verify the **raw** body:
177
+
178
+ ```python
179
+ from smswire import SignatureError
180
+
181
+ # Flask
182
+ @app.post("/hooks/smswire")
183
+ def smswire_hook():
184
+ try:
185
+ event = sms.webhooks.verify(request.get_data(), request.headers.get("X-SMSWire-Signature"))
186
+ except SignatureError:
187
+ return "", 400
188
+ if event["event"] == "message.status":
189
+ mark_order(event["metadata"], event["status"])
190
+ elif event["event"] == "message.received":
191
+ handle_reply(event["from"], event["body"])
192
+ return "", 200
193
+ ```
194
+
195
+ Django: `request.body` and `request.headers["X-SMSWire-Signature"]`. FastAPI: `await request.body()`. Without a client: `verify_webhook(raw_body, signature, secret)`. The same event can arrive twice; make the handler idempotent.
196
+
197
+ ## Errors and retries
198
+
199
+ Failed calls raise `SMSWireError` with `status` (None when no answer came), `code` (`invalid_request`, `invalid_api_key`, `rate_limited`, `daily_limit_reached`, `network_error`, `timeout`, …), `message` and `retry_after`.
200
+
201
+ The SDK retries (default `max_retries=2`, waiting `Retry-After` or backing off):
202
+
203
+ - reads, updates, deletes and `messages.send` (it carries an idempotency key): on 429, 5xx and network errors;
204
+ - `send_bulk`, `otp.send`, `otp.verify`, `schedules.create`: on 429 only, since a 5xx or a dropped connection may already have done the work.
205
+
206
+ A `Retry-After` longer than `max_retry_wait` (60 s, e.g. a daily limit) raises at once.
@@ -0,0 +1,185 @@
1
+ # SMSWire for Python
2
+
3
+ Send SMS and one-time codes from your app through your own Android phones with [SMSWire](https://smswire.app).
4
+
5
+ ```sh
6
+ pip install smswire
7
+ ```
8
+
9
+ Python 3.10+. Sync and async clients, built on httpx.
10
+
11
+ ## Set up
12
+
13
+ Each project on the dashboard has an API key and a slug (the part after `/p/` in its endpoint). Keep them in the environment:
14
+
15
+ ```sh
16
+ SMSWIRE_KEY="smswire_live_…"
17
+ SMSWIRE_PROJECT="prj_…"
18
+ SMSWIRE_WEBHOOK_SECRET="whsec_…" # only if you receive webhooks
19
+ # SMSWIRE_URL="https://api.smswire.app" # your server, if you host SMSWire yourself
20
+ ```
21
+
22
+ ```python
23
+ from smswire import SMSWire
24
+
25
+ sms = SMSWire() # or SMSWire(api_key=..., project=..., base_url=...)
26
+ ```
27
+
28
+ ## Send
29
+
30
+ ```python
31
+ message = sms.messages.send(
32
+ "+251911234567",
33
+ "Your order {{order}} shipped",
34
+ variables={"order": "A-1042"},
35
+ type="transactional", # otp | transactional | notification | marketing
36
+ tags=["orders"],
37
+ metadata={"user_id": 42}, # echoed back in webhooks
38
+ )
39
+ # → {"id": "msg_…", "status": "queued", "segments": 1, …}
40
+
41
+ # Your own idempotency key makes your retries safe too (the SDK adds a random one otherwise).
42
+ sms.messages.send(to, body, idempotency_key=f"order-{order.id}")
43
+
44
+ sms.messages.get(message["id"])
45
+ sms.messages.cancel(message["id"]) # before it reaches a phone
46
+
47
+ page = sms.messages.list(status="failed", limit=50)
48
+ for m in sms.messages.list_all(tag="orders"):
49
+ print(m["id"], m["status"])
50
+
51
+ batch = sms.messages.send_bulk(
52
+ [{"to": "+251911234567", "variables": {"name": "Abebe"}}, {"to": "+251922345678", "variables": {"name": "Sara"}}],
53
+ name="Weekend sale",
54
+ body="Hi {{name}}, 20% off this weekend",
55
+ rate=30, # per minute
56
+ )
57
+ # → {"batch_id": …, "accepted": 2, "rejected": [{"index", "to", "reason"}]}
58
+ ```
59
+
60
+ ## Templates in more than one language
61
+
62
+ A template saved on the dashboard can hold a text per language. Send it by name and each recipient
63
+ gets the one they read — the `language` on their contact — while everyone else gets the default text.
64
+ A message says which language it went out in (`language`; `null` is the default text), and `pt-BR`
65
+ matches a text written in `pt`.
66
+
67
+ ```python
68
+ sms.messages.send_bulk(
69
+ [
70
+ {"to": "+251911234567", "variables": {"name": "Abebe"}}, # reads am → the Amharic text
71
+ {"to": "+14155550123", "variables": {"name": "Alex"}}, # no language → the default text
72
+ {"to": "+5511999990000", "language": "pt-BR", "variables": {"name": "Bruna"}},
73
+ ],
74
+ template="order-shipped",
75
+ )
76
+
77
+ # One language for everybody, whatever they read:
78
+ sms.messages.send("+251911234567", template="order-shipped", language="am", variables={"name": "Abebe"})
79
+ ```
80
+
81
+ ## One-time codes
82
+
83
+ ```python
84
+ otp = sms.otp.send("+251911234567", length=6, ttl=300)
85
+ # later, with what the user typed:
86
+ result = sms.otp.verify(otp["id"], code)
87
+ if not result["valid"]:
88
+ print(result["reason"]) # invalid | expired | too_many_attempts | already_used
89
+ ```
90
+
91
+ ## Recurring sends
92
+
93
+ ```python
94
+ schedule = sms.schedules.create(
95
+ "0 9 * * 1",
96
+ name="Weekly report",
97
+ timezone="Africa/Addis_Ababa",
98
+ to="+251911234567",
99
+ body="Your weekly report is ready",
100
+ )
101
+ sms.schedules.update(schedule["id"], enabled=False)
102
+ sms.schedules.list()
103
+ sms.schedules.delete(schedule["id"])
104
+ ```
105
+
106
+ ## Contact groups
107
+
108
+ Groups belong to the workspace, so every project's key sees the same ones. With `keywords`, someone who texts exactly one of them to a workspace phone joins the group (and gets `join_reply` once); your webhook hears `group.joined`.
109
+
110
+ ```python
111
+ group = sms.groups.create("Promo", keywords=["A2"], join_reply="You're in! Reply STOP to opt out.")
112
+ sms.groups.add_members(group["id"], [{"phone": "+251911234567", "name": "Abebe"}])
113
+ for member in sms.groups.list_all_members(group["id"]):
114
+ print(member["phone"], member["source"])
115
+ sms.messages.send_bulk(group_ids=[group["id"]], body="Hi {{name|there}}, 20% off today")
116
+ sms.groups.remove_member(group["id"], "+251911234567")
117
+ ```
118
+
119
+ ## Async
120
+
121
+ ```python
122
+ from smswire import AsyncSMSWire
123
+
124
+ async with AsyncSMSWire() as sms:
125
+ await sms.messages.send("+251911234567", "Hello")
126
+ async for m in sms.messages.list_all(status="failed"):
127
+ ...
128
+ ```
129
+
130
+ ## Campaigns
131
+
132
+ A campaign is a send with a name: a message, who it goes to, who to leave out, and when. It is made as a
133
+ draft and nothing goes out until you start it, so you can check who it reaches first. Each run is an
134
+ ordinary batch. `marketing` needs `consent` -- that the recipients agreed to hear from you -- and
135
+ `stop_footer` ends every marketing message with your opt-out line, counted in its SMS parts.
136
+
137
+ ```python
138
+ campaign = sms.campaigns.create(
139
+ "Weekend sale",
140
+ body="Hi {{name|there}}, 20% off this weekend",
141
+ type="marketing",
142
+ consent=True,
143
+ audience={"group_ids": [group["id"]]},
144
+ exclude={"recent_days": 7},
145
+ stop_footer="Reply STOP to opt out",
146
+ )
147
+ print(sms.campaigns.preview(campaign["id"]))
148
+ sms.campaigns.send(campaign["id"])
149
+ results = sms.campaigns.results(campaign["id"])
150
+ print(results["delivered"], results["replies"], results["opt_outs"], results["parts"])
151
+ ```
152
+
153
+ ## Webhooks
154
+
155
+ Status updates (`message.status`) and replies (`message.received`) are POSTed to the project's webhook URL, signed with `X-SMSWire-Signature`. Verify the **raw** body:
156
+
157
+ ```python
158
+ from smswire import SignatureError
159
+
160
+ # Flask
161
+ @app.post("/hooks/smswire")
162
+ def smswire_hook():
163
+ try:
164
+ event = sms.webhooks.verify(request.get_data(), request.headers.get("X-SMSWire-Signature"))
165
+ except SignatureError:
166
+ return "", 400
167
+ if event["event"] == "message.status":
168
+ mark_order(event["metadata"], event["status"])
169
+ elif event["event"] == "message.received":
170
+ handle_reply(event["from"], event["body"])
171
+ return "", 200
172
+ ```
173
+
174
+ Django: `request.body` and `request.headers["X-SMSWire-Signature"]`. FastAPI: `await request.body()`. Without a client: `verify_webhook(raw_body, signature, secret)`. The same event can arrive twice; make the handler idempotent.
175
+
176
+ ## Errors and retries
177
+
178
+ Failed calls raise `SMSWireError` with `status` (None when no answer came), `code` (`invalid_request`, `invalid_api_key`, `rate_limited`, `daily_limit_reached`, `network_error`, `timeout`, …), `message` and `retry_after`.
179
+
180
+ The SDK retries (default `max_retries=2`, waiting `Retry-After` or backing off):
181
+
182
+ - reads, updates, deletes and `messages.send` (it carries an idempotency key): on 429, 5xx and network errors;
183
+ - `send_bulk`, `otp.send`, `otp.verify`, `schedules.create`: on 429 only, since a 5xx or a dropped connection may already have done the work.
184
+
185
+ A `Retry-After` longer than `max_retry_wait` (60 s, e.g. a daily limit) raises at once.
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "smswire"
7
+ version = "0.2.0"
8
+ description = "Official Python SDK for SMSWire: send SMS and one-time codes through your own Android phones."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.10"
13
+ dependencies = ["httpx>=0.25,<1"]
14
+ keywords = ["sms", "otp", "android", "gateway", "smswire"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Operating System :: OS Independent",
18
+ "Typing :: Typed",
19
+ "Intended Audience :: Developers",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ dev = ["pytest>=8", "mypy>=1.10"]
24
+
25
+ [project.urls]
26
+ Homepage = "https://smswire.app"
27
+ Documentation = "https://smswire.app/docs#sdks"
28
+ Source = "https://github.com/jolabs-io/smswire-python"
29
+
30
+ [tool.hatch.build.targets.wheel]
31
+ packages = ["src/smswire"]
32
+
33
+ [tool.pytest.ini_options]
34
+ testpaths = ["tests"]
35
+
36
+ [tool.mypy]
37
+ strict = true
38
+ files = ["src/smswire"]
@@ -0,0 +1,17 @@
1
+ """SMSWire: send SMS and one-time codes through your own Android phones."""
2
+
3
+ from ._client import DEFAULT_BASE_URL, AsyncSMSWire, SMSWire
4
+ from ._version import __version__
5
+ from .errors import SignatureError, SMSWireError
6
+ from .webhooks import SIGNATURE_HEADER, verify_webhook
7
+
8
+ __all__ = [
9
+ "SMSWire",
10
+ "AsyncSMSWire",
11
+ "SMSWireError",
12
+ "SignatureError",
13
+ "verify_webhook",
14
+ "SIGNATURE_HEADER",
15
+ "DEFAULT_BASE_URL",
16
+ "__version__",
17
+ ]