Skip to main content

Python SDK for the Inbox API — email management for developers

Project description

inbox-api

PyPI version Python

Python SDK for the Inbox API — email management for developers.

Installation

pip install inbox-api

Quick Start

Sync

from inbox_api import InboxApiClient

with InboxApiClient("https://api.example.com", "cw_your_token") as client:
    result = client.messages.list("account_id", page_size=5)
    for msg in result.items:
        print(f"{msg.subject} — from {msg.from_email}")

Async

import asyncio
from inbox_api import AsyncInboxApiClient

async def main():
    async with AsyncInboxApiClient("https://api.example.com", "cw_your_token") as client:
        result = await client.messages.list("account_id", page_size=5)
        for msg in result.items:
            print(f"{msg.subject} — from {msg.from_email}")

asyncio.run(main())

Authentication

The SDK authenticates using API tokens prefixed with cw_. Pass your token as the second argument to the client constructor.

client = InboxApiClient("https://api.example.com", "cw_your_token")

Resources

Resource Access Operations
Messages client.messages list, get, get_body, batch_mark_read, batch_archive, batch_move, iter_all
Threads client.threads list, get, iter_all
Send client.send send, reply, forward
Search client.search search, iter_all
Drafts client.drafts list, create, update, delete, send
Contacts client.contacts list, iter_all
Webhooks client.webhooks list, create, get, update, delete, templates
Accounts client.accounts list, get, health, digest

Send an Email

from inbox_api import InboxApiClient
from inbox_api.models.send import SendEmailRequest

with InboxApiClient("https://api.example.com", "cw_your_token") as client:
    client.send.send(SendEmailRequest(
        account_id="account_id",
        to=[{"email": "recipient@example.com"}],
        subject="Hello from Inbox API",
        body_text="Sent via the Python SDK.",
    ))

Search Messages

from inbox_api import InboxApiClient

with InboxApiClient("https://api.example.com", "cw_your_token") as client:
    results = client.search.search("account_id", "invoice")
    for msg in results.items:
        print(f"{msg.subject}{msg.snippet}")

Pagination

Use iter_all() to automatically paginate through all results:

from inbox_api import InboxApiClient

# Sync — iterate all messages
with InboxApiClient("https://api.example.com", "cw_your_token") as client:
    for msg in client.messages.iter_all("account_id"):
        print(msg.subject)
from inbox_api import AsyncInboxApiClient

# Async — iterate all messages
async with AsyncInboxApiClient("https://api.example.com", "cw_your_token") as client:
    async for msg in client.messages.iter_all("account_id"):
        print(msg.subject)
# Limit to first 5 pages for safety
with InboxApiClient("https://api.example.com", "cw_your_token") as client:
    for msg in client.messages.iter_all("account_id", max_pages=5):
        print(msg.subject)

Available on: client.messages.iter_all(), client.threads.iter_all(), client.contacts.iter_all(), client.search.iter_all().

Error Handling

from inbox_api import InboxApiClient, ApiError, RateLimitError, NotFoundError

with InboxApiClient("https://api.example.com", "cw_your_token") as client:
    try:
        msg = client.messages.get("nonexistent_id")
    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_code}: {e.message}")

Retry Configuration

The SDK automatically retries on 429 (rate limit) and 5xx (server error) responses with exponential backoff.

from inbox_api import InboxApiClient

# Default: 2 retries with exponential backoff
client = InboxApiClient("https://api.example.com", "cw_your_token")

# Disable retries
client = InboxApiClient("https://api.example.com", "cw_your_token", max_retries=0)

# More retries for batch operations
client = InboxApiClient("https://api.example.com", "cw_your_token", max_retries=5)

When a 429 response includes a Retry-After header, the SDK respects it instead of using calculated backoff.

Timeout Configuration

import httpx
from inbox_api import InboxApiClient

# Default: 30s request timeout, 5s connect timeout
client = InboxApiClient("https://api.example.com", "cw_your_token")

# Custom timeout
client = InboxApiClient(
    "https://api.example.com",
    "cw_your_token",
    timeout=httpx.Timeout(60.0, connect=10.0),
)

Advanced

Custom httpx Client

Inject a pre-configured httpx client for full control over transport settings:

import httpx
from inbox_api import InboxApiClient

custom_client = httpx.Client(
    proxy="http://proxy.example.com:8080",
)
client = InboxApiClient(
    "https://api.example.com",
    "cw_your_token",
    http_client=custom_client,
)

When you provide a custom client, the SDK will not close it on context manager exit.

License

MIT

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

inbox_api-0.1.4.tar.gz (59.4 kB view details)

Uploaded Source

Built Distribution

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

inbox_api-0.1.4-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file inbox_api-0.1.4.tar.gz.

File metadata

  • Download URL: inbox_api-0.1.4.tar.gz
  • Upload date:
  • Size: 59.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for inbox_api-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8ac462475f38ebb518de9483dd6fa89a75f3c016341261a5984a618230940bed
MD5 4f95035868c92612b2371b50692c83f2
BLAKE2b-256 6d29e803fb723dd2076617309b1b062367a417b96fdbcbc2c0adfcc1fb8eda4f

See more details on using hashes here.

File details

Details for the file inbox_api-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: inbox_api-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for inbox_api-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3aabe334a0db26897711bdbc47e1af4517920cd7bd8bf0b7b5e8a22a325fd177
MD5 339e9013a967df9f0d1d300915ac9876
BLAKE2b-256 e2f9ea8fdefe243959c243a43bce56fb31d85c40139bf1853ac35c2a0408c3f8

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