Skip to main content

SendByte Python SDK: the email API for Africa.

Project description

sendbyte

The official Python SDK for SendByte, the email API for Africa. Zero runtime dependencies (standard library only), with both synchronous and asynchronous clients.

Install

pip install sendbyte

Requires Python 3.8 or newer.

Quickstart

from sendbyte import SendByte

sendbyte = SendByte("sk_test_...")

email = sendbyte.emails.send(
    from_="PayLink <receipts@paylink.ng>",
    to="amaka@halo.ng",
    subject="Receipt for your payment",
    html="<p>Thank you. Your payment was received.</p>",
)

print(email["id"])

from_ is spelled with a trailing underscore because from is a reserved word in Python. Keys that start with sk_test_ run in the sandbox: every endpoint behaves the same, but nothing is actually delivered. Switch to an sk_live_ key to send for real.

Configuration

sendbyte = SendByte("sk_live_...", base_url="https://api.sendbyte.africa")

Async client

AsyncSendByte exposes the same surface with awaitable methods, running the transport in the default executor so the SDK stays dependency free.

import asyncio
from sendbyte import AsyncSendByte

async def main():
    sendbyte = AsyncSendByte("sk_test_...")
    email = await sendbyte.send_email(
        from_="PayLink <receipts@paylink.ng>",
        to="amaka@halo.ng",
        subject="Receipt",
        html="<p>Thank you.</p>",
    )
    print(email["id"])

asyncio.run(main())

API

Emails

sendbyte.emails.send(from_=..., to=..., subject=..., html=...)
sendbyte.emails.get("em_123")
sendbyte.emails.list(limit=20, status="delivered")

to, cc, bcc, and reply_to accept a single address or a list. Pass idempotency_key to make retries safe, scheduled_at for future sends, and template_id with variables to render a server side template.

Domains

domain = sendbyte.domains.create("paylink.ng")
# domain["dns_records"] lists the SPF, DKIM, and DMARC records to publish
sendbyte.domains.list()
sendbyte.domains.get(domain["id"])
sendbyte.domains.verify(domain["id"])

Webhooks

endpoint = sendbyte.webhooks.create(
    "https://example.com/hooks/sendbyte",
    ["email.delivered", "email.bounced"],
)
# endpoint["secret"] is shown once, store it now
sendbyte.webhooks.list()
sendbyte.webhooks.disable(endpoint["id"])
sendbyte.webhooks.replay("evt_123")

Verifying webhook signatures

Every webhook request carries a sendbyte-signature header. Verify it against the raw request body before trusting the payload.

from sendbyte import verify_webhook_signature

@app.post("/hooks/sendbyte")
def hooks(request):
    valid = verify_webhook_signature(
        secret=os.environ["SENDBYTE_WEBHOOK_SECRET"],
        header=request.headers.get("sendbyte-signature"),
        body=request.get_data(),  # the raw, unparsed body
    )
    if not valid:
        return "", 401
    # handle the event
    return "", 200

The check rejects missing, malformed, tampered, and stale signatures (default tolerance is 300 seconds) and never raises.

Errors

Failed requests raise a SendByteError carrying the API error shape.

from sendbyte import SendByteError

try:
    sendbyte.emails.send(from_=..., to=..., subject=..., html=...)
except SendByteError as err:
    print(err.code, err.status, err.docs_url)

Links

License

MIT

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

sendbyte-0.2.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

sendbyte-0.2.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file sendbyte-0.2.1.tar.gz.

File metadata

  • Download URL: sendbyte-0.2.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for sendbyte-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9b83edb6b03ecacc748bdc3838a4e16ffafc674466ff4db3e62127e6dc617c58
MD5 7f528239bc2097d42dd80fd4bd57f775
BLAKE2b-256 31a8c63867edcc1dbe4ac8fede8fc194724b2a11af3c91532dc0328908a947c7

See more details on using hashes here.

File details

Details for the file sendbyte-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: sendbyte-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for sendbyte-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f0a09db1b3cf96925f364c53e09516d58ccc43730f6b463ebe4b3d96c67392c
MD5 0f0aed81fbea8f208372ded7825e74ce
BLAKE2b-256 89933d9cd7ffd00e10c8c733e96dd83da58f24930af8e6b21757cca3ead050ed

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