Official Python client for letter.app - onboarding email drip campaigns. Auto-batching, retries, idempotency.
Project description
letterapp (Python)
Official Python client for letter.app - onboarding email drip campaigns for product teams.
pip install letterapp
Requires Python 3.8+. Zero runtime dependencies (standard library only).
Quick start
import os
from letterapp import Letter
letter = Letter(api_key=os.environ["LETTER_API_KEY"]) # Dashboard -> Settings -> API keys
# Tell Letter who your user is (call where users sign up or log in).
letter.identify(
user_id="user_123",
email="alice@example.com",
traits={"name": "Alice", "plan": "free"},
)
# Report something they did.
letter.track(user_id="user_123", event="Signed Up", properties={"source": "web"})
# Required before the process exits so no events are lost.
letter.close()
Or use it as a context manager, which flushes on exit:
with Letter(api_key=os.environ["LETTER_API_KEY"]) as letter:
letter.track(user_id="user_123", event="Workspace Created")
Serverless (Lambda, Cloud Functions)
There is no background time to flush in a serverless handler, so set
flush_at=1 and flush() at the end of each invocation:
letter = Letter(api_key=os.environ["LETTER_API_KEY"], flush_at=1)
def handler(event, context):
letter.track(user_id="user_123", event="Checkout Started")
letter.flush()
What it does
- Auto-batching - calls are queued and flushed every 100ms or 50 events by a background daemon thread.
- Retries -
429waitsRetry-After;5xxand network errors back off exponentially with jitter, up tomax_retries(default 3). - Idempotent - every call gets a UUID
message_idso retries are deduplicated server-side. - No dependencies - HTTP over the standard library
urllib.
API
Letter(
api_key,
base_url="https://api.letter.app", # only set for self-hosted / local
flush_at=50, # 1 for serverless
flush_interval=0.1, # seconds
max_retries=3,
timeout=10.0,
on_error=None, # callback(Exception) for bg errors
)
letter.identify(user_id, email=None, traits=None, timezone=None, timestamp=None, message_id=None)
letter.group(user_id, account_id, name=None, traits=None, timestamp=None, message_id=None)
letter.track(user_id, event, properties=None, timestamp=None, message_id=None)
letter.flush() # send queued calls now, block until done
letter.close() # flush + stop the background thread (also runs at exit)
Configuration errors and non-retryable API responses raise LetterError
(with .status and .body). Background transport errors are passed to
on_error instead, since they cannot be raised to the caller.
Full documentation
- SDK reference: https://letter.app/docs/python-sdk
- Ingestion API: https://letter.app/docs/api
License
MIT - see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file letterapp-0.1.0.tar.gz.
File metadata
- Download URL: letterapp-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.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7126626f85f2e44dfb6a158ab5323b60f57045bbcb0add04a325fce6b86fdf06
|
|
| MD5 |
1e5dc53789677ff90d2e5c93dc6e5f57
|
|
| BLAKE2b-256 |
84dc17f30df52779dd51903ddd65dcb7317544626999c1113d93afd5aa985a5e
|
File details
Details for the file letterapp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: letterapp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48892c26d5037f65bf74b499e99e5b81e8ec6b9e5b3e2f64128872295dd47cb5
|
|
| MD5 |
77f27fb026bd9269d02dcf38cdb6cb8a
|
|
| BLAKE2b-256 |
65265da66df54ce7e0560326031aebc63abf3d0a00edb2cfdd99094ff55b003a
|