Skip to main content

Calisero Python SMS API Library

PyPI version CI Coverage Python Typed Dependencies Code style: Ruff License Downloads

Official Python library for the Calisero transactional SMS API.

Send SMS messages, verify phone numbers with one-time codes, manage opt-outs for GDPR compliance, receive delivery reports and monitor your account, with a fully typed library that has no dependencies.

Features

  • 🚀 Simple & Intuitive: SmsClient.create(api_key), then client.messages.create(recipient=..., body=...)
  • 🔒 Type Safe: fully typed, py.typed included, checked with mypy --strict
  • 🌐 Zero Dependencies: built on urllib from the standard library, nothing else to install
  • 🧱 Immutable Models: frozen dataclasses with the API's own field names
  • 📱 Complete API Coverage: messages, verifications (OTP), opt-outs and accounts, checked against the API's OpenAPI document
  • 🔐 OTP / 2FA: start a verification and validate the code in two calls
  • ✂️ URL Shortening: shorten the links of a message body and track their clicks
  • 📊 Limits & Tracing: daily sending limit, request rate limit and the trace ID of every answer and error
  • 📬 Delivery Webhooks: validated parsing of delivery status callbacks, and a ready handler for Flask, Django, FastAPI or any WSGI server
  • 🛡️ Error Handling: an exception class for every kind of failure, with the API's message and the trace ID
  • 🕐 Romania Time Handled: pass a timezone-aware datetime to schedule a message, it is converted to the time zone the API expects
  • 🧪 Thoroughly Tested: unit, integration (real HTTP), contract (OpenAPI) and package smoke tests on Python 3.10 to 3.14, Linux, macOS and Windows, 100% coverage
  • 📖 Rich Examples: 19 runnable examples covering every operation
  • 🐘 Sibling Libraries: calisero/calisero-php, calisero/laravel-sms, calisero/calisero-symfony and @calisero/calisero-node

Requirements

  • Python 3.10 or later — tested on 3.10, 3.11, 3.12, 3.13 and 3.14
  • A Calisero API key

The library carries no runtime dependency: its HTTP client is urllib, from the standard library. It is meant for server-side code: never ship your API key to a browser or a mobile app.

Installation

pip install calisero

With other package managers: uv add calisero, poetry add calisero.

Getting Your API Key

To use this library, you'll need an API key from your Calisero account:

  1. Log in to your Calisero account at https://calisero.ro
  2. Navigate to the dashboard and go to the "API Keys" section
  3. Click "Add Key" to create a new API key
  4. Configure your key:
    • Give it a descriptive name (e.g., "Production App", "Development")
    • Set IP filters if needed for additional security
    • Choose a sandbox key to test without sending or paying for real messages
  5. Copy your API key and store it securely

Security Note: Never commit API keys to version control. Use environment variables or a secret manager.

Quick Start

Basic SMS Sending

import os

from calisero import SmsClient

# Create the SMS client
client = SmsClient.create(os.environ["CALISERO_API_KEY"])

# Send a simple SMS
message = client.messages.create(recipient="+40742***350", body="Hello from Calisero!").data

print(f"Message sent! ID: {message.id}")
print(f"Status: {message.status}")

Environment Configuration

For production applications, store your API key securely:

# .env file, or your platform's secret settings
CALISERO_API_KEY=your-api-key-here
import os

from calisero import SmsClient

client = SmsClient.create(os.environ.get("CALISERO_API_KEY"))

SmsClient.create() raises a TypeError when the key is missing (None) and a ValueError when it is empty, so a misconfigured environment fails at startup rather than on the first message. The whitespace around the key (the newline of a key read from a file) is dropped.

🎯 Common Use Cases

OTP / 2FA Authentication

The Verifications API generates the code, sends it by SMS and checks it, so your application never stores it:

from calisero import SmsClient, ValidationError

client = SmsClient.create(os.environ["CALISERO_API_KEY"])

# 1. Send a code (6 characters, valid for 5 minutes by default)
client.verifications.create(phone="+40742***350", brand="YourApp")

# 2. Check the code the user typed
try:
    verification = client.verifications.validate(phone="+40742***350", code=user_input).data
    print(f"Verified at {verification.verified_at}")
