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
Exemple de code
python -m pip install messagebird-sdkRequires Python 3.10+. The import package is bird.
2. Send an email
Export your API key. 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:
Exemple de code
export BIRD_API_KEY="bk_us1_..."Create send.py:
Exemple de code
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 automatically and reuses the call's idempotency key on each attempt. This prevents a retry from sending the message twice.
3. Run it
Exemple de code
python send.pyThe script prints the message ID and status:
Exemple de code
em_01ky7ma8y2es1s2akzk53tmjn0 acceptedaccepted is the API's 202: Bird has the message and delivers it asynchronously. Fetch it by its em_ ID with client.email.get(message.id) and watch the status move from accepted to delivered.
Next steps
- Python SDK reference: every method and option.
- Send your first email: the same flow with curl and the full sandbox address list.
- Sending domains: verify your own domain for production sending.
- Email API reference: the full request and response schema.
Ressources associées
Poursuivez avec la documentation, les guides et les exemples sur ce sujet. Les ressources sont en anglais.
Regarder le guideTesting email without spamming anyoneExplorer la fonctionnalitéTest email deliverySuivre le parcours d'apprentissageOperate messaging reliably
Essayez la pratique et obtenez un guide d'implémentation