Official Python SDK for the Texting Blue API -- send and receive iMessages programmatically.
pip install textingbluefromtextingblueimportTextingBlueclient=TextingBlue("tb_live_xxx")
# Send a messagemsg=client.messages.send(
to="+15551234567",
from_="+15559876543",
content="Hello from Texting Blue!",
)
print(msg["id"], msg["status"])
# List recent messagesresult=client.messages.list(limit=10)
forminresult["messages"]:
print(m["id"], m["from"], m["content"])
# Get a single messagemsg=client.messages.get("msg_abc123")| Resource | Methods |
|---|---|
client.messages | send(), list(), get() |
client.numbers | list(), get(), update(), delete() |
client.webhooks | create(), list(), get(), update(), delete() |
fromtextingblue.webhookimportverify_signature, construct_event# Verify a signatureis_valid=verify_signature(request_body, signature_header, webhook_secret)
# Verify and parse in one stepevent=construct_event(request_body, signature_header, webhook_secret)
print(event["type"]) # e.g. "message.received"fromtextingblueimportTextingBlue, AuthenticationError, RateLimitError, NotFoundError, ApiErrorclient=TextingBlue("tb_live_xxx")
try:
msg=client.messages.get("msg_nonexistent")
exceptAuthenticationError:
print("Check your API key")
exceptNotFoundError:
print("Message not found")
exceptRateLimitErrorase:
print(f"Rate limited. Retry after {e.retry_after}s")
exceptApiErrorase:
print(f"API error {e.status}: {e.message}")The client can be used as a context manager to ensure the underlying HTTP connection is closed:
withTextingBlue("tb_live_xxx") asclient:
client.messages.send(to="+15551234567", from_="+15559876543", content="Hi!")client=TextingBlue(
"tb_live_xxx",
base_url="https://api.texting.blue/v1", # defaulttimeout=30.0, # default, in seconds
)MIT