billionmail-python
A clean, synchronous, fully typed Python wrapper for the BillionMail Email Sending API.
Features
- Synchronous & Lightweight: Built on top of
requestswith persistentrequests.Sessionconnection pooling and context-manager support. - Strict Type Hinting: Full PEP 561 support (
py.typed) with typed responses (BillionMailResponse). - Explicit Error Mapping: Dedicated exception classes for all documented BillionMail API error codes (
1001–1005).
Installation
pip install billionmail-python
Quick Start
1. Initialize the Client
from billionmail import BillionMailClient
client = BillionMailClient(
api_key="YOUR_API_KEY",
base_url="https://mail.your-domain.com",
)
You can also use BillionMailClient as a context manager to automatically close the underlying HTTP session:
with BillionMailClient(api_key="YOUR_API_KEY", base_url="https://mail.your-domain.com") as client:
response = client.send(recipient="user@example.com")
print(response.msg)
2. Send a Single Email (/api/batch_mail/api/send)
Template variables defined in your BillionMail template (e.g., {{.API.username}}, {{.API.order_id}}) can be passed via attribs:
from billionmail import BillionMailClient
client = BillionMailClient(
api_key="YOUR_API_KEY",
base_url="https://mail.your-domain.com",
)
response = client.send(
recipient="recipient@example.com",
addresser="custom@yourdomain.com", # Optional: uses default sender if omitted
attribs={
"username": "Jesse",
"order_id": "20240501",
},
)
print(response.success) # True
print(response.code) # 0
print(response.msg) # "Email sent successfully"
3. Batch Send Emails (/api/batch_mail/api/batch_send)
Send a template email to multiple recipients at once. Note that in batch mode, attribs are shared across all recipients:
from billionmail import BillionMailClient
client = BillionMailClient(
api_key="YOUR_API_KEY",
base_url="https://mail.your-domain.com",
)
response = client.batch_send(
recipients=[
"user1@example.com",
"user2@example.com",
],
addresser="custom@yourdomain.com", # Optional
attribs={
"promo_code": "VIP2024",
"username": "Dear User",
},
)
print(response.success) # True
print(response.msg) # "Batch email send request accepted, 2 emails queued"
Error Handling
All API errors inherit from BillionMailError and map directly to BillionMail's documented error codes:
| Error Code | Exception Class | Description |
|---|---|---|
1001 |
InvalidAPIKeyError |
Invalid API key — check if the API key is correct |
1002 |
IPNotAllowedError |
IP not allowed — check IP whitelist configuration |
1003 |
InvalidRecipientError |
Invalid recipient — check email address format |
1004 |
TemplateNotFoundError |
Template does not exist — check the template ID |
1005 |
SendingFailedError |
Sending failed — check server error logs |
| Network/HTTP | BillionMailHTTPError |
Underlying network failure or non-JSON HTTP error |
from billionmail import (
BillionMailClient,
BillionMailError,
InvalidAPIKeyError,
InvalidRecipientError,
IPNotAllowedError,
SendingFailedError,
TemplateNotFoundError,
)
client = BillionMailClient(
api_key="YOUR_API_KEY",
base_url="https://mail.your-domain.com",
)
try:
client.send(recipient="recipient@example.com")
except InvalidAPIKeyError as exc:
print(f"Authentication failed (code {exc.code}): {exc.message}")
except IPNotAllowedError as exc:
print(f"Server IP is not whitelisted (code {exc.code}): {exc.message}")
except InvalidRecipientError as exc:
print(f"Bad recipient address (code {exc.code}): {exc.message}")
except TemplateNotFoundError as exc:
print(f"Missing template (code {exc.code}): {exc.message}")
except SendingFailedError as exc:
print(f"Delivery failed (code {exc.code}): {exc.message}")
except BillionMailError as exc:
print(f"BillionMail error: {exc}")
Advanced Configuration
client = BillionMailClient(
api_key="YOUR_API_KEY",
base_url="https://mail.your-domain.com",
timeout=15.0, # Default timeout in seconds (default: 30.0)
verify_ssl=True, # Set to False for self-signed certificates (equivalent to curl -k)
)
License
MIT
Metadata
Release files for billionmail-python 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| billionmail_python-0.1.0.tar.gz | 9.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| billionmail_python-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / billionmail_python-0.1.0.tar.gz
| Download URL | billionmail_python-0.1.0.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ebd3ad5f862b20b6e0b9c09535112ad935461be85908a2f8ec3eac57899901d
|
|
BLAKE2b-256 checksum How to use checksums |
bd86c2afc8596692e2907b4d67c9a239934ff247c6b0060028b9995ad05b783c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / billionmail_python-0.1.0-py3-none-any.whl
| Download URL | billionmail_python-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
895f855c1ce64bc22e95043c803fd1656ff7492691ad2acbffd68507e6f712a4
|
|
BLAKE2b-256 checksum How to use checksums |
fd73e01a00a6e0d898bbabb8f265f41365639538cefea13cb28798154600f04f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logSecurity for billionmail-python 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for billionmail_python-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.