Skip to content

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

License

Notifications You must be signed in to change notification settings

textingblue/textingblue-python

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

from textingblue import TextingBlue

client = TextingBlue("tb_live_xxx")

# Send a message
msg = client.messages.send(
    to="+15551234567",
    from_="+15559876543",
    content="Hello from Texting Blue!",
)
print(msg["id"], msg["status"])

# List recent messages
result = client.messages.list(limit=10)
for m in result["messages"]:
    print(m["id"], m["from"], m["content"])

# Get a single message
msg = client.messages.get("msg_abc123")

Available Resources

Resource Methods
client.messages send(), list(), get()
client.numbers list(), get(), update(), delete()
client.webhooks create(), list(), get(), update(), delete()

Webhook Verification

from textingblue.webhook import verify_signature, construct_event

# Verify a signature
is_valid = verify_signature(request_body, signature_header, webhook_secret)

# Verify and parse in one step
event = construct_event(request_body, signature_header, webhook_secret)
print(event["type"])  # e.g. "message.received"

Error Handling

from textingblue import TextingBlue, AuthenticationError, RateLimitError, NotFoundError, ApiError

client = TextingBlue("tb_live_xxx")

try:
    msg = client.messages.get("msg_nonexistent")
except AuthenticationError:
    print("Check your API key")
except NotFoundError:
    print("Message not found")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except ApiError as e:
    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:

with TextingBlue("tb_live_xxx") as client:
    client.messages.send(to="+15551234567", from_="+15559876543", content="Hi!")

Configuration

client = TextingBlue(
    "tb_live_xxx",
    base_url="https://api.texting.blue/v1",  # default
    timeout=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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages