python-termii 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.
- python_termii-0.1.0/LICENSE +21 -0
- python_termii-0.1.0/PKG-INFO +388 -0
- python_termii-0.1.0/README.md +364 -0
- python_termii-0.1.0/pyproject.toml +43 -0
- python_termii-0.1.0/python_termii.egg-info/PKG-INFO +388 -0
- python_termii-0.1.0/python_termii.egg-info/SOURCES.txt +26 -0
- python_termii-0.1.0/python_termii.egg-info/dependency_links.txt +1 -0
- python_termii-0.1.0/python_termii.egg-info/requires.txt +2 -0
- python_termii-0.1.0/python_termii.egg-info/top_level.txt +1 -0
- python_termii-0.1.0/setup.cfg +4 -0
- python_termii-0.1.0/termii_py/__init__.py +10 -0
- python_termii-0.1.0/termii_py/client.py +64 -0
- python_termii-0.1.0/termii_py/config.py +12 -0
- python_termii-0.1.0/termii_py/http/__init__.py +8 -0
- python_termii-0.1.0/termii_py/http/request_handler.py +141 -0
- python_termii-0.1.0/termii_py/http/request_response.py +64 -0
- python_termii-0.1.0/termii_py/services/__init__.py +14 -0
- python_termii-0.1.0/termii_py/services/campaign.py +175 -0
- python_termii-0.1.0/termii_py/services/contact.py +167 -0
- python_termii-0.1.0/termii_py/services/message.py +191 -0
- python_termii-0.1.0/termii_py/services/number.py +75 -0
- python_termii-0.1.0/termii_py/services/phonebook.py +137 -0
- python_termii-0.1.0/termii_py/services/sender_id.py +78 -0
- python_termii-0.1.0/termii_py/services/template.py +99 -0
- python_termii-0.1.0/termii_py/utils/__init__.py +0 -0
- python_termii-0.1.0/termii_py/utils/exception.py +11 -0
- python_termii-0.1.0/termii_py/value_object/__init__.py +5 -0
- python_termii-0.1.0/termii_py/value_object/phone_number.py +74 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Samuel Doghor
|
|
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,388 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-termii
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A clean Python SDK for the Termii API (SMS, Voice, and OTP)
|
|
5
|
+
Author-email: Samuel Doghor Destiny <labs@amdoghor.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/samdoghor/python-termii
|
|
8
|
+
Project-URL: Repository, https://github.com/samdoghor/python-termii
|
|
9
|
+
Keywords: termii,whatsapp,sms,otp,sdk,python,library
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: requests
|
|
22
|
+
Requires-Dist: python-dotenv
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# python-termii
|
|
26
|
+
|
|
27
|
+
A clean and lightweight Python SDK for [Termii](https://termii.com) — send SMS, WhatsApp messages, manage phonebooks,
|
|
28
|
+
contacts, campaigns, and more.
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/python-termii/)
|
|
31
|
+
[](https://pypi.org/project/python-termii/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
[](https://pypi.org/project/python-termii/)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Table of Contents
|
|
38
|
+
|
|
39
|
+
- [Installation](#installation)
|
|
40
|
+
- [Configuration](#configuration)
|
|
41
|
+
- [Services](#services)
|
|
42
|
+
- [Sender ID](#sender-id)
|
|
43
|
+
- [Messaging](#messaging)
|
|
44
|
+
- [Number](#number)
|
|
45
|
+
- [Template](#template)
|
|
46
|
+
- [Phonebook](#phonebook)
|
|
47
|
+
- [Contact](#contact)
|
|
48
|
+
- [Campaign](#campaign)
|
|
49
|
+
- [Error Handling](#error-handling)
|
|
50
|
+
- [Contributing](#contributing)
|
|
51
|
+
- [License](#license)
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install python-termii
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
Initialize the client with your API key and base URL. Both can be passed directly or loaded from environment variables.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from termii_py import TermiiClient
|
|
69
|
+
|
|
70
|
+
# Pass credentials directly
|
|
71
|
+
client = TermiiClient(api_key="YOUR_API_KEY", base_url="YOUR_BASE_URL")
|
|
72
|
+
|
|
73
|
+
# Or set environment variables and call with no arguments
|
|
74
|
+
client = TermiiClient()
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Using a `.env` file (recommended):**
|
|
78
|
+
|
|
79
|
+
```env
|
|
80
|
+
TERMII_API_KEY=your_api_key
|
|
81
|
+
TERMII_BASE_URL=your_base_url
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from termii_py import TermiiClient
|
|
86
|
+
|
|
87
|
+
client = TermiiClient()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
> Get your API key and base URL from your [Termii dashboard](https://app.termii.com). A `ClientConfigError` is raised if
|
|
91
|
+
> either value is missing.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Services
|
|
96
|
+
|
|
97
|
+
All services are available as attributes on the `TermiiClient` instance.
|
|
98
|
+
|
|
99
|
+
### Sender ID
|
|
100
|
+
|
|
101
|
+
**Fetch sender IDs** — optionally filter by name or status:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
# Fetch all
|
|
105
|
+
client.sender_id.fetch_id()
|
|
106
|
+
|
|
107
|
+
# Filter by name or status
|
|
108
|
+
client.sender_id.fetch_id(name="MyBrand", status="approved")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Request a new sender ID:**
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
client.sender_id.request_id(
|
|
115
|
+
sender_id="MyBrand",
|
|
116
|
+
usecase="Transactional alerts for order confirmations",
|
|
117
|
+
company="Acme Ltd"
|
|
118
|
+
)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### Messaging
|
|
124
|
+
|
|
125
|
+
**Send a single SMS:**
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
client.message.send_message(
|
|
129
|
+
sent_to="2348012345678",
|
|
130
|
+
sent_from="MyBrand",
|
|
131
|
+
message="Your order has been confirmed.",
|
|
132
|
+
channel="generic", # "generic", "dnd", or "voice"
|
|
133
|
+
type="plain"
|
|
134
|
+
)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
> For voice channel, `type` must be `"voice"`. WhatsApp messages must use `send_whatsapp_message()`.
|
|
138
|
+
|
|
139
|
+
**Send a WhatsApp message:**
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
# Text only
|
|
143
|
+
client.message.send_whatsapp_message(
|
|
144
|
+
sent_to="2348012345678",
|
|
145
|
+
sent_from="MyBrand",
|
|
146
|
+
message="Hello! Your appointment is confirmed."
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# With media attachment
|
|
150
|
+
client.message.send_whatsapp_message(
|
|
151
|
+
sent_to="2348012345678",
|
|
152
|
+
sent_from="MyBrand",
|
|
153
|
+
message="Here is your receipt.",
|
|
154
|
+
url="https://example.com/receipt.pdf",
|
|
155
|
+
caption="Receipt - March 2025"
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Send a bulk SMS:**
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
client.message.send_bulk_message(
|
|
163
|
+
sent_to=["2348012345678", "2349087654321"],
|
|
164
|
+
sent_from="MyBrand",
|
|
165
|
+
message="Our sale starts today!",
|
|
166
|
+
channel="generic", # "generic" or "dnd" only
|
|
167
|
+
type="plain"
|
|
168
|
+
)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
> Voice and WhatsApp are not supported for bulk messaging.
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
### Number
|
|
176
|
+
|
|
177
|
+
Send a message directly to a phone number without a sender ID:
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
client.number.send_message(
|
|
181
|
+
sent_to="2348012345678",
|
|
182
|
+
message="Your verification code is 123456."
|
|
183
|
+
)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
### Template
|
|
189
|
+
|
|
190
|
+
Send a message using a pre-approved WhatsApp template:
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
# Text template
|
|
194
|
+
client.template.send_message(
|
|
195
|
+
sent_to="2348012345678",
|
|
196
|
+
device_id="your-device-id",
|
|
197
|
+
template_id="your-template-id",
|
|
198
|
+
data={"studname": "Victor", "average": "30"}
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
# Media template (url and caption must be provided together)
|
|
202
|
+
client.template.send_message(
|
|
203
|
+
sent_to="2348012345678",
|
|
204
|
+
device_id="your-device-id",
|
|
205
|
+
template_id="your-template-id",
|
|
206
|
+
data={"name": "Victor"},
|
|
207
|
+
url="https://example.com/document.pdf",
|
|
208
|
+
caption="Course Result"
|
|
209
|
+
)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
> `device_id` is found on the Manage Device page of your Termii dashboard.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### Phonebook
|
|
217
|
+
|
|
218
|
+
**Fetch all phonebooks:**
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
client.phonebook.fetch_phonebooks()
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Create a phonebook:**
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
client.phonebook.create_phonebooks(
|
|
228
|
+
phonebook_name="Newsletter Subscribers",
|
|
229
|
+
description="Users opted in for weekly updates"
|
|
230
|
+
)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**Update a phonebook:**
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
client.phonebook.update_phonebook(
|
|
237
|
+
phonebook_id="abc123",
|
|
238
|
+
phonebook_name="VIP Customers",
|
|
239
|
+
description="High-value customer segment"
|
|
240
|
+
)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
**Delete a phonebook:**
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
client.phonebook.delete_phonebook(phonebook_id="abc123")
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
### Contact
|
|
252
|
+
|
|
253
|
+
**Fetch contacts in a phonebook:**
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
client.contact.fetch_contacts(phonebook_id="abc123")
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Add a single contact:**
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
client.contact.create_contact(
|
|
263
|
+
phonebook_id="abc123",
|
|
264
|
+
phone_number="8012345678",
|
|
265
|
+
country_code="234", # No leading "+"
|
|
266
|
+
first_name="Ada",
|
|
267
|
+
last_name="Obi",
|
|
268
|
+
email_address="ada@example.com",
|
|
269
|
+
company="Acme Ltd"
|
|
270
|
+
)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Add multiple contacts via CSV upload:**
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
client.contact.create_multiple_contacts(
|
|
277
|
+
phonebook_id="abc123",
|
|
278
|
+
country_code="234", # No leading "+"
|
|
279
|
+
file_path="/path/to/contacts.csv"
|
|
280
|
+
)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**Delete all contacts in a phonebook:**
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
client.contact.delete_contact(phonebook_id="abc123")
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
> ⚠️ `delete_contact` removes **all** contacts in the specified phonebook. Use with caution.
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
### Campaign
|
|
294
|
+
|
|
295
|
+
**Send a campaign:**
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
# Send immediately
|
|
299
|
+
client.campaign.send_campaign(
|
|
300
|
+
country_code="234", # No leading "+"
|
|
301
|
+
sender_id="MyBrand", # 3–11 characters
|
|
302
|
+
message="Big sale — ends tonight!",
|
|
303
|
+
message_type="plain", # "plain" or "unicode"
|
|
304
|
+
phonebook_id="abc123",
|
|
305
|
+
enable_link_tracking=False,
|
|
306
|
+
campaign_type="promotional",
|
|
307
|
+
schedule_sms_status="regular", # "regular" or "scheduled"
|
|
308
|
+
channel="dnd" # "dnd" or "generic"
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
# Schedule for later
|
|
312
|
+
client.campaign.send_campaign(
|
|
313
|
+
country_code="234",
|
|
314
|
+
sender_id="MyBrand",
|
|
315
|
+
message="Your monthly statement is ready.",
|
|
316
|
+
message_type="plain",
|
|
317
|
+
phonebook_id="abc123",
|
|
318
|
+
enable_link_tracking=True,
|
|
319
|
+
campaign_type="transactional",
|
|
320
|
+
schedule_sms_status="scheduled",
|
|
321
|
+
schedule_time="2025-12-31T23:59:00Z", # Required when schedule_sms_status is "scheduled"
|
|
322
|
+
channel="dnd"
|
|
323
|
+
)
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Fetch all campaigns:**
|
|
327
|
+
|
|
328
|
+
```python
|
|
329
|
+
client.campaign.fetch_campaigns()
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
**Fetch a specific campaign's history:**
|
|
333
|
+
|
|
334
|
+
```python
|
|
335
|
+
client.campaign.fetch_campaign_history(campaign_id="camp_xyz")
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**Retry a failed campaign:**
|
|
339
|
+
|
|
340
|
+
```python
|
|
341
|
+
client.campaign.retry_campaign(campaign_id="camp_xyz")
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Error Handling
|
|
347
|
+
|
|
348
|
+
The SDK validates inputs before making any network call and raises `ValueError` for invalid parameters. Wrap calls
|
|
349
|
+
accordingly:
|
|
350
|
+
|
|
351
|
+
```python
|
|
352
|
+
try:
|
|
353
|
+
response = client.message.send_message(
|
|
354
|
+
sent_to="2348012345678",
|
|
355
|
+
sent_from="MyBrand",
|
|
356
|
+
message="Hello!",
|
|
357
|
+
channel="generic",
|
|
358
|
+
type="plain"
|
|
359
|
+
)
|
|
360
|
+
except ValueError as e:
|
|
361
|
+
print(f"Validation error: {e}")
|
|
362
|
+
except Exception as e:
|
|
363
|
+
print(f"Unexpected error: {e}")
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Contributing
|
|
369
|
+
|
|
370
|
+
Contributions are welcome!
|
|
371
|
+
|
|
372
|
+
1. Fork the repository
|
|
373
|
+
2. Create a feature branch: `git checkout -b feature/your-feature`
|
|
374
|
+
3. Commit your changes: `git commit -m "feat: describe your change"`
|
|
375
|
+
4. Push: `git push origin feature/your-feature`
|
|
376
|
+
5. Open a Pull Request
|
|
377
|
+
|
|
378
|
+
Please open an issue first for significant changes.
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
Built by [Samuel Doghor](https://github.com/samdoghor) · Powered by the [Termii API](https://developer.termii.com)
|