Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

Texting Blue Python SDK

Official Python SDK for the Texting Blue API -- send and receive iMessages programmatically.

Installation

pip install textingblue

Quick Start

fromtextingblueimportTextingBlueclient=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")

Available Resources

ResourceMethods
client.messagessend(), list(), get()
client.numberslist(), get(), update(), delete()
client.webhookscreate(), list(), get(), update(), delete()

Webhook Verification

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"

Error Handling

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}")

Context Manager

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!")

Configuration

client=TextingBlue(
"tb_live_xxx",
base_url="https://api.texting.blue/v1", # defaulttimeout=30.0, # default, in seconds
)

Other SDKs

  • Node.js -- npm install @textingblue/node
  • PHP -- composer require textingblue/textingblue-php

Links

License

MIT

About

Official Python SDK for the Texting Blue API -- send and receive iMessages programmatically.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages