Skip to main content

The physical-mail API for AI agents. Send a real, tracked, compliant letter with one call.

Project description

Agent Letter — Python SDK

The physical-mail API for AI agents. Send a real, tracked, compliant letter with one call — the postal equivalent of giving an agent an email address.

Private beta. Request access at agentletter.dev.

Install

pip install agentletter

Quickstart

from agentletter import AgentLetter

client = AgentLetter()  # reads AGENTLETTER_API_KEY from the environment

letter = client.send(
    to={
        "name": "Jane Doe",
        "line1": "1 Market St",
        "city": "San Francisco",
        "state": "CA",
        "zip": "94105",
    },
    body=pdf_bytes,     # PDF bytes — or html="..." / template="..."
    certified=True,     # proof of delivery
)

print(letter.id, letter.status)  # "ltr_9f2a"  "in_transit"

Set your key once:

export AGENTLETTER_API_KEY="sk_live_..."

Sending content

Provide exactly one of:

client.send(to=addr, body=pdf_bytes)                       # a PDF
client.send(to=addr, html="<h1>Notice</h1>...")            # rendered HTML
client.send(to=addr, template="tmpl_123",
            variables={"name": "Jane", "amount": "$420"})  # a saved template

Typed addresses are supported too:

from agentletter import Address

client.send(
    to=Address(name="Jane Doe", line1="1 Market St",
               city="San Francisco", state="CA", zip="94105"),
    body=pdf_bytes,
)

Tracking

letter = client.get("ltr_9f2a")
print(letter.status, letter.tracking_number, letter.expected_delivery)

Async

import asyncio
from agentletter import AsyncAgentLetter

async def main():
    async with AsyncAgentLetter() as client:
        letter = await client.send(to=addr, body=pdf_bytes, certified=True)
        print(letter.id)

asyncio.run(main())

Errors

All errors subclass AgentLetterError:

from agentletter import AgentLetterError, AuthenticationError, RateLimitError

try:
    client.send(to=addr, body=pdf_bytes)
except AuthenticationError:
    ...   # bad / missing key
except RateLimitError:
    ...   # back off and retry
except AgentLetterError as e:
    print(e.status_code, e.message)

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

agentletter-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

agentletter-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file agentletter-0.1.0.tar.gz.

File metadata

  • Download URL: agentletter-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for agentletter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d78d16e2da9888b0336e9b292fae8c5e39e8c5bf5383f32c2349ebaba7107f0b
MD5 42bb12f656012998ee8b60806314bbc4
BLAKE2b-256 b82be9e6992ee286ac2204b96f89628aaf523f10fa639bdf6ac7cc4b2b619284

See more details on using hashes here.

File details

Details for the file agentletter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agentletter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for agentletter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33f0264d5eef01dabe5295eab66683349ee4eee04218ebca4fda489284d761b6
MD5 c92d72ac550570d840c955766957a802
BLAKE2b-256 a4119e7e213a5487ea7c368ab24d700e9e6141ca3d101f249aa439a0dd38b0a0

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