smsgo 0.3.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.
- smsgo-0.3.0/.github/workflows/ci.yml +22 -0
- smsgo-0.3.0/.github/workflows/publish.yml +29 -0
- smsgo-0.3.0/.gitignore +11 -0
- smsgo-0.3.0/CHANGELOG.md +44 -0
- smsgo-0.3.0/LICENSE +21 -0
- smsgo-0.3.0/PKG-INFO +301 -0
- smsgo-0.3.0/PUBLISHING.md +45 -0
- smsgo-0.3.0/README.md +274 -0
- smsgo-0.3.0/examples/buy_credits.py +40 -0
- smsgo-0.3.0/examples/check_balance.py +23 -0
- smsgo-0.3.0/examples/check_status.py +24 -0
- smsgo-0.3.0/examples/configure_webhook.py +22 -0
- smsgo-0.3.0/examples/receive_dlr_webhook.py +47 -0
- smsgo-0.3.0/examples/send_otp.py +22 -0
- smsgo-0.3.0/examples/send_sms.py +16 -0
- smsgo-0.3.0/pyproject.toml +37 -0
- smsgo-0.3.0/src/smsgo/__init__.py +67 -0
- smsgo-0.3.0/src/smsgo/client.py +983 -0
- smsgo-0.3.0/src/smsgo/errors.py +45 -0
- smsgo-0.3.0/src/smsgo/py.typed +0 -0
- smsgo-0.3.0/tests/test_client.py +550 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.8", "3.13"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v5
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- run: python -m pip install --upgrade pip
|
|
20
|
+
- run: python -m pip install -e .
|
|
21
|
+
- name: tests
|
|
22
|
+
run: python -m unittest discover -s tests -v
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Publica no PyPI ao criar uma Release no GitHub, ou manualmente pelo botão
|
|
4
|
+
# "Run workflow" (workflow_dispatch).
|
|
5
|
+
#
|
|
6
|
+
# Usa Trusted Publishing (OIDC) — NÃO precisa de token/secret. Pré-requisito:
|
|
7
|
+
# configurar um "pending publisher" no PyPI para o projeto `smsgo`, apontando
|
|
8
|
+
# para este repositório + workflow `publish.yml` + environment `pypi`.
|
|
9
|
+
# Guia: https://docs.pypi.org/trusted-publishers/
|
|
10
|
+
on:
|
|
11
|
+
release:
|
|
12
|
+
types: [published]
|
|
13
|
+
workflow_dispatch:
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
publish:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
environment: pypi
|
|
19
|
+
permissions:
|
|
20
|
+
id-token: write # Trusted Publishing (OIDC)
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v5
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.12"
|
|
26
|
+
- run: python -m pip install --upgrade build
|
|
27
|
+
- run: python -m build
|
|
28
|
+
- name: Publish
|
|
29
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
smsgo-0.3.0/.gitignore
ADDED
smsgo-0.3.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Todas as mudanças relevantes deste pacote são documentadas aqui.
|
|
4
|
+
O formato segue [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/)
|
|
5
|
+
e o versionamento segue [SemVer](https://semver.org/lang/pt-BR/).
|
|
6
|
+
|
|
7
|
+
## [0.3.0] - 2026-07-01
|
|
8
|
+
|
|
9
|
+
### Adicionado
|
|
10
|
+
|
|
11
|
+
- **Paridade total com o SDK Node.js** (`@orynlabs/smsgo`): mesmos métodos,
|
|
12
|
+
mapeamentos de campo, autenticação e superfície de erro.
|
|
13
|
+
- SMS: `get_numbers(id, *, status=, page=)` e `get_sms_types()`.
|
|
14
|
+
- Conta: `get_balance()`, `get_auto_recharge()`, `set_auto_recharge(...)`,
|
|
15
|
+
`get_webhook()`, `set_webhook(...)`.
|
|
16
|
+
- Modo de autenticação: propriedade `mode` (`'live'`/`'test'`/`None`) e
|
|
17
|
+
`resolve_mode()`. Chaves `test_…` selecionam sandbox de forma transparente.
|
|
18
|
+
- Namespaces como atributos, compartilhando auth/refresh/erros do cliente:
|
|
19
|
+
`smsgo.contacts.*`, `smsgo.lists.*`, `smsgo.billing.*` (incl. `purchase`
|
|
20
|
+
off-session — **não idempotente**).
|
|
21
|
+
- Helper de módulo `verify_webhook_signature(raw_body, signature_header,
|
|
22
|
+
secret)` — HMAC-SHA256 do corpo bruto, comparação em tempo constante
|
|
23
|
+
(`hmac.compare_digest`). Retorna `False` para assinatura ausente/vazia/`None`.
|
|
24
|
+
- Dataclasses tipadas para todas as respostas: `Balance`, `SmsTypeItem`,
|
|
25
|
+
`AutoRechargeConfig`, `WebhookConfig`, `Plan`, `Card`, `InvoiceItem`,
|
|
26
|
+
`SendDetail`/`SendSummary`/`SendNumberDetail`/`SendNumberItem`,
|
|
27
|
+
`SendListItem`, `PurchaseResult`, `ContactDetail`, `ListResult`, e o wrapper
|
|
28
|
+
`Paginated`/`PaginationMeta`.
|
|
29
|
+
- `SMSGoError.errors` (lista de `FieldError`) preenchido em `validation_error`
|
|
30
|
+
(422); `httpCodeName` agora inclui `503 → payment_unavailable`.
|
|
31
|
+
- Exemplos: `check_balance.py`, `buy_credits.py`, `configure_webhook.py`,
|
|
32
|
+
`receive_dlr_webhook.py`.
|
|
33
|
+
|
|
34
|
+
## [0.1.0] - 2026-06-27
|
|
35
|
+
|
|
36
|
+
### Adicionado
|
|
37
|
+
|
|
38
|
+
- Cliente `SMSGo` com autenticação de 2 passos transparente (SMSGo-key → token
|
|
39
|
+
Bearer de 48h, com cache e refresh automático no 401).
|
|
40
|
+
- Métodos `send`, `send_bulk`, `list` e `get`.
|
|
41
|
+
- `SMSGoError` tipado por `code` estável (`validation_error`,
|
|
42
|
+
`insufficient_balance`, `rate_limited`, etc.).
|
|
43
|
+
- Zero dependências de runtime (usa apenas a stdlib `urllib`). Pacote tipado
|
|
44
|
+
(`py.typed`), compatível com Python 3.8+.
|
smsgo-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SMSGo
|
|
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.
|
smsgo-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: smsgo
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: SDK oficial Python para a API de SMS da SMSGo — envie SMS, OTP e campanhas no Brasil em minutos.
|
|
5
|
+
Project-URL: Homepage, https://smsgo.com.br
|
|
6
|
+
Project-URL: Repository, https://github.com/sms-go/smsgo-sdk-python
|
|
7
|
+
Project-URL: Issues, https://github.com/sms-go/smsgo-sdk-python/issues
|
|
8
|
+
Author: SMSGo
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: 2fa,brasil,otp,sms,sms-api,smsgo,totalvoice-alternative,twilio-alternative
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Communications
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# smsgo (Python)
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/smsgo/)
|
|
31
|
+
[](https://pypi.org/project/smsgo/)
|
|
32
|
+
[](https://github.com/sms-go/smsgo-sdk-python/actions/workflows/ci.yml)
|
|
33
|
+
[](./LICENSE)
|
|
34
|
+
|
|
35
|
+
SDK oficial **Python** para a [SMSGo](https://smsgo.com.br) — a API de SMS simples para o Brasil. Envie **OTP/2FA, alertas transacionais e campanhas** com poucas linhas.
|
|
36
|
+
|
|
37
|
+
- ⚡ **Integra em minutos** — autenticação cuidada pra você (sem ritual de token manual).
|
|
38
|
+
- 💸 **Sem mensalidade** — créditos pré-pagos que não expiram, preço em real.
|
|
39
|
+
- 🇧🇷 **Brasil-first** — entrega para todas as operadoras, LGPD nativo.
|
|
40
|
+
- 🟢 **Zero dependências** — usa só a biblioteca padrão. Tipado (`py.typed`).
|
|
41
|
+
- 🎁 **R$ 10 grátis** ao criar a conta — dá pra testar sem cartão.
|
|
42
|
+
|
|
43
|
+
> Nova conta e chave em **[smsgo.com.br](https://smsgo.com.br)** → painel → **Minha conta → API**.
|
|
44
|
+
|
|
45
|
+
Paridade total com o [SDK oficial Node.js](https://www.npmjs.com/package/@orynlabs/smsgo): mesmos métodos, mapeamentos de campo, autenticação e erros.
|
|
46
|
+
|
|
47
|
+
## Instalação
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install smsgo
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Requer Python 3.8+.
|
|
54
|
+
|
|
55
|
+
## Começo rápido
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import os
|
|
59
|
+
from smsgo import SMSGo
|
|
60
|
+
|
|
61
|
+
smsgo = SMSGo(api_key=os.environ["SMSGO_KEY"])
|
|
62
|
+
|
|
63
|
+
result = smsgo.send(
|
|
64
|
+
phone="+5511999990000",
|
|
65
|
+
message="Olá do SMSGo 👋",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
print(result.id, result.status) # -> "a1b2c3...", "queued"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Você passa só a `api_key`. O SDK troca a chave por um token Bearer (válido 48h), guarda em cache e renova sozinho quando expira ou retorna 401.
|
|
72
|
+
|
|
73
|
+
## Enviar um OTP (2FA)
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import random
|
|
77
|
+
from smsgo import SMSGo, SMSGoError
|
|
78
|
+
|
|
79
|
+
smsgo = SMSGo(api_key="...")
|
|
80
|
+
code = f"{random.randint(0, 999999):06d}" # 6 dígitos
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
smsgo.send(phone="+5511999990000", message=f"Seu código SMSGo é {code}. Válido por 5 minutos.")
|
|
84
|
+
# guarde `code` com TTL (ex.: Redis) e compare na verificação
|
|
85
|
+
except SMSGoError as err:
|
|
86
|
+
print(err.status, err.code, err.message)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Envio em massa
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
smsgo.send_bulk(
|
|
93
|
+
messages=[
|
|
94
|
+
{"phone": "+5511999990000", "message": "Oi, Ana!"},
|
|
95
|
+
{"phone": "+5521988887777", "message": "Oi, Bruno!"},
|
|
96
|
+
],
|
|
97
|
+
url_callback="https://seuapp.com/webhooks/smsgo", # status de entrega (opcional)
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Consultar envios
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
page = smsgo.list(page=1) # Paginated(meta, data=[SendListItem, ...])
|
|
105
|
+
detail = smsgo.get("a1b2c3-...") # SendDetail com summary de acompanhamento
|
|
106
|
+
print(detail.summary.delivered, detail.summary.done)
|
|
107
|
+
|
|
108
|
+
# Números de um envio, filtrando por bucket de status:
|
|
109
|
+
nums = smsgo.get_numbers("a1b2c3-...", status="failed", page=1) # delivered|failed|in_progress
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Modo de teste (sandbox)
|
|
113
|
+
|
|
114
|
+
Use a **chave de teste** (prefixo `test_`, no painel → Minha conta → API) como `api_key`. Nada muda no código: os envios **não debitam saldo nem são despachados de verdade**, as respostas são idênticas às de produção (com `test=True`) e os webhooks disparam com o mesmo flag.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
sandbox = SMSGo(api_key=os.environ["SMSGO_TEST_KEY"])
|
|
118
|
+
print(sandbox.resolve_mode()) # 'test' (ou use a propriedade `sandbox.mode`)
|
|
119
|
+
r = sandbox.send(phone="+5511999990000", message="teste")
|
|
120
|
+
print(r.test) # True
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`mode` retorna `None` antes da 1ª chamada autenticada; `resolve_mode()` força a resolução.
|
|
124
|
+
|
|
125
|
+
## Saldo e catálogo
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
balance = smsgo.get_balance()
|
|
129
|
+
print(balance.balance, balance.currency) # 42.50 'BRL'
|
|
130
|
+
print(balance.company["name"])
|
|
131
|
+
|
|
132
|
+
for t in smsgo.get_sms_types(): # catálogo (id vai em sms_type_id)
|
|
133
|
+
print(t.id, t.name, t.sale or t.price)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Comprar créditos + recarga automática
|
|
137
|
+
|
|
138
|
+
`billing.purchase` cobra um cartão salvo **off-session**. Informe `quantity` **ou** `plan_id`; sem `card_id`, usa o cartão padrão.
|
|
139
|
+
|
|
140
|
+
> ⚠️ **Não é idempotente**: cada chamada gera uma cobrança nova. Em timeout, consulte `smsgo.billing.invoices()` antes de repetir — não faça retry cego.
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
plans = smsgo.billing.plans() # pacotes (tiers)
|
|
144
|
+
cards = smsgo.billing.cards() # cartões salvos (4 últimos dígitos)
|
|
145
|
+
|
|
146
|
+
receipt = smsgo.billing.purchase(quantity=1000, card_id=cards[0].id)
|
|
147
|
+
print(receipt.status) # 'succeeded' já creditou o saldo | 'processing' confirma via webhook
|
|
148
|
+
print(receipt.invoice_uuid, receipt.total)
|
|
149
|
+
|
|
150
|
+
# Recarga automática + alerta de saldo:
|
|
151
|
+
smsgo.set_auto_recharge(
|
|
152
|
+
enabled=True,
|
|
153
|
+
threshold=10, # recarrega quando o saldo <= R$ 10
|
|
154
|
+
plan_quantity=1000, # compra 1000 créditos a cada recarga
|
|
155
|
+
card_id=cards[0].id, # obrigatório p/ ligar
|
|
156
|
+
alert_enabled=True,
|
|
157
|
+
alert_threshold=15, # e-mail quando o saldo <= R$ 15
|
|
158
|
+
)
|
|
159
|
+
cfg = smsgo.get_auto_recharge()
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Webhooks de saída (DLR + respostas)
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# Define a URL que recebe `sms.status` (DLR) e `sms.reply` (resposta). Guarde o secret.
|
|
166
|
+
cfg = smsgo.set_webhook(url="https://seuapp.com/webhooks/smsgo")
|
|
167
|
+
print(cfg.url, cfg.secret)
|
|
168
|
+
|
|
169
|
+
smsgo.set_webhook(rotate_secret=True) # gira o segredo
|
|
170
|
+
smsgo.set_webhook(url="") # desativa
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Cada requisição traz `X-SMSGo-Signature: sha256=<hmac>` — o HMAC-SHA256 do **corpo bruto** com o seu `secret`. **Valide sempre** com o helper embutido (comparação em tempo constante, nunca levanta exceção):
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from smsgo import verify_webhook_signature
|
|
177
|
+
|
|
178
|
+
# raw_body: bytes/str exatamente como recebido (NÃO reparseie antes de validar)
|
|
179
|
+
ok = verify_webhook_signature(raw_body, request.headers["X-SMSGo-Signature"], secret)
|
|
180
|
+
if not ok:
|
|
181
|
+
return "invalid signature", 401
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Servidor completo em [`examples/receive_dlr_webhook.py`](./examples/receive_dlr_webhook.py).
|
|
185
|
+
|
|
186
|
+
## Contatos e listas
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
list_id = smsgo.lists.create(name="Clientes VIP").id
|
|
190
|
+
contact_id = smsgo.contacts.create(
|
|
191
|
+
full_name="Ana Souza",
|
|
192
|
+
phone="+5511999990000",
|
|
193
|
+
email="ana@exemplo.com",
|
|
194
|
+
lists=[list_id],
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
smsgo.contacts.list(page=1, search="ana") # Paginated(meta, data)
|
|
198
|
+
smsgo.contacts.update(contact_id, full_name="Ana S.", phone="+5511999990000")
|
|
199
|
+
smsgo.contacts.delete(contact_id)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Tratamento de erros
|
|
203
|
+
|
|
204
|
+
Toda resposta não-2xx vira um `SMSGoError` com `status` e um `code` estável:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from smsgo import SMSGo, SMSGoError
|
|
208
|
+
|
|
209
|
+
try:
|
|
210
|
+
smsgo.send(phone="+5511999990000", message="Olá")
|
|
211
|
+
except SMSGoError as err:
|
|
212
|
+
if err.code == "insufficient_balance": # 402 — sem saldo
|
|
213
|
+
...
|
|
214
|
+
elif err.code == "rate_limited": # 429 — muitas requisições
|
|
215
|
+
...
|
|
216
|
+
elif err.code == "validation_error": # 422 — detalhe por campo
|
|
217
|
+
for fe in err.errors or []:
|
|
218
|
+
print(fe.field, fe.message)
|
|
219
|
+
else:
|
|
220
|
+
print(err.status, err.code, err.message)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
| `code` | HTTP | Significado |
|
|
224
|
+
| ----------------------- | ---- | --------------------------------- |
|
|
225
|
+
| `bad_request` | 400 | Requisição malformada |
|
|
226
|
+
| `unauthorized` | 401 | Chave/token inválido |
|
|
227
|
+
| `insufficient_balance` | 402 | Saldo insuficiente |
|
|
228
|
+
| `provider_out_of_stock` | 409 | Estoque do provedor indisponível |
|
|
229
|
+
| `validation_error` | 422 | Dados do request inválidos |
|
|
230
|
+
| `rate_limited` | 429 | Limite de envios atingido |
|
|
231
|
+
| `payment_unavailable` | 503 | Pagamento temporariamente fora |
|
|
232
|
+
| `network_error` | 0 | Falha de rede/transporte |
|
|
233
|
+
|
|
234
|
+
## Referência
|
|
235
|
+
|
|
236
|
+
### `SMSGo(api_key, *, base_url=..., timeout=30.0)`
|
|
237
|
+
|
|
238
|
+
| Parâmetro | Tipo | Default | Descrição |
|
|
239
|
+
| ---------- | ------- | -------------------------- | ------------------------------ |
|
|
240
|
+
| `api_key` | `str` | — | **Obrigatório.** Sua SMSGo-key.|
|
|
241
|
+
| `base_url` | `str` | `https://api.smsgo.com.br` | Não precisa mexer; só se a SMSGo orientar. |
|
|
242
|
+
| `timeout` | `float` | `30.0` | Timeout das requisições (s). |
|
|
243
|
+
|
|
244
|
+
### Métodos (cliente)
|
|
245
|
+
|
|
246
|
+
- `send(phone, message, *, schedule=None, reference=None, sender=None, sms_type_id=None)` → `SendResult`
|
|
247
|
+
- `send_bulk(messages, *, url_callback=None, flash_sms=None, sms_type_id=None)` → `SendResult`
|
|
248
|
+
- `list(page=1)` → `Paginated[SendListItem]`
|
|
249
|
+
- `get(id)` → `SendDetail`
|
|
250
|
+
- `get_numbers(id, *, status=None, page=None)` → `Paginated[SendNumberItem]`
|
|
251
|
+
- `get_sms_types()` → `list[SmsTypeItem]`
|
|
252
|
+
- `get_balance()` → `Balance`
|
|
253
|
+
- `get_auto_recharge()` → `AutoRechargeConfig`
|
|
254
|
+
- `set_auto_recharge(*, enabled=None, threshold=None, plan_quantity=None, card_id=None, alert_enabled=None, alert_threshold=None)` → `AutoRechargeConfig`
|
|
255
|
+
- `get_webhook()` / `set_webhook(*, url=None, rotate_secret=None)` → `WebhookConfig`
|
|
256
|
+
- `resolve_mode()` → `'live' | 'test'` · propriedade `mode` → `'live' | 'test' | None`
|
|
257
|
+
|
|
258
|
+
> `sender` é mapeado para o campo `from` da API (palavra reservada em Python).
|
|
259
|
+
|
|
260
|
+
### `smsgo.contacts`
|
|
261
|
+
|
|
262
|
+
- `list(*, page, per_page=None, search=None, title=None)` → `Paginated`
|
|
263
|
+
- `create(*, full_name, phone, email=None, lists=None)` → `str` (UUID)
|
|
264
|
+
- `get(id)` → `ContactDetail` · `update(id, *, full_name, phone, email=None, lists=None)` → `str` · `delete(id)` → `dict`
|
|
265
|
+
|
|
266
|
+
### `smsgo.lists`
|
|
267
|
+
|
|
268
|
+
- `list(*, page, per_page=None, title=None)` → `Paginated`
|
|
269
|
+
- `create(*, name)` / `get(id)` / `update(id, *, name)` → `ListResult` · `delete(id)` → `dict`
|
|
270
|
+
|
|
271
|
+
### `smsgo.billing`
|
|
272
|
+
|
|
273
|
+
- `plans()` → `list[Plan]` · `cards()` → `list[Card]`
|
|
274
|
+
- `invoices(*, page=None, per_page=None)` → `Paginated[InvoiceItem]`
|
|
275
|
+
- `purchase(*, quantity=None, plan_id=None, card_id=None, coupon=None)` → `PurchaseResult` (**não idempotente**)
|
|
276
|
+
|
|
277
|
+
### Módulo
|
|
278
|
+
|
|
279
|
+
- `verify_webhook_signature(raw_body, signature_header, secret)` → `bool` — valida `X-SMSGo-Signature` em tempo constante.
|
|
280
|
+
|
|
281
|
+
## Exemplos
|
|
282
|
+
|
|
283
|
+
Na pasta [`examples/`](./examples):
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
SMSGO_KEY=suachave python examples/send_sms.py +5511999990000
|
|
287
|
+
SMSGO_KEY=suachave python examples/send_otp.py +5511999990000
|
|
288
|
+
SMSGO_KEY=suachave python examples/check_status.py
|
|
289
|
+
SMSGO_KEY=suachave python examples/check_balance.py
|
|
290
|
+
SMSGO_KEY=suachave python examples/buy_credits.py
|
|
291
|
+
SMSGO_KEY=suachave python examples/configure_webhook.py https://seuapp.com/webhooks/smsgo
|
|
292
|
+
SMSGO_WEBHOOK_SECRET=whsec_... python examples/receive_dlr_webhook.py
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Migrando da TotalVoice / Twilio?
|
|
296
|
+
|
|
297
|
+
SMSGo foca em **DX simples e preço em real**. Sem cadastro de remetente pra começar, sem cobrança em dólar, créditos que não expiram. Há também o [SDK oficial Node.js](https://www.npmjs.com/package/@orynlabs/smsgo).
|
|
298
|
+
|
|
299
|
+
## Licença
|
|
300
|
+
|
|
301
|
+
MIT © SMSGo
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Publicando o `smsgo` (PyPI)
|
|
2
|
+
|
|
3
|
+
Guia de release do SDK Python. Registry: **PyPI** · pacote `smsgo`. Publicação por **Trusted Publishing (OIDC)** — sem token/secret.
|
|
4
|
+
|
|
5
|
+
## Pré-requisitos (uma vez)
|
|
6
|
+
|
|
7
|
+
1. Projeto `smsgo` no PyPI com um **Trusted Publisher** (ou "pending publisher" antes do 1º release) apontando para:
|
|
8
|
+
- Repositório: `sms-go/smsgo-sdk-python`
|
|
9
|
+
- Workflow: `publish.yml`
|
|
10
|
+
- Environment: `pypi`
|
|
11
|
+
- Guia oficial: https://docs.pypi.org/trusted-publishers/
|
|
12
|
+
2. No GitHub do repo → _Settings → Environments_ → criar o environment **`pypi`** (o workflow usa `environment: pypi`).
|
|
13
|
+
|
|
14
|
+
O workflow [`/.github/workflows/publish.yml`](.github/workflows/publish.yml) builda (`python -m build`) e publica via `pypa/gh-action-pypi-publish` usando OIDC. **Nenhum token é necessário.**
|
|
15
|
+
|
|
16
|
+
## Passo a passo do release
|
|
17
|
+
|
|
18
|
+
1. `master` verde no CI (`python -m unittest`).
|
|
19
|
+
2. **Suba a versão** em **dois** lugares (devem bater):
|
|
20
|
+
- [`pyproject.toml`](pyproject.toml) → `version = "0.3.0"`
|
|
21
|
+
- [`src/smsgo/__init__.py`](src/smsgo/__init__.py) → `__version__ = "0.3.0"`
|
|
22
|
+
3. Atualize o [`CHANGELOG.md`](CHANGELOG.md).
|
|
23
|
+
4. (Opcional, sanity local) `python -m pip install --upgrade build && python -m build` → confira `dist/`.
|
|
24
|
+
5. Commit + push na `master`.
|
|
25
|
+
6. **Tag + Release:**
|
|
26
|
+
```bash
|
|
27
|
+
git tag v0.3.0 && git push origin v0.3.0
|
|
28
|
+
```
|
|
29
|
+
No GitHub → _Releases → Draft a new release_ → tag `v0.3.0` → _Publish release_ → dispara o `publish.yml`.
|
|
30
|
+
- Alternativa: _Actions → Publish to PyPI → Run workflow_.
|
|
31
|
+
- Fallback com token: `python -m build && twine upload dist/*` (usando um API token do PyPI).
|
|
32
|
+
|
|
33
|
+
## Verificação pós-publicação
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip index versions smsgo # deve listar a nova versão
|
|
37
|
+
python -m venv /tmp/venv && /tmp/venv/bin/pip install "smsgo==0.3.0"
|
|
38
|
+
/tmp/venv/bin/python -c "import smsgo; print(smsgo.__version__, smsgo.verify_webhook_signature)"
|
|
39
|
+
```
|
|
40
|
+
Página: https://pypi.org/project/smsgo/
|
|
41
|
+
|
|
42
|
+
## Notas
|
|
43
|
+
|
|
44
|
+
- O PyPI é **imutável**: não dá para sobrescrever uma versão — só `yank` (esconde) e publicar uma nova.
|
|
45
|
+
- `version` do `pyproject.toml` **e** `__version__` precisam bater com a tag. Ver o guia central [`api/docs/sdks-publicacao.md`](../api/docs/sdks-publicacao.md).
|