Skip to content

Transactional Email

B2B SaaSE-commerceMarketplaces

Send Python and Ruby transactional emails safely

Ship receipts, invites, and password resets from Django, FastAPI, or Rails using Apex's stdlib-only Python 3.10+ and Ruby 3.0+ clients with automatic Idempotency-Key retries and sandbox helpers.

Stdlib-only Python 3.10+ and Ruby 3.0+ clients with built-in sandbox.

6 min read10 min setupUpdated
Two backend engineers sorting numbered receipt envelopes beside a brass mechanical date stamp on a sunlit oak studio bench.
Stdlib-only Python and Ruby clients attach deterministic Idempotency-Keys so Sidekiq or Celery retries never double-send a receipt.

Python & Ruby retry & sandbox simulator

Simulate worker retries, idempotency replay, and sandbox errors

Switch between Python 3.10+ and Ruby 3.0+, inject 429/5xx/409 failures, and see which calls retry safely versus raise typed exceptions.

Illustrative worker · apex_transactional retry matrix
40,000
ApexApex · Live Playbook Simulator

People entering journey

40,000

Cap: 3 sends / week

Recovered conversions

2,560

+920 over single-channel email

Unsubscribe rate

0.7%

Down from 1.9% unguarded blast

Journey performance by orchestration strategy

StrategyConversionsRevenueUnsubscribes
Static email drip1,640$137,760760
Apex Adaptive Journey2,560$215,040280

Conversions with adaptive branching

2,560

+$77,280 incremental revenue

  • Exits immediately on conversion so buyers never get a redundant nudge.
  • Workspace guardrails cap sends at 3/week and honor quiet hours.

Adaptive send decision path

  1. Hour 0Trigger event enters journeyGuardrails

    Apex checks suppression list, quiet hours, and weekly send cap.

  2. Hour 24Channel fallback branchAdaptive

    Non-openers with push permission receive a concise mobile/web push instead of a second email.

  3. On purchaseImmediate conversion exitExit goal

    Journey halts the instant checkout completes and credits the winning branch.

The complete playbook

Step-by-step setup, worked math, and real limits.

Steps, technical details, and live pricing.

How it works without Apex

Use Apex's stdlib-only apex_transactional clients for Python 3.10+ and Ruby 3.0+ (zero requests, httpx, faraday, or httparty dependencies) to send inline emails or dashboard-edited commId templates. Every call attaches and reuses an Idempotency-Key across backoff retries on network, 429, 5xx, and 409 idempotency_in_flight errors, plus includes sandbox mode and sandbox_recipient helpers for bounce tests.

How Apex does it for you

Apex replays cached responses for 24 hours per Idempotency-Key, rejects mismatched payload reuse with 409 idempotency_key_mismatch, applies workspace brand settings to commId templates without deploys, and lets CI simulate bounces in sandbox mode.

How to set this up in 5 steps

  1. Mint a workspace transactional API key (apex_tx_)

    Create an apex_tx_ secret in Apex Settings and load it as APEX_TX_KEY in your Django, FastAPI, or Rails environment.

  2. Install the stdlib-only Python wheel or Ruby gem

    Run pip install https://app.apex.inc/downloads/sdk/apex_transactional-0.3.1-py3-none-any.whl (Python) or curl -fsSLO https://app.apex.inc/downloads/sdk/apex_transactional-0.3.1.gem && gem install ./apex_transactional-0.3.1.gem (Ruby) with zero third-party HTTP dependencies.

  3. Pick inline body or dashboard-managed commId template

    Send inline subject/html/text for simple internal alerts, or reference a saved transactional commId with a variables map so operators can edit copy without redeploying (never mix both shapes in one call).

  4. Pass a business idempotency_key from your worker job

    Supply a stable key like receipt-1812 or invite-{token}. If omitted, the SDK generates a UUID and reuses it across retries; passing your own business key also protects across Celery or Sidekiq job re-runs.

  5. Test success and bounce paths in sandbox mode

    Instantiate the client with sandbox=True and call sandbox_recipient('success') or sandbox_recipient('bounce') in CI to verify your exception handlers without delivering real email.

Stdlib-only Python and Ruby clients

Receipts, login codes, and team invitations usually originate in Celery, RQ, Sidekiq, or ActiveJob workers. When a queue worker retries a job after a transient timeout, a naive HTTP call emails your customer twice; meanwhile, bloated vendor SDKs often clash with pinned versions of requests, httpx, pydantic, faraday, or httparty.

Apex ships stdlib-only transactional clients for Python 3.10+ and Ruby 3.0+ with zero external HTTP dependencies. Install the Python wheel directly with pip install https://app.apex.inc/downloads/sdk/apex_transactional-0.3.1-py3-none-any.whl, or download and install the Ruby gem with curl -fsSLO https://app.apex.inc/downloads/sdk/apex_transactional-0.3.1.gem && gem install ./apex_transactional-0.3.1.gem. Both docs pages publish the exact SHA-256 checksums for pinned builds.

