Contiguity's official Python SDK.
You can install the SDK using pip
pip install contiguityThen, import & initialize it like this:
from contiguity import Contiguity
client = Contiguity(token="your_token_here")Tip
It is recommended to set the CONTIGUITY_TOKEN environment variable instead of hardcoding your token. The SDK will automatically read this variable if no token is provided during initialization.
You can get your token from the Contiguity console.
As long as you provided Contiguity a valid token, and provide valid inputs, sending emails will be a breeze!
To send an email with an HTML body:
client.email.send(
to="example@example.com",
from_="Contiguity",
subject="My first email!",
body_html="<b>I sent an email using Contiguity</b>",
)To send an email with a text body:
client.email.send(
to="example@example.com",
from_="Contiguity",
subject="My first email!",
body_text="I sent an email using Contiguity",
)reply_toallows you to set a reply-to email address.ccallows you to CC email addresses.bccallows you to BCC email addresses.headersallows you to set custom email headers.
As long as you provided Contiguity a valid token, and will provide valid inputs, sending texts will be a breeze!
client.text.send(to="+15555555555", message="My first text using Contiguity")Note: Contiguity expects the recipient phone number to be formatted in E.164. You can attempt to pass numbers in formats like NANP, and the SDK will try its best to convert it. If it fails, it will throw an error!
Contiguity aims to make communications extremely simple and elegant. In doing so, we're providing an OTP API to send one time codes - for free (no additional charge, the text message is still billed/added to quota)
To send your first OTP, first create one:
from contiguity.otp import OTPLanguage
response = client.otp.send("+15555555555", language=OTPLanguage.ENGLISH, name="Contiguity")
otp_id = response.otp_idContiguity supports 33 languages for OTPs, see the OTPLanguage enum for the full list.
The name parameter is optional, it customizes the message to say "Your [name] code is ..."
To verify an OTP a user has inputted, simply call client.otp.verify():
response = client.otp.verify(otp_id, otp=user_input)
is_verified = response.verified # True or FalseThe OTP expires 15 minutes after sending it.
Want to resend an OTP? Use client.otp.resend():
response = client.otp.resend(otp_id)OTP expiry does not renew.
The SDK also supports sending iMessages, WhatsApp messages, managing email domains, and leasing phone numbers.
See more examples in the examples folder.
- Contiguity Identity will be supported
- Adding support for calls
- Adding support for webhooks
- and much more!