Send an SMS with Python
Send one message to a simulated recipient, then keep its ID for delivery tracking.
1. Prepare the workspace
Prepare an owned US-eligible SMS number, enable the US destination, complete its required registration and fund the workspace. The test recipient +15005550006 simulates delivery and is billed at the normal destination rate; it does not reach a handset. Follow workspace setup before running this sample.
2. Install and configure
Use Python 3.10 or later. In a new project directory:
Ejemplo de código
python3 -m venv .venv
source .venv/bin/activate
python -m pip install messagebird-sdk
export BIRD_API_KEY="YOUR_API_KEY"
export BIRD_SMS_FROM="YOUR_ELIGIBLE_US_NUMBER"Replace the environment values with your workspace key and eligible sender number. The SDK selects the API region from the key. Run this example on your server or development machine.
3. Run the example
Save as sms.py:
Ejemplo de código
import os
from bird import Bird
with Bird(api_key=os.environ["BIRD_API_KEY"]) as client:
message = client.sms.send(
from_=os.environ["BIRD_SMS_FROM"],
to="+15005550006",
text="Your studio visit is tomorrow at 14:00.",
category="transactional",
metadata={"booking": "FN-1042"},
)
print(message.id, message.status.value)Ejemplo de código
python sms.py4. Inspect the outcome
The response prints a message ID and the accepted status. Processing and delivery happen afterward. Inspect the ID in the SMS log or use the read example in your first SMS. The simulated destination progresses through its delivery outcome without contacting a handset.
Running this script again creates another logical send. If the result of a request is uncertain, follow idempotency guidance before sending again.
Next steps
Recursos relacionados
Continúa con la documentación, guías y ejemplos sobre este tema. Los recursos están en inglés.
Comprender el conceptoOne-way and two-way SMSUsar la herramientaCheck your message segmentsExplorar la funcionalidadTwo-way SMSSeguir la ruta de aprendizajeBuild your first integration
Obtener un resumen de implementación