Skip to main content

Python SDK for the UseSend API

Project description

UseSend Python SDK

A minimal Python SDK for the UseSend API, mirroring the structure of the JavaScript SDK.

Installation

Install via pip or Poetry:

pip install usesend
# or
poetry add usesend

Usage

from usesend import UseSend, types

# By default: raises UseSendHTTPError on non-2xx.
client = UseSend("us_123")

# 1) TypedDict payload (autocomplete in IDEs). Use dict to pass 'from'.
payload: types.EmailCreate = {
    "to": "test@example.com",
    "from": "no-reply@example.com",
    "subject": "Hello",
    "html": "<strong>Hi!</strong>",
}
resp, _ = client.emails.send(payload=payload)

# 2) Or pass a plain dict (supports 'from')
resp, _ = client.emails.send(payload={
    "to": "test@example.com",
    "from": "no-reply@example.com",
    "subject": "Hello",
    "html": "<strong>Hi!</strong>",
})

# 3) Campaigns
campaign_payload: types.CampaignCreate = {
    "name": "Welcome Series",
    "subject": "Welcome to our service!",
    "html": "<p>Thanks for joining us!</p>",
    "from": "welcome@example.com",
    "contactBookId": "cb_1234567890",
}
campaign_resp, _ = client.campaigns.create(payload=campaign_payload)

# Schedule a campaign
schedule_payload: types.CampaignSchedule = {
    "scheduledAt": "2024-12-01T10:00:00Z",
}
schedule_resp, _ = client.campaigns.schedule(
    campaign_id=campaign_resp["id"],
    payload=schedule_payload
)

# Pause/resume campaigns
client.campaigns.pause(campaign_id="campaign_123")
client.campaigns.resume(campaign_id="campaign_123")

# Toggle behavior if desired:
# - raise_on_error=False: return (None, error_dict) instead of raising
# No model parsing occurs; methods return plain dicts following the typed shapes.
client = UseSend("us_123", raise_on_error=False)
raw, err = client.emails.get(email_id="email_123")
if err:
    print("error:", err)
else:
    print("ok:", raw)

Development

This package is managed with Poetry. Models are maintained in-repo under usesend/types.py (readable names). Update this file as the API evolves.

It is published as usesend on PyPI.

Available Resources

  • Emails: client.emails.send(), client.emails.get()
  • Contacts: client.contacts.create(), client.contacts.get(), client.contacts.list()
  • Domains: client.domains.create(), client.domains.get(), client.domains.verify()
  • Campaigns: client.campaigns.create(), client.campaigns.get(), client.campaigns.schedule(), client.campaigns.pause(), client.campaigns.resume()

Notes

  • Human-friendly models are available under usesend.types (e.g., EmailCreate, CampaignCreate, Contact, APIError).
  • Endpoint methods accept TypedDict payloads or plain dicts via the payload= keyword.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usesend-0.2.7.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usesend-0.2.7-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file usesend-0.2.7.tar.gz.

File metadata

  • Download URL: usesend-0.2.7.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for usesend-0.2.7.tar.gz
Algorithm Hash digest
SHA256 0e1b2de022734730b11849fb2f2896d4afdc44d47f0b8d4308abd9ecd12d538f
MD5 c6b65427c86c0ddbce5c4b18a602a7f4
BLAKE2b-256 cfce5fdde94867d4fe444995a72a6849b15d2f38bc1c6ce3961ba6eed4af0589

See more details on using hashes here.

File details

Details for the file usesend-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: usesend-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.24

File hashes

Hashes for usesend-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b55226dd310144e56fc89442d82ea32ae85f2630cc267b94ebc0fbdc3729d0bf
MD5 fe9fcce063ea55a2050a9655e9e5e932
BLAKE2b-256 32f7cc25254eb595210f8516df43b9dadafa634707a5a13c3230ed5edcbfdbea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page