except ValidationError as error:
    # A wrong or expired code, too many attempts (5), or a code already used
    print(error.message)

A code validates only once: once verified, the same code sent again is refused ("The validation code has already been used."), so record the verification in your application rather than checking the code again.

To send a code you generate yourself, hide it in the API's answers and in the dashboard with visible_body:

client.messages.create(
    recipient=user_phone_number,
    body="Your verification code is: AC3-4F6. Valid for 5 minutes.",
    visible_body="Your verification code is: ******. Valid for 5 minutes.",
    sender="YourApp",
)

Order Notifications

client.messages.create(
    recipient=customer_phone,
    body=f"Order #{order_number} confirmed! Estimated delivery: {delivery_date}",
    callback_url="https://yourstore.com/webhooks/sms/dlr",
    sender="YourStore",
)

Marketing Campaigns with Opt-out Compliance

The API refuses to send to a number that opted out: the message fails validation (422) and is neither sent nor billed.

from calisero import ValidationError

try:
    client.messages.create(
        recipient=phone_number,
        body="Special offer! Get 20% off with code SAVE20. Reply STOP to opt out.",
        sender="YourBrand",
    )
except ValidationError as error:
    if "recipient" not in error.validation_errors:
        raise

    print(f"Not sent to {phone_number}: {' '.join(error.validation_errors['recipient'])}")

# When a customer asks to stop receiving messages
client.opt_outs.create(phone=phone_number, reason="Replied STOP")

Advanced Message Creation

from datetime import datetime, timezone

response = client.messages.create(
    recipient="+40742***350",
    body="Your code is 123456. Manage alerts: https://yoursite.com/alerts",
    visible_body="Your code is ******. Manage alerts: https://yoursite.com/alerts",  # Shown in answers and the dashboard
    validity=24,  # Validity period, in hours
    schedule_at=datetime(2026, 12, 25, 8, 0, tzinfo=timezone.utc),  # Sent at 10:00, Romania time
    callback_url="https://yoursite.com/webhook",  # Delivery reports
    sender="Calisero",  # One of your approved sender IDs
    shorten_urls=True,  # Shorten the links of the body
)

schedule_at takes a timezone-aware datetime, converted to the Romania time the API reads, or a YYYY-MM-DD HH:MM:SS string already in Romania time. A naive datetime is refused with a ValueError: which time zone it is in cannot be known. A time already past today sends the message at once; the API refuses an earlier day, and accepts up to 5 years ahead.

Authentication

Using an API Key

client = SmsClient.create("your-api-key-here")

Custom Authentication Provider

Pass an object with a get_token() method instead of the key: it is called before every request, e.g. to read the key from a secret manager and rotate it without a restart.

from calisero import SmsClient


class VaultToken:
    def get_token(self) -> str:
        return secret_manager.read("calisero-api-key")


client = SmsClient.create(VaultToken())

📚 Examples

This library includes runnable examples for every operation in the examples/ directory:

📱 Message Examples

🚫 Opt-out Examples (GDPR Compliance)

✅ Verification Examples (OTP)

👤 Account Examples

📬 Webhook Examples

🛡️ Error Handling

🚀 Running Examples

git clone https://github.com/calisero/calisero-pyton.git
cd calisero-pyton
uv sync
CALISERO_API_KEY=your-api-key-here CALISERO_TEST_PHONE=+40742123456 uv run python examples/messages/send_simple_sms.py

Note: Examples use masked phone numbers (+40742***350) unless CALISERO_TEST_PHONE is set. Use a sandbox API key to try them without sending real messages.

API Reference

Every call is synchronous and takes its arguments as keywords, the ids of the resources excepted. A single resource comes as an ApiResponse (data, response_meta), a list as a Paginated (data, links, meta, response_meta). Every call also takes an optional timeout: seconds to wait for its answer, instead of the client's.

Messages

Send a Message

response = client.messages.create(recipient="+40742***350", body="Hello World!")

message = response.data
print(message.id)  # Message UUID
print(message.status)  # 'scheduled', then 'sent', 'delivered' or 'undelivered'
print(message.parts)  # Number of SMS parts

