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.0.tar.gz (10.6 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.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sendbyte-0.2.0.tar.gz
  • Upload date:
  • Size: 10.6 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.0.tar.gz
Algorithm Hash digest
SHA256 7962dc16145fa8bfeb37f281c1b78f0e08d3c2eea903fe272404062f2f416573
MD5 6b216633afaf55d39517556960154256
BLAKE2b-256 23ff7ae3e84e3a089f9c466ef3c31f7da6c9d6936f5c655014ca31e59ff3ace4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sendbyte-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9228f2bfb98e6ca75f6966e2b010b72f4c0c7b137df2eb2aa9e2dd5f24566e3d
MD5 b2c21d1e0ada333e4c0efa30b6090a92
BLAKE2b-256 b2935017091ba9188a18c88c98b554b6c6548842c4f768f2e12c594f63ccce30

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