weezy-sdk 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.
- weezy_sdk-0.1.0/LICENSE +21 -0
- weezy_sdk-0.1.0/PKG-INFO +72 -0
- weezy_sdk-0.1.0/README.md +58 -0
- weezy_sdk-0.1.0/pyproject.toml +24 -0
- weezy_sdk-0.1.0/setup.cfg +4 -0
- weezy_sdk-0.1.0/src/weezy/__init__.py +5 -0
- weezy_sdk-0.1.0/src/weezy/_transport.py +43 -0
- weezy_sdk-0.1.0/src/weezy/client.py +70 -0
- weezy_sdk-0.1.0/src/weezy/py.typed +0 -0
- weezy_sdk-0.1.0/src/weezy/resources.py +1173 -0
- weezy_sdk-0.1.0/src/weezy/types.py +68 -0
- weezy_sdk-0.1.0/src/weezy_sdk.egg-info/PKG-INFO +72 -0
- weezy_sdk-0.1.0/src/weezy_sdk.egg-info/SOURCES.txt +15 -0
- weezy_sdk-0.1.0/src/weezy_sdk.egg-info/dependency_links.txt +1 -0
- weezy_sdk-0.1.0/src/weezy_sdk.egg-info/requires.txt +1 -0
- weezy_sdk-0.1.0/src/weezy_sdk.egg-info/top_level.txt +1 -0
- weezy_sdk-0.1.0/tests/test_client.py +69 -0
weezy_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Weezy
|
|
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.
|
weezy_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: weezy-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed synchronous and asynchronous Weezy SMS and WhatsApp SDK
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/pekenio/weezy-sdk
|
|
7
|
+
Project-URL: Repository, https://github.com/pekenio/weezy-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/pekenio/weezy-sdk/issues
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: httpx<1,>=0.27
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# weezy-sdk
|
|
16
|
+
|
|
17
|
+
Typed SMS and WhatsApp clients for Python 3.11+.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install weezy-sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The package is named `weezy-sdk`; import clients from `weezy`.
|
|
26
|
+
|
|
27
|
+
For local development, install from this repository with `pip install ./python`.
|
|
28
|
+
|
|
29
|
+
## Synchronous client
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import os
|
|
33
|
+
from weezy import Weezy, WeezyError
|
|
34
|
+
|
|
35
|
+
with Weezy(
|
|
36
|
+
client_id=os.environ['WEEZY_CLIENT_ID'],
|
|
37
|
+
client_secret=os.environ['WEEZY_CLIENT_SECRET'],
|
|
38
|
+
) as client:
|
|
39
|
+
wallet = client.sms.balance()
|
|
40
|
+
message = client.sms.send(body={
|
|
41
|
+
'to': '+2250700000000', 'body': 'Bonjour !', 'sender_name': 'WEEZY',
|
|
42
|
+
})
|
|
43
|
+
status = client.sms.status(message_x_id=message['x_id'])
|
|
44
|
+
result = client.whatsapp(os.environ['WEEZY_INSTANCE_ID']).messages.send_text_message(body={
|
|
45
|
+
'phone': '2250700000000', 'message': 'Bonjour !',
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Asynchronous client
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import asyncio
|
|
53
|
+
import os
|
|
54
|
+
from weezy import AsyncWeezy
|
|
55
|
+
|
|
56
|
+
async def main():
|
|
57
|
+
async with AsyncWeezy(
|
|
58
|
+
client_id=os.environ['WEEZY_CLIENT_ID'],
|
|
59
|
+
client_secret=os.environ['WEEZY_CLIENT_SECRET'],
|
|
60
|
+
) as client:
|
|
61
|
+
print(await client.sms.balance())
|
|
62
|
+
|
|
63
|
+
asyncio.run(main())
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Send methods create real messages with live credentials. Use a dedicated test account and recipient when testing.
|
|
67
|
+
|
|
68
|
+
SMS methods: `balance()`, `senders()`, `send(body=...)`, `send_bulk(body=...)`, `status(message_x_id=...)`, `opt_outs(body=...)`. All arguments are keyword-only. WhatsApp resource methods match the backend handler names; see [the full reference](API.md).
|
|
69
|
+
|
|
70
|
+
`WeezyError` exposes `status`, `details` and `request_id`. A timeout or transport failure has status `0`. Close clients with `close()` / `await aclose()` or use the context managers above. Options include `base_url` (full client API prefix), `timeout` in seconds and an injectable `httpx` transport. No automatic retries.
|
|
71
|
+
|
|
72
|
+
TypedDict request and response contracts are exported from `weezy.types`. They support editor/type-checker assistance; runtime validation remains on the API.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# weezy-sdk
|
|
2
|
+
|
|
3
|
+
Typed SMS and WhatsApp clients for Python 3.11+.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install weezy-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package is named `weezy-sdk`; import clients from `weezy`.
|
|
12
|
+
|
|
13
|
+
For local development, install from this repository with `pip install ./python`.
|
|
14
|
+
|
|
15
|
+
## Synchronous client
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import os
|
|
19
|
+
from weezy import Weezy, WeezyError
|
|
20
|
+
|
|
21
|
+
with Weezy(
|
|
22
|
+
client_id=os.environ['WEEZY_CLIENT_ID'],
|
|
23
|
+
client_secret=os.environ['WEEZY_CLIENT_SECRET'],
|
|
24
|
+
) as client:
|
|
25
|
+
wallet = client.sms.balance()
|
|
26
|
+
message = client.sms.send(body={
|
|
27
|
+
'to': '+2250700000000', 'body': 'Bonjour !', 'sender_name': 'WEEZY',
|
|
28
|
+
})
|
|
29
|
+
status = client.sms.status(message_x_id=message['x_id'])
|
|
30
|
+
result = client.whatsapp(os.environ['WEEZY_INSTANCE_ID']).messages.send_text_message(body={
|
|
31
|
+
'phone': '2250700000000', 'message': 'Bonjour !',
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Asynchronous client
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import asyncio
|
|
39
|
+
import os
|
|
40
|
+
from weezy import AsyncWeezy
|
|
41
|
+
|
|
42
|
+
async def main():
|
|
43
|
+
async with AsyncWeezy(
|
|
44
|
+
client_id=os.environ['WEEZY_CLIENT_ID'],
|
|
45
|
+
client_secret=os.environ['WEEZY_CLIENT_SECRET'],
|
|
46
|
+
) as client:
|
|
47
|
+
print(await client.sms.balance())
|
|
48
|
+
|
|
49
|
+
asyncio.run(main())
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Send methods create real messages with live credentials. Use a dedicated test account and recipient when testing.
|
|
53
|
+
|
|
54
|
+
SMS methods: `balance()`, `senders()`, `send(body=...)`, `send_bulk(body=...)`, `status(message_x_id=...)`, `opt_outs(body=...)`. All arguments are keyword-only. WhatsApp resource methods match the backend handler names; see [the full reference](API.md).
|
|
55
|
+
|
|
56
|
+
`WeezyError` exposes `status`, `details` and `request_id`. A timeout or transport failure has status `0`. Close clients with `close()` / `await aclose()` or use the context managers above. Options include `base_url` (full client API prefix), `timeout` in seconds and an injectable `httpx` transport. No automatic retries.
|
|
57
|
+
|
|
58
|
+
TypedDict request and response contracts are exported from `weezy.types`. They support editor/type-checker assistance; runtime validation remains on the API.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "weezy-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
license-files = ["LICENSE"]
|
|
10
|
+
description = "Typed synchronous and asynchronous Weezy SMS and WhatsApp SDK"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
dependencies = ["httpx>=0.27,<1"]
|
|
14
|
+
|
|
15
|
+
[tool.setuptools.packages.find]
|
|
16
|
+
where = ["src"]
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.package-data]
|
|
19
|
+
weezy = ["py.typed"]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/pekenio/weezy-sdk"
|
|
23
|
+
Repository = "https://github.com/pekenio/weezy-sdk"
|
|
24
|
+
Issues = "https://github.com/pekenio/weezy-sdk/issues"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from urllib.parse import quote, urlsplit
|
|
3
|
+
import httpx
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class WeezyError(Exception):
|
|
7
|
+
def __init__(self, message: str, *, status: int = 0, details: Any = None, request_id: str | None = None):
|
|
8
|
+
super().__init__(message)
|
|
9
|
+
self.status = status
|
|
10
|
+
self.details = details
|
|
11
|
+
self.request_id = request_id
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def segment(value: Any) -> str:
|
|
15
|
+
if value is None or str(value) in ("", ".", ".."):
|
|
16
|
+
raise ValueError("A valid path parameter is required")
|
|
17
|
+
return quote(str(value), safe="")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def validate(client_id: str, client_secret: str, base_url: str, timeout: float) -> str:
|
|
21
|
+
if not client_id or not client_secret or ":" in client_id:
|
|
22
|
+
raise ValueError("Valid client_id and client_secret are required")
|
|
23
|
+
url = urlsplit(base_url)
|
|
24
|
+
if url.scheme not in ("https", "http") or not url.netloc or url.username or url.password or url.query or url.fragment:
|
|
25
|
+
raise ValueError("Invalid base_url")
|
|
26
|
+
if not timeout > 0 or timeout == float("inf"):
|
|
27
|
+
raise ValueError("timeout must be finite and positive")
|
|
28
|
+
return base_url.rstrip("/")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def decode(response: httpx.Response, *, unwrap: bool) -> Any:
|
|
32
|
+
if response.status_code == 204:
|
|
33
|
+
return None
|
|
34
|
+
try:
|
|
35
|
+
data = response.json()
|
|
36
|
+
except ValueError:
|
|
37
|
+
raise WeezyError("API returned a non-JSON response", status=response.status_code, details=response.text,
|
|
38
|
+
request_id=response.headers.get("x-request-id")) from None
|
|
39
|
+
envelope = isinstance(data, dict) and isinstance(data.get("code"), int) and "msg" in data
|
|
40
|
+
if response.is_error or response.is_redirect or (unwrap and envelope and data['code'] >= 400):
|
|
41
|
+
raise WeezyError(data.get("msg", f"API request failed ({response.status_code})") if isinstance(data, dict) else f"API request failed ({response.status_code})",
|
|
42
|
+
status=response.status_code, details=data, request_id=response.headers.get("x-request-id"))
|
|
43
|
+
return data.get("data") if unwrap and envelope else data
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
import httpx
|
|
3
|
+
from ._transport import WeezyError, decode, segment, validate
|
|
4
|
+
from .resources import SmsAPI, AsyncSmsAPI, WhatsAppAPI, AsyncWhatsAppAPI
|
|
5
|
+
|
|
6
|
+
DEFAULT_BASE_URL = "https://api.weezy.app/client/api/v1"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Weezy:
|
|
10
|
+
def __init__(self, *, client_id: str, client_secret: str, base_url: str = DEFAULT_BASE_URL,
|
|
11
|
+
timeout: float = 30, transport: httpx.BaseTransport | None = None):
|
|
12
|
+
self._base_url = validate(client_id, client_secret, base_url, timeout)
|
|
13
|
+
self._http = httpx.Client(auth=(client_id, client_secret), timeout=timeout, transport=transport,
|
|
14
|
+
headers={"Accept": "application/json"}, follow_redirects=False)
|
|
15
|
+
self.sms = SmsAPI(self)
|
|
16
|
+
|
|
17
|
+
def whatsapp(self, instance_id: str) -> WhatsAppAPI:
|
|
18
|
+
segment(instance_id)
|
|
19
|
+
return WhatsAppAPI(self, instance_id)
|
|
20
|
+
|
|
21
|
+
def request(self, method: str, path: str, *, body: Any = None, query: dict | None = None, unwrap: bool = False) -> Any:
|
|
22
|
+
try:
|
|
23
|
+
response = self._http.request(method, self._base_url + path, json=body,
|
|
24
|
+
params={k: v for k, v in (query or {}).items() if v is not None})
|
|
25
|
+
except httpx.TimeoutException:
|
|
26
|
+
raise WeezyError("Request timed out") from None
|
|
27
|
+
except httpx.HTTPError:
|
|
28
|
+
raise WeezyError("Network request failed") from None
|
|
29
|
+
return decode(response, unwrap=unwrap)
|
|
30
|
+
|
|
31
|
+
def close(self) -> None:
|
|
32
|
+
self._http.close()
|
|
33
|
+
|
|
34
|
+
def __enter__(self):
|
|
35
|
+
return self
|
|
36
|
+
|
|
37
|
+
def __exit__(self, *args):
|
|
38
|
+
self.close()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class AsyncWeezy:
|
|
42
|
+
def __init__(self, *, client_id: str, client_secret: str, base_url: str = DEFAULT_BASE_URL,
|
|
43
|
+
timeout: float = 30, transport: httpx.AsyncBaseTransport | None = None):
|
|
44
|
+
self._base_url = validate(client_id, client_secret, base_url, timeout)
|
|
45
|
+
self._http = httpx.AsyncClient(auth=(client_id, client_secret), timeout=timeout, transport=transport,
|
|
46
|
+
headers={"Accept": "application/json"}, follow_redirects=False)
|
|
47
|
+
self.sms = AsyncSmsAPI(self)
|
|
48
|
+
|
|
49
|
+
def whatsapp(self, instance_id: str) -> AsyncWhatsAppAPI:
|
|
50
|
+
segment(instance_id)
|
|
51
|
+
return AsyncWhatsAppAPI(self, instance_id)
|
|
52
|
+
|
|
53
|
+
async def request(self, method: str, path: str, *, body: Any = None, query: dict | None = None, unwrap: bool = False) -> Any:
|
|
54
|
+
try:
|
|
55
|
+
response = await self._http.request(method, self._base_url + path, json=body,
|
|
56
|
+
params={k: v for k, v in (query or {}).items() if v is not None})
|
|
57
|
+
except httpx.TimeoutException:
|
|
58
|
+
raise WeezyError("Request timed out") from None
|
|
59
|
+
except httpx.HTTPError:
|
|
60
|
+
raise WeezyError("Network request failed") from None
|
|
61
|
+
return decode(response, unwrap=unwrap)
|
|
62
|
+
|
|
63
|
+
async def aclose(self) -> None:
|
|
64
|
+
await self._http.aclose()
|
|
65
|
+
|
|
66
|
+
async def __aenter__(self):
|
|
67
|
+
return self
|
|
68
|
+
|
|
69
|
+
async def __aexit__(self, *args):
|
|
70
|
+
await self.aclose()
|
|
File without changes
|