Backend developer writing clean retry notes beside stacked kraft paper mailers on a sunny timber workbench.
Passing a deterministic business key like receipt-1812 guarantees background worker retries replay the first response instead of sending twice.

Inline vs. template send shapes

Both SDKs support two mutually exclusive payload shapes (mixing commId with subject/html/text returns 400 validation_error):

  1. Template shape (`commId` + `variables`, recommended): References a saved workspace transactional communication. Operators can tweak wording in the composer without a code deploy, workspace branding applies automatically, and transactional templates suppress unsubscribe links.
  2. Inline shape (`subject` + `html`/`text`): Useful when content belongs right next to the call site (internal ops alerts or quick scripts).
import os
from apex_transactional import ApexTransactionalClient

apex = ApexTransactionalClient(
    base_url="https://app.apex.inc",
    api_key=os.environ["APEX_TX_KEY"],  # starts with apex_tx_
)

apex.send(
    {
        "to": "alex@example.com",
        "commId": "invite",
        "variables": {
            "inviterName": "Jordan",
            "orgName": "Northwind",
            "role": "member",
            "acceptUrl": "https://app.example.com/invite/accept?token=tok_123",
        },
    },
    idempotency_key="invite-tok_123",
)
require "apex_transactional"

apex = ApexTransactional::Client.new(
  base_url: "https://app.apex.inc",
  api_key: ENV.fetch("APEX_TX_KEY"),
)

apex.send(
  { to: "alex@example.com", subject: "Receipt #1812", text: "Thanks for your order." },
  idempotency_key: "receipt-1812",
)
Two engineers testing printed mail template swatches under warm studio daylight to check brand consistency.
Template sends via commId pull workspace branding and let operators adjust copy in the composer without waiting on a backend deploy.

Retry policy and sandbox testing

Every send() attaches an Idempotency-Key (using your business key when provided, or generating and reusing one UUID per call across internal retries). Both clients apply exponential backoff with jitter (default 3 attempts, 250 ms base delay capped at 5,000 ms) using this exact policy:

OutcomeRetried automatically?SDK behavior
Network / TCP / DNS, `429`, `5xx`, `409 idempotency_in_flight`YesBackoff with jitter using the same Idempotency-Key
TimeoutNoSingle attempt within the configured timeout (default 30s)
`400`, `401`, `409 idempotency_key_mismatch`, `422`NoRaises a typed exception (ApexValidationError, ApexAuthError, ApexIdempotencyMismatchError)

In CI and staging tests, pass sandbox=True (Python) or sandbox: true (Ruby) and address sandbox_recipient("success") or sandbox_recipient("bounce") to verify error handling deterministically without sending a single real email. You can also inject a custom transport callable for unit tests.

What this costs on Apex

Live Apex pricing · Pay-as-you-go

Estimated Apex cost for Django or Rails SaaS sending 40,000 transactional receipts, invites, and password resets per month

$18 / month

Estimated from live usage meters.

Apex meter / scheduleScenario volumeFree allowance / basisRateApex cost
Messages
Transactional receipts, password resets, and team invitations (40,000 monthly transactional sends with 24-hour idempotency replay)
40,000 / mo10K / month$60.00 per 100K messages$18

Sandbox mode calls and replayed idempotent retries incur zero duplicate communication charges. History: 13 months no card, 3 years with card, 7 years once you've paid an invoice. Live pricing.

Sandbox simulations and 24-hour idempotent response replays never bill as extra sends, so you pay only for real delivered emails.

Create keys & templates via MCP

Mint an apex_tx_ key and inspect transactional templates from your editor

Ask your coding agent to check existing transactional API keys and list transactional communications before wiring your Python or Ruby worker.

1Add Apex to your editor

Install in Grok Build

Opens Grok Build and adds Apex. Nothing to configure.

2Tell your agent

Prompt for your AI editor

In my Apex workspace, call list_transactional_api_keys and list_communications to show our active transactional templates and confirm our sending domain status before I wire apex_transactional.

The first time your agent calls Apex, it gives you a link to approve in the browser. There is no key to paste. In Grok Build you can also run /setup-apex.

See how editor setup works step by step

backend-workers · Grok BuildWaiting for approval
Agent
You

Set up Apex in this repo.

Set up Apex · 0 of 4
  • Signed in
  • Workspace named
  • Events arriving
  • Conversion picked
  • Stripe

Your move

Stop Celery and Sidekiq retries from emailing the same receipt twice.

Use stdlib-only clients with 24-hour Idempotency-Key replay, typed exceptions, and deterministic sandbox bounce tests.