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:
Esempio di codice
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:
Esempio di codice
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)Esempio di codice
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
Risorse correlate
Prosegui con la documentazione, le guide e gli esempi per questo argomento. Le risorse sono in inglese.
Comprendi il concettoOne-way and two-way SMSUsa lo strumentoCheck your message segmentsEsplora la funzionalitàTwo-way SMSSegui il percorso di apprendimentoBuild your first integration
Ottieni un brief di implementazione