SDK oficial Python para a API ZapApi — WhatsApp para desenvolvedores
Project description
ZapApi Python SDK
SDK oficial Python para a ZapApi — WhatsApp API para desenvolvedores.
Instalacao
pip install zapapi
Quick Start
from zapapi import ZapApi
client = ZapApi(api_key="zap_live_sua_chave_aqui")
# Criar uma sessao
session = client.sessions.create(name="Meu Bot")
# Enviar mensagem de texto
client.messages.send_text(
session_id=session["id"],
to="5511999999999@s.whatsapp.net",
text="Ola pelo ZapApi!",
)
# Listar sessoes
for s in client.sessions.list():
print(s["name"], s["status"])
Async
import asyncio
from zapapi import AsyncZapApi
async def main():
async with AsyncZapApi(api_key="zap_live_sua_chave_aqui") as client:
sessions = await client.sessions.list()
await client.messages.send_text(
session_id=sessions[0]["id"],
to="5511999999999@s.whatsapp.net",
text="Mensagem async!",
)
asyncio.run(main())
Recursos Disponiveis
| Recurso | Descricao |
|---|---|
client.sessions |
Criar, conectar, desconectar e gerenciar sessoes WhatsApp |
client.messages |
Enviar texto, midia, botoes, listas, localizacao, contato, enquete, reacao, sticker |
client.groups |
Criar e gerenciar grupos, participantes, links de convite |
client.contacts |
Verificar numeros, foto de perfil |
client.webhooks |
Registrar, atualizar, testar e gerenciar webhooks |
client.account |
Dados da conta, uso, chaves de API |
Enviar Diferentes Tipos de Mensagem
# Midia (imagem, video, audio, documento)
client.messages.send_media(
session_id="sess_abc",
to="5511999999999@s.whatsapp.net",
media_url="https://example.com/foto.jpg",
type="image",
caption="Veja esta foto!",
)
# Localizacao
client.messages.send_location(
session_id="sess_abc",
to="5511999999999@s.whatsapp.net",
latitude=-23.5505,
longitude=-46.6333,
name="Sao Paulo",
)
# Enquete
client.messages.send_poll(
session_id="sess_abc",
to="5511999999999@s.whatsapp.net",
question="Qual sua linguagem favorita?",
options=["Python", "TypeScript", "Go"],
)
# Reacao
client.messages.send_reaction(
session_id="sess_abc",
to="5511999999999@s.whatsapp.net",
message_id="msg_xyz",
emoji="👍",
)
Gerenciar Grupos
# Criar grupo
group = client.groups.create(
session_id="sess_abc",
name="Equipe Vendas",
participants=["5511999999999@s.whatsapp.net"],
)
# Adicionar participantes
client.groups.add_participants(
session_id="sess_abc",
group_id=group["id"],
participants=["5511888888888@s.whatsapp.net"],
)
# Link de convite
link = client.groups.invite_link(session_id="sess_abc", group_id=group["id"])
Webhooks
# Registrar webhook
client.webhooks.create(
url="https://meuapp.com/webhook",
events=["message.received", "session.status"],
secret="meu_segredo",
)
# Verificar assinatura no seu servidor
from zapapi import verify_signature
is_valid = verify_signature(
body=request.body, # bytes do body
signature=request.headers["X-ZapApi-Signature"],
secret="meu_segredo",
)
Tratamento de Erros
from zapapi import ZapApi, ZapApiError, RateLimitError, AuthenticationError
client = ZapApi(api_key="zap_live_...")
try:
client.sessions.get("sess_inexistente")
except AuthenticationError:
print("Chave de API invalida")
except RateLimitError as e:
print(f"Rate limit — tente novamente em {e.retry_after}s")
except ZapApiError as e:
print(f"Erro {e.status_code}: {e.message}")
Context Manager
# Sync
with ZapApi(api_key="zap_live_...") as client:
client.sessions.list()
# Async
async with AsyncZapApi(api_key="zap_live_...") as client:
await client.sessions.list()
Links
Licenca
MIT - INOVIX
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
zapapi-1.0.0.tar.gz
(12.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
zapapi-1.0.0-py3-none-any.whl
(14.6 kB
view details)
File details
Details for the file zapapi-1.0.0.tar.gz.
File metadata
- Download URL: zapapi-1.0.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cebc45bc75069929ff06739a88f6ca7929251ea36fa553f4e6a329711aa1547f
|
|
| MD5 |
eb9e94b1fb9c1d63e6365398fd24efed
|
|
| BLAKE2b-256 |
7cb810d77838d43c664fa27d6a58f9a0f10363c880e7c1720b6c95e0b9eae609
|
File details
Details for the file zapapi-1.0.0-py3-none-any.whl.
File metadata
- Download URL: zapapi-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9a4bb06d25c55558da73da1a9c1ef39bddf96273577753ca45f84bd8f71cffe
|
|
| MD5 |
75418e6c7dc8c3bfa70b177981729eca
|
|
| BLAKE2b-256 |
3065eb4501c32b1458c38c199c8a3f26f7531d04d330e8b21d8fe2e0d987e3f9
|