Python SDK for the OpenSend email API
Project description
opensend Python SDK
Minimal first-party Python SDK for OpenSend transactional email sends with a familiar email API surface.
Use your OpenSend API key (os_...) with OpenSend as a Resend alternative.
The SDK keeps selected alias compatibility for migration-oriented code.
Installation
From this repository before the PyPI release:
python -m pip install ./packages/python-sdk
After opensend==0.1.0 is published to PyPI, install with:
python -m pip install opensend==0.1.0
Setup
Use an environment variable instead of hardcoding API keys:
export OPENSEND_API_KEY="os_your_api_key"
For self-hosted OpenSend, point the SDK at your deployment origin. The default
hosted origin is https://opensend.namuh.co.
export OPENSEND_BASE_URL="http://localhost:3015"
Send an email
The module-level surface keeps familiar Python email SDK ergonomics:
import os
import opensend
opensend.api_key = os.environ["OPENSEND_API_KEY"]
opensend.base_url = os.environ.get("OPENSEND_BASE_URL", opensend.DEFAULT_BASE_URL)
params: opensend.Emails.SendParams = {
"from": "hello@yourdomain.com",
"to": "recipient@example.com",
"subject": "Hello from OpenSend",
"html": "<h1>It works!</h1>",
}
email = opensend.Emails.send(params)
print(email["id"])
Python reserves from as a keyword argument name, but dictionary keys can still
use the OpenSend JSON field name. If you prefer constructing dictionaries
with Python identifiers, the SDK also accepts from_ or from_email and sends
that value as JSON from.
params: opensend.SendParams = {
"from_": "hello@yourdomain.com",
"to": ["recipient@example.com"],
"subject": "Hello from OpenSend",
"text": "It works!",
}
Batch send
result = opensend.Emails.send_batch([
{
"from": "hello@yourdomain.com",
"to": "a@example.com",
"subject": "Hi A",
"html": "<p>A</p>",
},
{
"from": "hello@yourdomain.com",
"to": "b@example.com",
"subject": "Hi B",
"html": "<p>B</p>",
},
])
print(result["data"])
Instance client
import os
from opensend import DEFAULT_BASE_URL, OpenSend
client = OpenSend(
os.environ["OPENSEND_API_KEY"],
base_url=os.environ.get("OPENSEND_BASE_URL", DEFAULT_BASE_URL),
)
email = client.emails.send({
"from": "hello@yourdomain.com",
"to": "recipient@example.com",
"subject": "Hello from OpenSend",
"html": "<h1>It works!</h1>",
})
Resend is also exported as an alias class for migration-oriented code:
from opensend import Resend
client = Resend(os.environ["OPENSEND_API_KEY"], base_url="http://localhost:3015")
Errors
Non-2xx API responses raise opensend.OpenSendError (also exported as
opensend.ApiError). The exception keeps OpenSend's public error envelope fields
when present.
try:
opensend.Emails.send(params)
except opensend.OpenSendError as error:
print(error.status_code, error.code, error.message, error.details)
Supported first slice
opensend.Emails.send(params)→POST /emailsopensend.Emails.send_batch(params)→POST /emails/batch- Bearer API key auth
- Configurable base URL
- Optional
idempotency_key=request header - Typed request/response structures for transactional email sends
This first package intentionally does not implement every OpenSend API resource yet.
Tests
python -m unittest discover packages/python-sdk/tests
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 opensend-0.1.0.tar.gz.
File metadata
- Download URL: opensend-0.1.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
929e0b3360c1e65c356a9ed8187cfbe9059b396ed019bbd3e23a7a454b78ed36
|
|
| MD5 |
8aeaf2ac9d6553b2535bdea55559b5ad
|
|
| BLAKE2b-256 |
479e470246458987a05714cc411178c7fa6f3ccae29d1dc4376e9c2bccb22e32
|
File details
Details for the file opensend-0.1.0-py3-none-any.whl.
File metadata
- Download URL: opensend-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
273b176675d13ee74307eeaaafebbba42fe8765dcbaeee11c8f74326b2fca49b
|
|
| MD5 |
fcd46bfb477bd783afa0a5ebf6f0cb54
|
|
| BLAKE2b-256 |
4b3acd83673dfb10599e0ef8e9b48495c4969a4adfca63cc85d7304d78bf930e
|