Bird

Python

Send your first email from a plain Python script using the Bird Python SDK's sync client. Three steps: install, send, run.

1. Install the SDK

代码示例
python -m pip install messagebird-sdk
Requires Python 3.10+. The import package is bird.

2. Send an email

Create an API key with permission to send and read email, then export it. The SDK reads BIRD_API_KEY from the environment and infers the region (us1 or eu1) from the bk_us1_ / bk_eu1_ prefix, so Bird() needs no arguments:
代码示例
export BIRD_API_KEY="bk_us1_..."
Create send.py:
代码示例
from bird import APIError, Bird

with Bird() as client:
    try:
        message = client.email.send(
            from_={"email": "onboarding@messagebird.dev", "name": "Bird"},
            to=["delivered@messagebird.dev"],
            subject="Hello from Bird",
            html="<p>My first Bird email.</p>",
        )
        print(message.id, message.status)
    except APIError as err:
        print("send failed:", err)
from_ is the Python spelling of the from field (from is a reserved word). onboarding@messagebird.dev is Bird's shared onboarding sender (no domain verification needed) and delivered@messagebird.dev is a sandbox recipient that always delivers.
The SDK retries transient failures with the same idempotency key. Completed responses are replayed within a three-hour window; a lost response can still leave the outcome uncertain. Follow the retry guidance before starting another send.

3. Run it

代码示例
python send.py
The script prints the message ID and status:
代码示例
em_01ky7ma8y2es1s2akzk53tmjn0 accepted
accepted is the API's 202: Bird accepted the request and processes delivery asynchronously. Copy the printed em_ ID, then save this as check.py, replacing YOUR_MESSAGE_ID with that ID:
代码示例
from bird import Bird

with Bird() as client:
    message = client.email.get("YOUR_MESSAGE_ID")
    print(message.id, message.status, message.delivered_count)
Run python check.py with the same BIRD_API_KEY. This opens a fresh client and reads the original send; it does not send another message. If delivery is still pending, run the check again later. The events guide explains each recipient outcome.
For a failed send, correct authentication or validation errors before retrying. For a timeout or server error, inspect the email log before creating a new operation; a missing response does not prove the first request failed.

Next steps