Skip to main content

Production-grade Python SDK for the AxeDz CPaaS API (SMS, Email, Wallet)

Project description

AxeDz Python SDK

Production-grade Python SDK for the AxeDz CPaaS platform. Send SMS and email, manage wallet balances, and inspect usage transactions with a clean, typed API inspired by Stripe and Twilio SDKs.

Features

  • SMS and email sending
  • Wallet balance and transaction history
  • API key authentication via x-api-key header
  • Automatic retries with exponential backoff (network and 5xx errors)
  • Rich, typed exception hierarchy
  • Standardized response envelope (success, data, meta)
  • Optional async client via httpx
  • Environment variable configuration

Installation

pip install axedz

For async support:

pip install axedz[async]

Authentication

All requests are authenticated with your AxeDz API key via the x-api-key header:

x-api-key: <API_KEY>

You can pass the key directly or via environment variable:

export AXEDZ_API_KEY="your_api_key"
export AXEDZ_BASE_URL="https://your-api.example.com/api"  # optional

Quick Start

from axedz import AxeDz

client = AxeDz("API_KEY")

# Send SMS
client.sms.send("+213xxxxxxxx", "Hello")

# Send email
client.email.send(
    "user@mail.com",
    "Welcome",
    text="Hello from AxeDz",
)

# Wallet balance
print(client.wallet.balance())

# Usage transactions
print(client.wallet.transactions(limit=20, offset=0))

Usage

Initialize the client

from axedz import AxeDz

client = AxeDz(
    api_key="your_api_key",
    base_url="http://localhost:3000/api",  # default
    timeout=10,                             # seconds
    max_retries=2,                          # retry network/5xx failures
    debug=False,                            # enable request logging
)

Or use environment variables:

client = AxeDz()  # reads AXEDZ_API_KEY and AXEDZ_BASE_URL

Use as a context manager to ensure the HTTP session is closed:

with AxeDz("API_KEY") as client:
    client.sms.send("+213555123456", "Hello")

SMS

response = client.sms.send(
    to="+213555123456",
    message="Your verification code is 123456",
)

print(response["success"])  # True
print(response["data"])     # {"id": "...", "status": "queued"}
print(response["meta"])     # {"status_code": 202, ...}

Optional provider override:

client.sms.send("+213555123456", "Hello", provider="twilio")

Email

Send plain text:

client.email.send(
    "user@example.com",
    "Welcome to AxeDz",
    text="Thanks for signing up!",
)

Send HTML:

client.email.send(
    "user@example.com",
    "Invoice",
    html="<h1>Your invoice</h1><p>Thank you.</p>",
)

Send to multiple recipients and include callback metadata:

client.email.send(
    to=["user1@example.com", "user2@example.com"],
    subject="Welcome",
    body="<h1>Hello World</h1>",
    body_type="html",
    sender_name="AxeDz",
    callback_url="https://webhook.site/129b1309-5626-4a61-ac52-60f73fe4aa6b",
    callback_data={"user_id": 123},
)

Wallet

Fetch balance:

balance = client.wallet.balance()
print(balance["data"]["balance"])
print(balance["data"]["currency"])

List usage transactions:

transactions = client.wallet.transactions(limit=20, offset=0)

for event in transactions["data"]["records"]:
    print(event)

pagination = transactions["data"]["pagination"]
print(pagination["total"], pagination["hasMore"])

Response format

Every SDK method returns a normalized envelope:

{
    "success": True,
    "data": { ... },   # API payload
    "meta": { ... },   # status code, headers, pagination, etc.
}

Raw HTTP responses are never exposed.

Error handling

The SDK raises typed exceptions with full context:

Exception When
ValidationError Invalid input or 400/422 API responses
AuthenticationError Missing/invalid API key (401/403)
RateLimitError Rate limit exceeded (429)
ServerError Server-side failures (5xx)
NetworkError Timeouts and connectivity issues
AxeDzError Base class for all SDK errors

Example:

from axedz import AxeDz, AuthenticationError, ValidationError

client = AxeDz("API_KEY")

try:
    client.sms.send("", "Hello")
except ValidationError as error:
    print(error.message)
    print(error.status_code)
    print(error.response_body)
    print(error.request)
except AuthenticationError as error:
    print("Check your API key:", error.message)

Retries

The SDK automatically retries failed requests when:

  • A network error occurs (timeout, connection failure)
  • The API returns a 5xx server error

It does not retry validation, authentication, or rate-limit errors. Retries use exponential backoff (default: 2 attempts).

Async client (optional)

import asyncio
from axedz.async_client import AsyncAxeDz

async def main():
    async with AsyncAxeDz("API_KEY") as client:
        result = await client.sms.send("+213555123456", "Hello")
        print(result)

asyncio.run(main())

Install async dependencies first:

pip install axedz[async]

Development

git clone https://github.com/axedz/axedz-python.git
cd axedz-python
pip install -e ".[dev]"
pytest

License

MIT — see LICENSE.

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

axedz-2.0.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

axedz-2.0.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file axedz-2.0.0.tar.gz.

File metadata

  • Download URL: axedz-2.0.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for axedz-2.0.0.tar.gz
Algorithm Hash digest
SHA256 0803f5c4a9e2785941b898ba376468aa66f198f0607691e1384cafb926a4cde1
MD5 7b5eb83412d2c92d125408b518a03d66
BLAKE2b-256 653f57101fed130f59c944f2d8b5a5156c501574db4fb97c2e7a193daeed26b2

See more details on using hashes here.

File details

Details for the file axedz-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: axedz-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for axedz-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b69b15aa91dd63b3806d85883f144a2edf1dc0bc70950e93d0ff429a419febe6
MD5 4309edf6fbc1c32eaedea092972baca9
BLAKE2b-256 e9d82b6fe704c6ddf1086c8fd1d1820f7d8c8bfd741cdaa696d3ae66d0cba2f1

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