Skip to main content

vintasend-twilio

A Twilio SMS adapter for vintasend.

VintaSend records every notification, renders it from a template at send time, and hands the result to an adapter for delivery. This package is an adapter for the SMS notification type: it renders the notification with any BaseTemplatedSMSRenderer and posts the body to Twilio's Messages API. Pair it with any vintasend backend and an SMS renderer (for example vintasend-jinja, or vintasend-managed-templates' ManagedTemplateSMSRenderer).

Both service flavours are covered:

Class For
TwilioSMSNotificationAdapter NotificationService (sync)
TwilioAsyncIOSMSNotificationAdapter AsyncIONotificationService (awaits Twilio through its async HTTP client)

Install

poetry add vintasend-twilio
# or
pip install vintasend-twilio

twilio comes as a dependency.

Usage

from vintasend.services.notification_service import NotificationService
from vintasend_twilio import TwilioSMSNotificationAdapter

adapter = TwilioSMSNotificationAdapter(
    my_sms_renderer,                      # any BaseTemplatedSMSRenderer
    my_backend,                           # any vintasend backend
    account_sid="ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    auth_token="...",
    from_phone_number="+15550001234",
)

service = NotificationService(notification_adapters=[adapter], notification_backend=my_backend)

Or let the service build it from settings. Every option below is an adapter keyword argument, so it goes in the kwargs half of a NOTIFICATION_ADAPTERS entry:

NOTIFICATION_ADAPTERS = [
    (
        ("vintasend_twilio.TwilioSMSNotificationAdapter", {"from_phone_number": "+15550001234"}),
        "vintasend_jinja.services.notification_template_renderers.jinja_template_renderer.JinjaTemplatedSMSRenderer",
    ),
]

With credentials left out of the kwargs, they are read from the environment (see below), which keeps the auth token out of your settings module.

Options

Keyword argument Environment fallback Meaning
account_sid TWILIO_ACCOUNT_SID Twilio account SID. Required unless client is given.
auth_token TWILIO_AUTH_TOKEN Twilio auth token. Required unless client is given.
from_phone_number TWILIO_FROM_PHONE_NUMBER E.164 number to send from. Exactly one of this and messaging_service_sid is required.
messaging_service_sid TWILIO_MESSAGING_SERVICE_SID Twilio Messaging Service to send through instead of a fixed number.
phone_number_context_key — Context key holding the recipient's number for regular notifications. Default "phone_number".
status_callback — URL Twilio calls with delivery status updates.
client — A prebuilt twilio.rest.Client. Overrides account_sid, auth_token and client_kwargs.
client_kwargs — Extra keyword arguments for twilio.rest.Client (region, edge, http_client, ...).

A missing sender or missing credentials raises TwilioConfigurationError when the adapter is constructed, not at the first send.

Where the recipient's number comes from

  • A one-off notification carries its destination on itself (email_or_phone), so nothing else is needed.

  • A regular notification only knows the user, and vintasend's backend seam has no phone lookup. The adapter reads the number from the context the notification's context generator returns, under phone_number_context_key (default phone_number):

    from vintasend.services.dataclasses import NotificationContextDict
    from vintasend.services.notification_service import register_context
    
    @register_context("sms_verification")
    def sms_verification(user_id: str) -> NotificationContextDict:
        user = get_user(user_id)
        return {"phone_number": user.phone_number, "code": user.pending_code}
    

    A regular notification whose context has no non-empty number raises MissingRecipientPhoneNumberError before anything is sent.

Like the email adapters, the adapter also adds base_url to the context handed to the renderer (from NOTIFICATION_DEFAULT_BASE_URL_PROTOCOL and NOTIFICATION_DEFAULT_BASE_URL_DOMAIN), so an SMS template can build absolute links.

Errors

Every exception derives from vintasend's NotificationError:

  • TwilioConfigurationError -- no usable sender or credentials, raised at construction.
  • MissingRecipientPhoneNumberError -- a regular notification's context has no number.
  • TwilioSendError -- Twilio rejected the message. It carries Twilio's HTTP status and error code, names the notification id, and chains the original TwilioRestException as __cause__. Its own message never includes the recipient's number.

Both send errors subclass NotificationSendError, so the service marks the notification as failed the same way it does for any other adapter.

AsyncIO

TwilioAsyncIOSMSNotificationAdapter takes the same options. Unless you inject a client, it builds Twilio's Client with AsyncTwilioHttpClient (aiohttp-backed) and awaits messages.create_async, so the request never blocks the event loop. The client is built on first send rather than in the constructor, because the aiohttp session needs a running event loop and AsyncIONotificationService instantiates its adapters synchronously. An injected client must have been built with an async http_client.

Injecting a client

For a shared client, an API key instead of the auth token, a region or edge, or a custom HTTP client:

from twilio.rest import Client

client = Client(api_key_sid, api_key_secret, account_sid, region="ie1")
TwilioSMSNotificationAdapter(renderer, backend, from_phone_number="+15550001234", client=client)

Development

poetry install --with dev
poetry run pytest
poetry run ruff check .
poetry run mypy
poetry run tox        # the suite across Python 3.10-3.13

The tests drive the real adapter against a recording Twilio HTTP client, so nothing touches the network.

Metadata

Release files for vintasend-twilio 3.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vintasend-twilio 3.6.0
File Size Uploaded Provenance Actions
vintasend_twilio-3.6.0.tar.gz 8.1 kB With provenance Details for vintasend_twilio-3.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vintasend-twilio 3.6.0
File Interpreter ABI Platform Actions
vintasend_twilio-3.6.0-py3-none-any.whl Python 3 none any Details for vintasend_twilio-3.6.0-py3-none-any.whl

Total release size: 16.8 kB

Release files / vintasend_twilio-3.6.0.tar.gz

Download URL vintasend_twilio-3.6.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
13bed4a115047c982b1ba7d1ac9f718ce2ca1ca36171185bdc7d2a0c6ad921ed
BLAKE2b-256 checksum
How to use checksums
d3ee655eb14ca7c94f74078a0d8177bcdf6b6459fbf5edb53c2184f380634473
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 4, 2026.

Transparency log

Release files / vintasend_twilio-3.6.0-py3-none-any.whl

Download URL vintasend_twilio-3.6.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27d1f2f66cb47bbbba914d59f9aba8fc8874f46c7c5a9b46fdca1cf6dba8d3c6
BLAKE2b-256 checksum
How to use checksums
eed997921e1c8312d1e44c5f4ed6acc62456ee9d00821f07215439ba50c529a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 4, 2026.

Transparency log

Security for vintasend-twilio 3.6.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vintasend_twilio-3.6.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 Nov 4, 2026.

Transparency log

A 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.6.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page