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
Ejemplo de código
python -m pip install messagebird-sdkRequires 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:
Ejemplo de código
export BIRD_API_KEY="bk_us1_..."Create send.py:
Ejemplo de código
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
Ejemplo de código
python send.pyThe script prints the message ID and status:
Ejemplo de código
em_01ky7ma8y2es1s2akzk53tmjn0 acceptedaccepted 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:
Ejemplo de código
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
- 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.
Recursos relacionados
Continúa con la documentación, guías y ejemplos sobre este tema. Los recursos están en inglés.
Ver la guíaGetting started with emailComprender el conceptoShould I use a Bird SDK or call the API directly?Explorar la funcionalidadEmailSeguir la ruta de aprendizajeBuild your first integration
Prueba el ejercicio y obtén un resumen de implementación