Python SDK
PyPI: coffeemail v0.1.0Complete reference for the official coffeemail package for Python (PyPI). Synchronous and asynchronous (FastAPI/asyncio) support, Pydantic v2 models, safe return data, error pattern and .unwrap() method.
Looking for Node.js or TypeScript docs? Check the official reference for the @coffeemail/node package.
Installation
pypi.org/project/coffeemail ↗1. Synchronous Client (Django, Flask, Celery)
Support for synchronous (CoffeeMail) and asynchronous (AsyncCoffeeMail) clients. The API Key is automatically loaded from COFFEEMAIL_API_KEY if omitted.
CoffeeMail(api_key: str | None = None, *, timeout: float = 10.0, locale: Locale = "pt-BR")2. Asynchronous Client (FastAPI, asyncio, Temporal)
Support for synchronous (CoffeeMail) and asynchronous (AsyncCoffeeMail) clients. The API Key is automatically loaded from COFFEEMAIL_API_KEY if omitted.
AsyncCoffeeMail(api_key: str | None = None, *, timeout: float = 10.0, locale: Locale = "pt-BR")Tuple Unpacking (Recommended)
Padrão Idiomático SeguroAll operations return an instance of CoffeeMailResponse[T] allowing direct unpacking of data, error or calling .unwrap() to raise catchable exceptions.
.unwrap() Method (Exception Style)
Try / ExceptAll operations return an instance of CoffeeMailResponse[T] allowing direct unpacking of data, error or calling .unwrap() to raise catchable exceptions.
Cryptographic Webhook Validation
The Webhooks.verify_signature utility validates the HMAC SHA-256 signature in the x-coffeemail-signature header against payload tampering.
Emails
.send()
Synchronous Signature:client.emails.send(payload: SendEmailPayload | dict) -> CoffeeMailResponse[SendEmailResponse]Asynchronous Signature:await async_client.emails.send(payload: SendEmailPayload | dict) -> CoffeeMailResponse[SendEmailResponse]Sends a transactional email synchronously or asynchronously.
.send_batch()
Synchronous Signature:client.emails.send_batch(emails: list[SendEmailPayload | dict]) -> CoffeeMailResponse[BatchSendEmailResult]Asynchronous Signature:await async_client.emails.send_batch(emails: list[SendEmailPayload | dict]) -> CoffeeMailResponse[BatchSendEmailResult]Sends multiple emails in a single optimized batch.
.get()
Synchronous Signature:client.emails.get(email_id: str) -> CoffeeMailResponse[EmailDetail]Asynchronous Signature:await async_client.emails.get(email_id: str) -> CoffeeMailResponse[EmailDetail]Retrieves email details, delivery status, and timestamps.
.list()
Synchronous Signature:client.emails.list(limit: int | None = None, after: str | None = None, status: str | None = None) -> CoffeeMailResponse[ListEmailsResponse]Asynchronous Signature:await async_client.emails.list(limit: int | None = None, after: str | None = None, status: str | None = None) -> CoffeeMailResponse[ListEmailsResponse]Lists recent emails with pagination and status filters.
.cancel()
Synchronous Signature:client.emails.cancel(email_id: str) -> CoffeeMailResponse[dict[str, object]]Asynchronous Signature:await async_client.emails.cancel(email_id: str) -> CoffeeMailResponse[dict[str, object]]Cancels a scheduled email before delivery.
Domains
.create()
Synchronous Signature:client.domains.create(name: str) -> CoffeeMailResponse[CreateDomainResponse]Asynchronous Signature:await async_client.domains.create(name: str) -> CoffeeMailResponse[CreateDomainResponse]Registers a new sending domain and returns required DNS records.
.verify()
Synchronous Signature:client.domains.verify(domain_id: str) -> CoffeeMailResponse[DomainDetail]Asynchronous Signature:await async_client.domains.verify(domain_id: str) -> CoffeeMailResponse[DomainDetail]Runs active verification for SPF, DKIM, DMARC, and MX records.
.list()
Synchronous Signature:client.domains.list() -> CoffeeMailResponse[ListDomainsResponse]Asynchronous Signature:await async_client.domains.list() -> CoffeeMailResponse[ListDomainsResponse]Lists configured domains for the organization.
.get()
Synchronous Signature:client.domains.get(domain_id: str) -> CoffeeMailResponse[DomainDetail]Asynchronous Signature:await async_client.domains.get(domain_id: str) -> CoffeeMailResponse[DomainDetail]Gets details and DNS propagation status for a domain.
.delete()
Synchronous Signature:client.domains.delete(domain_id: str) -> CoffeeMailResponse[dict[str, object]]Asynchronous Signature:await async_client.domains.delete(domain_id: str) -> CoffeeMailResponse[dict[str, object]]Removes a registered sending domain.
Templates
.create()
Synchronous Signature:client.templates.create(payload: CreateTemplatePayload | dict) -> CoffeeMailResponse[TemplateDetail]Asynchronous Signature:await async_client.templates.create(payload: CreateTemplatePayload | dict) -> CoffeeMailResponse[TemplateDetail]Creates an email template with dynamic variables.
.preview()
Synchronous Signature:client.templates.preview(payload: PreviewTemplatePayload | dict) -> CoffeeMailResponse[PreviewTemplateResponse]Asynchronous Signature:await async_client.templates.preview(payload: PreviewTemplatePayload | dict) -> CoffeeMailResponse[PreviewTemplateResponse]Renders an HTML preview of the template with simulated variables.
.list()
Synchronous Signature:client.templates.list() -> CoffeeMailResponse[list[TemplateDetail]]Asynchronous Signature:await async_client.templates.list() -> CoffeeMailResponse[list[TemplateDetail]]Lists email templates registered in the organization.
Audiences
.create()
Synchronous Signature:client.audiences.create(payload: CreateAudiencePayload | dict) -> CoffeeMailResponse[AudienceDetail]Asynchronous Signature:await async_client.audiences.create(payload: CreateAudiencePayload | dict) -> CoffeeMailResponse[AudienceDetail]Creates a new audience list for contacts and campaigns.
.add_contact()
Synchronous Signature:client.audiences.add_contact(audience_id: str, payload: ContactPayload | dict) -> CoffeeMailResponse[ContactDetail]Asynchronous Signature:await async_client.audiences.add_contact(audience_id: str, payload: ContactPayload | dict) -> CoffeeMailResponse[ContactDetail]Adds or updates a contact in an audience.
.bulk_add()
Synchronous Signature:client.audiences.bulk_add(audience_id: str, contacts: list[ContactPayload | dict]) -> CoffeeMailResponse[BulkContactResult]Asynchronous Signature:await async_client.audiences.bulk_add(audience_id: str, contacts: list[ContactPayload | dict]) -> CoffeeMailResponse[BulkContactResult]Imports contacts in bulk into an existing audience.
Broadcasts
.create()
Synchronous Signature:client.broadcasts.create(payload: CreateBroadcastPayload | dict) -> CoffeeMailResponse[BroadcastDetail]Asynchronous Signature:await async_client.broadcasts.create(payload: CreateBroadcastPayload | dict) -> CoffeeMailResponse[BroadcastDetail]Creates a broadcast campaign associated with an audience.
.send()
Synchronous Signature:client.broadcasts.send(broadcast_id: str) -> CoffeeMailResponse[BroadcastDetail]Asynchronous Signature:await async_client.broadcasts.send(broadcast_id: str) -> CoffeeMailResponse[BroadcastDetail]Triggers broadcast delivery to all active subscribers in the audience.
Suppressions
.list()
Synchronous Signature:client.suppressions.list(limit: int | None = None, after: str | None = None) -> CoffeeMailResponse[ListSuppressionsResponse]Asynchronous Signature:await async_client.suppressions.list(limit: int | None = None, after: str | None = None) -> CoffeeMailResponse[ListSuppressionsResponse]Lists suppressed email addresses from bounces or unsubscribes.
.add()
Synchronous Signature:client.suppressions.add(email: str, reason: str = "manual") -> CoffeeMailResponse[SuppressionDetail]Asynchronous Signature:await async_client.suppressions.add(email: str, reason: str = "manual") -> CoffeeMailResponse[SuppressionDetail]Manually adds an email address to the suppression list.
Webhooks
.verify_signature()
Synchronous Signature:Webhooks.verify_signature(payload: str | bytes, signature: str, secret: str) -> boolCryptographically verifies the HMAC SHA-256 signature in the webhook header.
Statistics
.get()
Synchronous Signature:client.stats.get(from_date: str | None = None, to_date: str | None = None) -> CoffeeMailResponse[StatsOverview]Asynchronous Signature:await async_client.stats.get(from_date: str | None = None, to_date: str | None = None) -> CoffeeMailResponse[StatsOverview]Queries aggregate sending, delivery, and rejection statistics by period.