Skip to main content

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)

Billing

# Get current credit balance
balance = cb.billing.get_balance()

# List available credit packages
packages = cb.billing.list_packages()

# List credit consumption/transaction history
history = cb.billing.list_transactions()

Segments, Templates & Webhooks

The SDK also provides native access to cb.segments, cb.templates, and cb.webhooks.

# Example: Create a Webhook
cb.webhooks.create(
    url="https://yourapp.com/webhooks/castbrick",
    events=["sms.delivered", "sms.failed"]
)

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

Metadata

Release files for castbrick 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for castbrick 0.2.4
File Size Uploaded Provenance Actions
castbrick-0.2.4.tar.gz 10.2 kB With provenance Details for castbrick-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for castbrick 0.2.4
File Interpreter ABI Platform Actions
castbrick-0.2.4-py3-none-any.whl Python 3 none any Details for castbrick-0.2.4-py3-none-any.whl

Total release size: 21.5 kB

Release files / castbrick-0.2.4.tar.gz

Download URL castbrick-0.2.4.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e832251676e4eee36f6a7297ffb0e2c2906be72d22e872f8ce61d25fa7170ccc
BLAKE2b-256 checksum
How to use checksums
eb339dae232312e1fe748cbca27d16ddecb61be213fe9efc33f049fa51604eb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / castbrick-0.2.4-py3-none-any.whl

Download URL castbrick-0.2.4-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c85fac8165a3857f8cb84f97430aad23dda7d72242154c6f06c31d4df51504b
BLAKE2b-256 checksum
How to use checksums
60b168009efaecac555b3320ccd679a56466be5183863b35ba2047df788bbde8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for castbrick 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for castbrick-0.2.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page