Skip to main content

Official Python SDK for the CastBrick API — SMS, Contacts and Broadcasts.

Project description

castbrick

Official Python SDK for the CastBrick API — send SMS, manage contacts and run broadcasts.

Zero dependencies. Works with Python 3.8+.

Installation

pip install castbrick

Quick start

import os
from castbrick import CastBrick

cb = CastBrick(api_key=os.environ["CASTBRICK_API_KEY"])

result = cb.sms.send(
    to=["+244923000000"],
    content="Hello from CastBrick!",
)
print(result.message_id, result.status)

SMS

# Send
result = cb.sms.send(
    to=["+244923000000", "+244912000000"],
    content="Your OTP is 1234",
    sender_id="MyApp",                    # optional — your approved Sender ID
    scheduled_at="2026-11-28T09:00:00Z",  # optional — schedule for later
    fallback=True,                        # optional — fall back to CastBrick sender if senderId unavailable
)

# List (with optional filters)
page = cb.sms.list(
    page=1,
    page_size=20,
    status="delivered",           # pending | sent | delivered | failed | scheduled
    phone="+244923000000",
    from_date="2026-01-01T00:00:00Z",
    to_date="2026-06-01T00:00:00Z",
)
print(page.total_count)

# Cancel a scheduled SMS
cb.sms.cancel_scheduled("message-id")

Contacts

# List (with optional search)
page = cb.contacts.list(search="joão")

# Get
contact = cb.contacts.get("contact-id")

# Create — comma or newline-separated phone numbers
cb.contacts.create(phone_numbers="+244923000000\n+244912000000")

# Delete
cb.contacts.delete("contact-id")

# Contact lists
list_id = cb.contacts.create_list("VIP Customers")  # returns the new list ID (str)
cb.contacts.add_to_list(list_id, contact.id)
cb.contacts.remove_from_list(list_id, contact.id)

Broadcasts

# Create
broadcast_id = cb.broadcasts.create(
    name="Black Friday",
    message="50% off everything today!",
    contact_list_id="list-id",  # optional
    sender_id="MyApp",          # optional
)

# Send immediately
cb.broadcasts.send(broadcast_id)

# Update with schedule
cb.broadcasts.update(
    broadcast_id,
    name="Black Friday",
    message="50% off everything today!",
    schedule_at="2026-11-28T09:00:00Z",
)

# Other operations
cb.broadcasts.cancel(broadcast_id)
new_id = cb.broadcasts.duplicate(broadcast_id)
cb.broadcasts.delete(broadcast_id)

Error handling

from castbrick import CastBrickApiError

try:
    cb.sms.send(to=["+244923000000"], content="Hello!")
except CastBrickApiError as e:
    print(f"{e.status_code}: {e.body}")
    # 401 → invalid or revoked API key
    # 402 → insufficient credits
    # 422 → validation error

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

castbrick-0.1.3.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

castbrick-0.1.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file castbrick-0.1.3.tar.gz.

File metadata

  • Download URL: castbrick-0.1.3.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for castbrick-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fdd060f0c1785f22a571455a3605ca27f3d93f9ebd9445035e010c87fb4f86d0
MD5 14e6803317d35494d93faed377f3276f
BLAKE2b-256 8ce0ca1e95ff72419f140a88debc284912201ed5a0da2edbc9bb43b0fcd4c9b5

See more details on using hashes here.

File details

Details for the file castbrick-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: castbrick-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for castbrick-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cbf3363d8af269e953b03ad93b8c23f6ceaacce4c6ef050ea23ba51e863ef1a6
MD5 5fe5176184b8bf847c909f4c5124e4a3
BLAKE2b-256 db9f436e9d7e53279b16798a7665bebffa1db730e8bf8d6daa4921bca496f069

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