Skip to main content

Official Python SDK for the RaviMail REST API v1 (api.ravimail.com.br).

Project description

RaviMail Python SDK

PyPI version PyPI downloads Python versions License: MIT

Official Python client for the RaviMail REST API v1. Type-hinted, minimal dependencies (requests only).

Why this exists. RaviMail is a Brazilian email infrastructure platform with 155 documented REST endpoints. This SDK gives you Pythonic access to all of them, with proper exceptions and a familiar Session-based HTTP layer.

Installation

pip install ravimail

Requirements: Python 3.9+.

Quickstart — Hello World

from ravimail import Client

rm = Client("rvm_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

resp = rm.transactional.send(
    to="recipient@example.com",
    from_="you@yourdomain.com",  # `from` is reserved in Python — use from_
    subject="Welcome to the show",
    html="<h1>Glad you're here</h1>",
)

print(resp["data"]["message_id"])  # msg_xxxxxxxxxxxx

Test mode (no billing, no real send)

Any token prefixed with rvm_test_* enables sandbox mode automatically.

test = Client("rvm_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
test.transactional.send(to="bounce@simulator.ravimail.com.br", from_="...", subject="...", html="...")

See the Mailbox Simulator for deterministic test scenarios.

Available resources

All 23 resources mirror the REST API exactly.

Resource Coverage
rm.me Token info + quotas
rm.transactional send / batch / list / get
rm.contacts CRUD + add_tags / remove_tags / suppress / import_
rm.lists CRUD
rm.templates CRUD + render + versioning
rm.campaigns CRUD + start / pause / resume / cancel / duplicate + A/B
rm.domains Add / verify / dns_check / upgrade_to_panel
rm.files Upload (path or file handle) / list / get / delete
rm.webhooks Endpoints + deliveries + rotate_secret
rm.suppression list / suppress / unsuppress
rm.analytics summary / timeseries / by_domain/ip/node/isp/device/country / heatmap
rm.events list + stream_url()
rm.verification email + batch
rm.segments CRUD + compute
rm.exports Async CSV jobs
rm.inbound_routes Inbound parsing → forward webhook
rm.drips CRUD + steps + subscribe / unsubscribe
rm.subaccounts Multi-tenant CRUD + tokens
rm.reputation summary / domains / ips / nodes
rm.custom_fields List / create / delete
rm.reports Scheduled reports CRUD
rm.account Balance / usage / packages / top_up / payments
rm.smtp_relay SMTP credentials + log

Idempotency keys

For any write you want to retry safely:

rm.transactional.send(
    to="user@example.com",
    from_="you@yourdomain.com",
    subject="Order confirmation",
    html="<p>...</p>",
    idempotency_key="order-1024-confirmation",
)

The API guarantees the second call with the same key returns the original response, byte for byte.

Webhook signature verification

Standalone function — no Client instance needed:

from ravimail import verify_signature

def handle_webhook(request):
    signature = request.headers.get("X-Ravimail-Signature", "")
    raw_body  = request.get_data()  # Flask: raw bytes; Django: request.body
    secret    = os.environ["RAVIMAIL_WEBHOOK_SECRET"]

    if not verify_signature(signature, raw_body, secret):
        return "", 401

    # ... process payload
    return "", 200

Uses hmac.compare_digest — constant-time comparison.

Error handling

from ravimail import (
    Client,
    ApiError,
    AuthenticationError,
    ValidationError,
    RateLimitError,
)

try:
    rm.transactional.send(to="...", from_="...", subject="...", html="...")
except ValidationError as e:
    # 422 — bad payload; e.detail has the field-level info
    print(e.detail)
except RateLimitError as e:
    # 429 — back off
    time.sleep(e.retry_after_seconds or 5)
except AuthenticationError:
    # 401 — token invalid/revoked
    ...
except ApiError as e:
    # any other 4xx/5xx; e.status has the HTTP code
    ...

Configuration

import requests

rm = Client(
    "rvm_live_...",
    base_url="https://api.ravimail.com.br",  # override for staging
    timeout=30.0,                             # seconds
    session=requests.Session(),               # reuse for connection pooling
)

SSE event stream

Install sseclient-py:

pip install sseclient-py
import requests
from sseclient import SSEClient

res = requests.get(
    rm.events.stream_url(),
    headers={"Authorization": f"Bearer {token}", "Accept": "text/event-stream"},
    stream=True,
)
for event in SSEClient(res).events():
    print(event.data)

Links

License

MIT © Ravi Systems LTDA

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ravimail-1.0.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ravimail-1.0.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file ravimail-1.0.0.tar.gz.

File metadata

  • Download URL: ravimail-1.0.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ravimail-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3243c27cb32d0c40169ec7447574545bdc10784f1156c95bac7f0e2499674bc9
MD5 987218dd383c26fc23d7e5e792482917
BLAKE2b-256 32ad02a2ad42968b0394b86899fb1c1b68103344ae9db4ae5a2b39125212172b

See more details on using hashes here.

File details

Details for the file ravimail-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ravimail-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ravimail-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3683094fb3b2cd095d764fa06c0ff2312a06f1691ce498341b10e24119f58a3
MD5 6d733f7103cb7ce936d23e21a798a230
BLAKE2b-256 8c112d30dd043f45cf0aa487ce611e392a6bca51459bafd4ee350fc98c59e056

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page