# What the answer's headers report
print(response.response_meta.trace_id)  # The request's trace ID
print(response.response_meta.daily_remaining)  # Messages left today (None: no daily limit)
Argument Type Description
recipient str Required. Mobile number in E.164 format, e.g. +40742123456
body str Required. The text, at most 1600 characters; its links may have to go to approved domains (below)
visible_body str Shown instead of body in the API's answers and the dashboard
validity int Validity period, in hours
schedule_at datetime | str When to send it: a timezone-aware datetime, or a YYYY-MM-DD HH:MM:SS string in Romania time
callback_url str Where Calisero posts the delivery status updates: a public http(s):// address
sender str One of your approved sender IDs, written exactly as approved; the default sender when omitted
shorten_urls bool Shorten the http(s):// links of the body

The arguments left as None are not sent; False and 0 are.

  • sender must be a sender ID already approved for your account (Messages > Senders in the dashboard), written exactly as approved: the match is case-sensitive. A sender that is unknown, still pending, rejected or another account's is refused with a ValidationError (422, "The sender is invalid or is not approved." in validation_errors["sender"]) and nothing is sent or billed: leave sender out to use the default sender until yours is approved. The sender IDs of the examples (Calisero, YourApp...) are placeholders, not senders you can use.
  • callback_url must be an http or https address on the public Internet: private, loopback and link-local addresses are refused, and redirects are not followed.

An account restricted to its approved link domains may link only to them. Every link in body, with or without https:// (www.example.ro, example.ro/path), must go to a domain approved for the account, exactly, or as one of its subdomains when they were approved too; a link Calisero shortens is checked by the address it opens. Any other link is refused with a ValidationError (422) on the body field, its message naming the domain: the message is not created, not sent and not billed, test messages from the sandbox included. Ask for a domain in the dashboard, under Messages › Link domains.

The field at fault tells a refused link from a refused sender:

from calisero import ValidationError

try:
    client.messages.create(recipient=recipient, body="Your order has shipped: https://yourstore.ro/orders/1001")
except ValidationError as error:
    if "body" in error.validation_errors:
        ...  # e.g. "Links to yourstore.ro are not allowed for this account: it is not one of its approved link domains."
    elif "sender" in error.validation_errors:
        ...  # "The sender is invalid or is not approved."
    else:
        raise

A scheduled message whose link domain is rejected or revoked before it is due is not sent nor billed: its status becomes failed, and its page in the dashboard shows the reason (error code 1005).

Shorten URLs

Set shorten_urls=True and Calisero replaces every http:// and https:// link of the body with a short one before sending, so the SMS gets shorter (and may take fewer parts). Each shortened link comes back with its click statistics. Test messages (a sandbox account or a sandbox API key) keep their links as written and come back with an empty shortened_urls:

message = client.messages.create(
    recipient="+40742***350",
    body="Your order has shipped! Track it: https://yourstore.com/orders/12345/tracking",
    shorten_urls=True,
).data

for link in message.shortened_urls:
    print(link.original_link)  # https://yourstore.com/orders/12345/tracking
    print(link.shortened_link)  # https://calisero.ro/s/ghJKPV

# Later: how many times the links were opened
for link in client.messages.get(message.id).data.shortened_urls:
    print(link.click_count, link.last_click)  # Number of clicks, last click or None

Get Message Details

message = client.messages.get("message-uuid-here").data

print(message.recipient, message.body, message.status)
print(message.sent_at, message.delivered_at)

List Messages

page = client.messages.list()  # Newest first, 50 a page

for message in page:  # A page iterates over its items (page.data)
    print(f"{message.id}: {message.body}")

print(f"Current page: {page.meta.current_page}")

if page.has_next_page:
    following = client.messages.list(page=page.meta.current_page + 1)

