Skip to main content

SDK Python ufficiale per l'API di Sending.dev (email + WhatsApp + Telegram)

Project description

sending-sdk

SDK Python ufficiale per l'API di Sending.dev (email + WhatsApp + Telegram).

I modelli Pydantic sono generati dallo spec OpenAPI; il client e' scritto a mano per la migliore DX.

Installazione

pip install sending-sdk

Si importa come sending:

from sending import Sending

Richiede Python >= 3.10.

Uso

from sending import Sending

client = Sending(api_key="sk_...")

# Email transazionale (accetta un dict oppure un modello Pydantic)
client.emails.send({
    "to": "cliente@esempio.com",
    "from": "you@tuodominio.com",
    "subject": "Benvenuto",
    "html": "<p>Ciao!</p>",
    "idempotencyKey": "welcome-001",
})

# Messaggio multi-canale
client.messages.send({
    "channel": "whatsapp",
    "to": "+393331234567",
    "text": "Ciao!",
    "idempotencyKey": "wa-001",
})

Come context manager (chiude la connessione httpx):

with Sending(api_key="sk_...") as client:
    page = client.contacts.list(q="mario", page=1, page_size=50)
    print(page["total"], page["data"])

Client asincrono

Stessa API, su httpx.AsyncClient:

import asyncio
from sending import AsyncSending

async def main():
    async with AsyncSending(api_key="sk_...") as client:
        await client.emails.send({
            "to": "cliente@esempio.com",
            "from": "you@tuodominio.com",
            "subject": "Benvenuto",
            "html": "<p>Ciao!</p>",
            "idempotencyKey": "welcome-001",
        })
        page = await client.contacts.list(q="mario", page=1, page_size=50)
        print(page["total"])

asyncio.run(main())

Modelli tipizzati (opzionali)

from sending import models

body = models.SendEmailInput(
    to="a@b.com", **{"from": "you@dominio.com"},
    subject="Ciao", html="<p>Hi</p>", idempotencyKey="welcome-001",
)
client.emails.send(body)  # serializzato con gli alias corretti (es. "from")

Gestione errori

from sending import SendingError

try:
    client.emails.send({...})
except SendingError as err:
    print(err.status, err.code, err.body)

Risorse disponibili

emails · messages · events · campaigns · contacts · lists · tags · custom_fields · segments · domains · inboxes · email_rules · automations · webhooks · utm · integrations · usage.

Sviluppo

pip install -e ".[dev]"
python scripts/gen.py   # rigenera sending/models.py da openapi.json
pytest

Lo openapi.json viene copiato qui da pnpm openapi:generate (package @sending/openapi).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sending_sdk-0.1.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sending_sdk-0.1.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file sending_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: sending_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for sending_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7a8e4ce83a91c5b6e465b241c9771497dd49be9a94224b00210420228fa79dc2
MD5 72df784f188bea988e7bc459ff078794
BLAKE2b-256 32b27d0e180510fd57aad7c9262fa938fb1e1e69d5ef38a6bab5451269cab9d2

See more details on using hashes here.

File details

Details for the file sending_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sending_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for sending_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ecf2dea86b356a807893f304f8d72fe0a6a4b674241621b49386272c6e6e031
MD5 001ff2640de31521b01482ec7190697a
BLAKE2b-256 0accbddd0dd1f73b98a0d0b660691cd30ba6e552e75927aca9b2e2e2297314c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page