page.meta holds current_page, per_page, path, from_ and to (the API's from, a Python keyword); page.links the URLs of the first, prev and next pages.

Delete a Message

Only a message still scheduled can be cancelled:

from calisero import ForbiddenError

try:
    client.messages.delete("message-uuid-here")
    print("Message cancelled")
except ForbiddenError:
    print("Cannot delete: the message is already queued, sent or delivered")

Verifications (OTP)

Create a Verification

response = client.verifications.create(
    phone="+40742***350",
    brand="Calisero",  # Named in the default message; required unless a template is given
    # template="Your Calisero code is {code}",  # Or a message of your own, holding {code}
    # expires_in=10,  # Minutes the code stays valid, 1 to 10 (5 by default)
)

verification = response.data
print(verification.id, verification.status)  # 'unverified'
print(verification.expires_at)

# The code's SMS counts towards the account's daily sending limit
print(response.response_meta.daily_remaining)

Neither the brand nor the template may contain links (web addresses, domains, emails or IP addresses): the codes are sent from a shared sender, so the API refuses them with a ValidationError (422).

Get Verification Details

verification = client.verifications.get("verification-uuid-here").data

print(verification.status)  # 'unverified' or 'verified'
print(verification.verified_at)  # Timestamp or None
print(verification.expired, verification.attempts)

List Verifications

from calisero import VerificationStatus

# Optionally only the verified or the unverified ones
page = client.verifications.list(page=1, status=VerificationStatus.VERIFIED)

for verification in page:
    print(f"{verification.id} | {verification.phone} | {verification.status}")

Validate a Verification Code (OTP)

The code is checked against the latest verification of the phone number, in any case:

verification = client.verifications.validate(phone="+40742***350", code="ABC123").data

print(verification.status)  # 'verified'

A wrong or expired code, a sixth attempt, or a code already used (a code validates only once) raises a ValidationError whose validation_errors["code"] says which; a phone number without a verification a NotFoundError.

Opt-outs

Create an Opt-out

opt_out = client.opt_outs.create(phone="+40742***350", reason="User requested opt-out via website").data

print(f"Opt-out created with ID: {opt_out.id}")

List Opt-outs

for opt_out in client.opt_outs.list():
    print(f"{opt_out.phone}: {opt_out.reason or 'no reason'}")

Get, Update and Delete an Opt-out

opt_out = client.opt_outs.get("optout-uuid-here").data

client.opt_outs.update("optout-uuid-here", phone=opt_out.phone, reason="Updated reason")

# The number can receive messages again
client.opt_outs.delete("optout-uuid-here")

Accounts

account = client.accounts.get("account-uuid-here").data

print(f"Account: {account.name}")
print(f"Credit: {account.credit}")
print(f"Status: {account.status}")  # 'active', 'pending' or 'disabled'
print(f"Sandbox: {'Yes' if account.sandbox else 'No'}")

# Daily sending limit (None when no daily limit applies)
print(f"Daily limit: {account.daily_limit or 'none'}")
print(f"Left today: {account.daily_remaining if account.daily_remaining is not None else 'unlimited'}")
print(f"Sent today: {account.sent_today}")

Statuses

The models keep a status as the string the API sent, so a status a future API version adds still reads. The MessageStatus, VerificationStatus, AccountStatus and DeliveryStatus string enums hold the known values:

from calisero import MessageStatus

if message.status == MessageStatus.DELIVERED:
    ...

Delivery Status Webhooks

When a message has a callback_url, Calisero posts a JSON payload to it each time the message's status changes (sent, delivered or undelivered). Answer with any 2xx status within 2 seconds: only a failed connection or a slower answer is retried (at most 5 attempts in total), a non-2xx answer is not.

DeliveryWebhookHandler reads and validates the payload, hands it to your on_message as a DeliveryWebhookMessage, and tells you how to answer:

import os

from calisero import DeliveryWebhookHandler, DeliveryWebhookMessage


def on_message(message: DeliveryWebhookMessage) -> None:
    print(message.message_id)  # The message's UUID
    print(message.status)  # 'sent', 'delivered' or 'undelivered'
    print(message.delivered_at)  # Set for 'delivered'
    print(message.price)  # Price charged for the message's parts
    print(message.remaining_balance)  # Account balance after billing
    print(message.daily_remaining)  # Messages left today when it was sent (None: no daily limit)
    # Keep it short (update a record, queue a job): the answer waits for it


handler = DeliveryWebhookHandler(
    on_message,
    # Optional: accept only callback URLs that carry ?token=<this secret>
    token=os.environ["CALISERO_WEBHOOK_TOKEN"],
    on_error=lambda error: print(error),  # A refused callback, or a failed on_message
)

Flask:

from flask import Flask, request

app = Flask(__name__)


@app.post("/webhooks/calisero")
def calisero_webhook():
    result = handler.handle(request.get_data(), method=request.method, token=request.args.get("token"))

    return result.body, result.status, result.headers

Django:

from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt


@csrf_exempt
def calisero_webhook(request):
    result = handler.handle(request.body, method=request.method, token=request.GET.get("token"))

    return JsonResponse(result.body, status=result.status, headers=result.headers)

FastAPI (a blocking on_message runs off the event loop):

import asyncio

from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse

app = FastAPI()


@app.post("/webhooks/calisero")
async def calisero_webhook(request: Request) -> JSONResponse:
    body = await request.body()
    result = await asyncio.to_thread(
        handler.handle, body, method=request.method, token=request.query_params.get("token")
    )

    return JSONResponse(result.body, status_code=result.status, headers=result.headers)

Any WSGI server: the handler is itself a WSGI application, so mount it where you like (e.g. gunicorn yourapp.webhooks:handler, or under a path with werkzeug's DispatcherMiddleware). It reads the token from the query string and refuses a body larger than max_body_size before reading it.

Then send the URL with the secret as each message's callback URL: callback_url=f"https://yourapp.com/webhooks/calisero?token={os.environ['CALISERO_WEBHOOK_TOKEN']}".

Answer When
200 {"received": true} on_message handled the update
400 / 413 The payload is not a delivery status update / is larger than max_body_size (64 KiB)
401 token is set and the request lacks it (compared in constant time)
405 Not a POST
500 on_message raised

Calisero does not sign its callbacks, which is why the handler checks a secret token in the URL instead. To read the payload yourself, use DeliveryWebhookMessage.from_json(raw_body) or DeliveryWebhookMessage.from_dict(parsed_body): both raise an InvalidWebhookPayloadError for a malformed payload (and for the [] Calisero sends when the message was cancelled meanwhile).

Daily Sending Limit

Every account has its own daily sending limit: how many messages it can send in a day. A new account starts with a default limit and keeps it until Calisero raises it on request.

  • Every real message counts once, whatever its number of parts: the messages of messages.create() and the codes of verifications.create() alike. A scheduled message counts on the day it is created.
  • Test messages (a sandbox account or a sandbox API key) never count and are never refused.
  • The day ends at midnight, Romania time (Europe/Bucharest), whatever time zone you send from.

You can see the limit and what is left of it in three places:

# 1. On the account
account = client.accounts.get("account-uuid-here").data
print(account.daily_limit, account.daily_remaining, account.sent_today)  # e.g. 1000, 873, 127

# 2. After every message or verification created (X-Daily-Limit / X-Daily-Remaining)
meta = client.messages.create(recipient="+40742***350", body="Hello!").response_meta
print(meta.daily_limit, meta.daily_remaining)  # e.g. 1000, 872 (after this message)

# 3. In every delivery status callback: message.daily_limit, message.daily_remaining, message.sent_today

Once the limit is reached, new messages and verifications are refused with a DailyLimitExceededError until midnight, Romania time. Nothing is sent and nothing is billed:

from calisero import DailyLimitExceededError

try:
    client.messages.create(recipient=recipient, body=body)
except DailyLimitExceededError as error:
    print(error.message)  # What happened and when the limit resets
    print(error.daily_limit)  # e.g. 1000
    print(error.daily_remaining)  # 0
    print(error.resets_at)  # e.g. 2026-10-01T00:00:00+03:00
    print(error.retry_after)  # Seconds until the reset

To raise the limit, contact Calisero with your account and the daily volume you expect.

Rate Limits & Trace ID

Request Rate Limit

Separately from the daily sending limit, each API user may make 240 requests a minute, on every endpoint. Above that the API answers 429 and the library raises a RateLimitedError:

import time

from calisero import DailyLimitExceededError, RateLimitedError

try:
    client.messages.create(recipient=recipient, body=body)
except DailyLimitExceededError:
    ...  # The daily sending limit: wait until error.resets_at
except RateLimitedError as error:
    # The request rate limit: wait a few seconds and retry
    time.sleep(error.retry_after or 1)
    print(error.rate_limit_limit)  # 240
    print(error.rate_limit_remaining)  # 0
    print(error.rate_limit_reset)  # Unix timestamp when requests are accepted again

DailyLimitExceededError extends RateLimitedError, so catch it first. After any successful call, response_meta.rate_limit_remaining tells how many requests are left in the current minute.

Trace ID

Every API answer carries the request's trace ID. Log it: quoting it to support lets Calisero find the request at once, and the dashboard shows everything that happened to it under Developers → Debug.

from calisero import ApiError

# On success
print(client.messages.create(recipient=recipient, body=body).response_meta.trace_id)

# On error
try:
    client.messages.create(recipient=recipient, body=body)
except ApiError as error:
    logger.error("Calisero request %s failed: %s", error.trace_id, error.message)

Error Handling

Every error the API answers with is an ApiError, of the subclass that matches its status:

from calisero import (
    ApiError,
    DailyLimitExceededError,
    NotFoundError,
    RateLimitedError,
    ServerError,
    TransportError,
    UnauthorizedError,
    ValidationError,
)

try:
    client.messages.create(recipient="+40742***350", body="Test message")
except UnauthorizedError:
    print("Invalid or revoked API key")  # 401
except ValidationError as error:
    print(f"Validation error: {error.message}")  # 422
    for field, messages in error.validation_errors.items():
        print(f"{field}: {', '.join(messages)}")
except DailyLimitExceededError as error:
    print(f"Daily limit reached. Sending resumes at: {error.resets_at}")  # 429
except RateLimitedError as error:
    print(f"Rate limited. Retry after: {error.retry_after} seconds")  # 429
except ServerError as error:
    print(f"Server error: {error.message}")  # 5xx
except TransportError as error:
    print(f"Network error: {error.message}", error.__cause__)  # No answer
except ApiError as error:
    print(f"API error {error.status_code}: {error.message} (trace ID: {error.trace_id})")

Every ApiError carries the API's own error message (message, also its str()), the HTTP status (status_code), the request's trace ID (trace_id; request_id returns the same value) and the decoded error body (error_details). CaliseroError is the base class of every exception the library raises, ApiError and InvalidWebhookPayloadError included.

Exception When
UnauthorizedError 401: invalid, revoked or missing API key, or a request from an IP the key does not allow
ForbiddenError 403: not allowed, e.g. deleting a message already sent, or another account's resource
NotFoundError 404: the resource does not exist
ValidationError 422: invalid request data; field errors in validation_errors
DailyLimitExceededError 429: the account reached its daily sending limit
RateLimitedError 429: more than 240 requests a minute
ServerError 500, 502, 503, 504
ApiError Any other API error, or an answer the library cannot read; base class of the above
TransportError The request got no answer: network error or timeout (the original exception is its __cause__)

Arguments that cannot be sent at all (an empty id, a page that is not a positive integer, a naive datetime) raise a TypeError or a ValueError before any request is made.

Retries

The library never retries a request on its own. The API takes no idempotency key, so a message retried after a timeout or a server error may already have been sent: check with messages.list() before sending it again. The API itself refuses (422, duplicate_sms) the same message to the same recipient sent again within 5 seconds.

Advanced Configuration

Client Options

from calisero import AppInfo, SmsClient

client = SmsClient.create(
    os.environ["CALISERO_API_KEY"],
    timeout=10,  # Seconds to wait for the connection and each read (30 by default)
    base_url="https://rest.calisero.ro/api/v1",  # The default
    app_info=AppInfo("MyShop", "2.1.0"),  # Named in the User-Agent header
)

# One call with a timeout of its own
client.messages.list(timeout=5)

Every request goes to https://rest.calisero.ro/api/v1 with a 30-second timeout and the headers Authorization: Bearer <key>, Accept: application/json, Content-Type: application/json and the User-Agent below. Redirects are not followed, so the API key never goes to another host.

TLS

The API accepts HTTPS connections with TLS 1.2 or TLS 1.3 only: since 1 November 2026, a client that offers only TLS 1.0 or 1.1 is refused during the TLS handshake, with no HTTP answer (a TransportError), and nothing is sent or billed. Python 3.10 and later offer TLS 1.2 and 1.3 by default, so the library needs nothing more; an ssl_context of your own must allow one of them.

Keep the base URL on https://: the API redirects http:// to https://, and the library follows no redirect, so a request to http:// fails with an ApiError carrying the 3xx status.

User-Agent

Every request names the library and its version, then the runtime, so Calisero can tell its requests apart and see which version sent them:

User-Agent: Calisero-SMS-Python/1.0.2 (CPython 3.14.0; linux x86_64)

A request whose User-Agent starts with Calisero-SMS-Python/ comes from this library. Give your application's name with app_info and it follows, so the requests of each of your applications can be told apart too:

client = SmsClient.create(os.environ["CALISERO_API_KEY"], app_info=AppInfo("MyShop", "2.1.0"))

print(client.http_client.user_agent)
# Calisero-SMS-Python/1.0.2 (CPython 3.14.0; linux x86_64) MyShop/2.1.0

Characters a header does not allow (spaces, diacritics…) become - in the name and the version.

Through a Proxy, with Your Own TLS Settings

The HTTPS_PROXY and NO_PROXY environment variables apply by default. To set a proxy, or TLS settings such as a certificate authority of your own:

import ssl

client = SmsClient.create(
    os.environ["CALISERO_API_KEY"],
    proxy="http://proxy.internal:3128",
    ssl_context=ssl.create_default_context(cafile="/etc/ssl/certs/internal-ca.pem"),
)

Custom Transport

A transport sends a request and returns the answer, whatever its status; it raises only when there is no answer. Write your own to log the traffic, add headers, or plug in another HTTP client:

import time

from calisero import HttpRequest, HttpResponse, SmsClient, UrllibTransport


class LoggingTransport:
    def __init__(self) -> None:
        self.inner = UrllibTransport(timeout=15)

    def send(self, request: HttpRequest) -> HttpResponse:
        started = time.perf_counter()
        response = self.inner.send(request)
        print(f"{request.method} {request.url} → {response.status} in {time.perf_counter() - started:.3f} s")

        return response


client = SmsClient.create(os.environ["CALISERO_API_KEY"], transport=LoggingTransport())

With httpx (connection pooling, HTTP/2):

import httpx

from calisero import HttpRequest, HttpResponse, SmsClient


class HttpxTransport:
    def __init__(self, client: httpx.Client) -> None:
        self.client = client

    def send(self, request: HttpRequest) -> HttpResponse:
        response = self.client.request(
            request.method,
            request.url,
            headers=request.headers,
            content=request.body,
            timeout=request.timeout if request.timeout is not None else httpx.USE_CLIENT_DEFAULT,
        )

        return HttpResponse(response.status_code, response.headers.multi_items(), response.content)


client = SmsClient.create(os.environ["CALISERO_API_KEY"], transport=HttpxTransport(httpx.Client(timeout=30)))

With requests, HttpResponse(response.status_code, response.headers.items(), response.content) reads the answer of session.request(..., allow_redirects=False). A transport's request carries a repr() that hides the API key, so it can be logged as is.

Building the Client Yourself

SmsClient.create() covers the usual needs. For anything else, build the HttpClient yourself: its last_response is the raw answer to the last request, headers included.

from calisero import BearerTokenAuthProvider, HttpClient, SmsClient, UrllibTransport

http_client = HttpClient(
    BearerTokenAuthProvider(os.environ["CALISERO_API_KEY"]),  # Or your own get_token() provider
    transport=UrllibTransport(timeout=60),
    base_url="https://rest.calisero.ro/api/v1",
)

client = SmsClient(http_client)
client.accounts.get("account-uuid-here")

print(http_client.last_response.get_header_line("X-Trace-Id"))

asyncio

The client is synchronous. In asyncio code, run its calls in a thread, where they do not block the event loop:

message = (await asyncio.to_thread(client.messages.create, recipient="+40742***350", body="Hello!")).data

A client can be shared by several threads.

Type Hints

The library ships its type information (py.typed) and passes mypy --strict: the calls, the models and the exceptions are all typed. The models are frozen dataclasses:

from calisero import CreateMessageResponse, Message, SmsClient

response: CreateMessageResponse = SmsClient.create(api_key).messages.create(recipient="+40742***350", body="Hello!")
message: Message = response.data

Testing

uv run pytest                     # Run the tests
uv run pytest --cov               # With coverage
uv run ruff check . && uv run ruff format --check .   # Code style (Ruff)
uv run mypy                       # Types, strict
sh scripts/qa.sh                  # Everything CI runs: lint, types, tests, package smoke tests, examples

TESTING.md describes the suite: unit tests, integration tests over real HTTP against a local server, contract tests against the API's OpenAPI document, and smoke tests of the built package.

Testing Your Implementation

Give the client a stub transport: your tests then run without the network and see every request.

import json

from calisero import HttpRequest, HttpResponse, SmsClient


class StubTransport:
    def __init__(self, *answers: HttpResponse) -> None:
        self.answers = list(answers)
        self.requests: list[HttpRequest] = []

    def send(self, request: HttpRequest) -> HttpResponse:
        self.requests.append(request)

        return self.answers.pop(0)


def test_sends_the_order_confirmation() -> None:
    message = {
        "id": "9e2574e8-3615-4090-9b5a-0fc812079da8",
        "recipient": "+40742***350",
        "body": "Order #1001 confirmed!",
        "parts": 1,
        "created_at": "2025-02-06T10:18:43.000000Z",
        "status": "scheduled",
    }
    transport = StubTransport(HttpResponse(201, {}, json.dumps({"data": message})))
    client = SmsClient.create("test-key", transport=transport)

    send_order_confirmation(client, order)  # Your code

    assert json.loads(transport.requests[0].body) == {"recipient": "+40742***350", "body": "Order #1001 confirmed!"}

To test error handling, answer with the error the API sends, e.g. HttpResponse(422, {}, json.dumps({"message": "The recipient field is required.", "errors": {"recipient": ["The recipient field is required."]}})).

Contributing

Please see CONTRIBUTING.md for details on how to contribute to this project.

Security

If you discover any security-related issues, please email support@calisero.ro instead of using the issue tracker.

License

This library is open-sourced software licensed under the MIT license.

Support

Changelog

Please see CHANGELOG.md for more information on what has changed recently.

Metadata

Release files for calisero 1.0.2

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

Source distribution (sdist)

Source distribution for calisero 1.0.2
File Size Uploaded Provenance Actions
calisero-1.0.2.tar.gz 106.2 kB With provenance Details for calisero-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for calisero 1.0.2
File Interpreter ABI Platform Actions
calisero-1.0.2-py3-none-any.whl Python 3 none any Details for calisero-1.0.2-py3-none-any.whl

Total release size: 163.1 kB

Release files / calisero-1.0.2.tar.gz

Download URL calisero-1.0.2.tar.gz
Size 106.2 kB
Tags Source
SHA-256 checksum
How to use checksums
21713e1358ed5e604315eca95d6ebeb69fdd0f42ed973a0f536ef9e79a699961
BLAKE2b-256 checksum
How to use checksums
9c9cf11d6dd3bb56699f278c3162bd59a060347d7252f7d1175b0bee2ad1bc9f
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 26, 2026.

Transparency log

Release files / calisero-1.0.2-py3-none-any.whl

Download URL calisero-1.0.2-py3-none-any.whl
Size 57.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d2bf8198fe3c1f5866c072e768a4af2fb815d3afe0fa4736ce5549989c87d89
BLAKE2b-256 checksum
How to use checksums
76d236f9605900bd6786b0c9dabdae8306468a67c2fd93528b00a10d4995dda8
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 26, 2026.

Transparency log

Security for calisero 1.0.2

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 calisero-1.0.2.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 26, 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

1.0.2 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