How to Send SMS with Python and the DataFlows API

How to Send SMS with Python and the DataFlows API

Learn how to send SMS messages from a Python application using the DataFlows SMS API. This guide covers getting your API token, writing your first script, and best practices for reliable delivery to Australian mobile numbers.

Australian businesses send appointment reminders, order updates, and marketing messages every day, and a large share of these workflows run on Python. If you are building a booking system, an internal tool, or a customer notification service, you need a reliable way to send SMS messages without managing telecom infrastructure yourself.

This guide shows you how to send SMS messages from a Python application using the DataFlows SMS API. You will learn what a Python SMS API integration is, why Australian businesses rely on one instead of building SMS delivery from scratch, and how to write a working Python script that sends a text message in a few lines of code. By the end, you will have a script you can adapt for appointment reminders, order notifications, or one-time passcodes.

What Is a Python SMS API Integration

A Python SMS API integration is a method of sending and receiving text messages from a Python application by making HTTP requests to an SMS provider's API, rather than connecting directly to telecom carriers. Instead of managing SIM cards, modems, or carrier contracts, a developer sends a request containing the recipient's number and message text to an endpoint such as the DataFlows SMS API, and the provider handles delivery across Australian mobile networks.

This approach works with any Python setup, including Flask and Django web applications, scheduled scripts, background workers, and serverless functions. Because the integration relies on standard HTTP calls, it does not require a specific framework or library beyond a way to send a POST request, such as the requests package.

For Australian businesses, a Python SMS API integration is typically the fastest way to add SMS notifications, one-time passwords, or bulk messaging to an existing product without building telecom infrastructure from scratch.

Why It Matters for Australian Businesses

Email open rates keep falling, and many customers do not check apps between visits. SMS remains one of the few channels almost every Australian reads within minutes of receiving it, which makes it well suited for time-sensitive messages like appointment reminders, delivery updates, and verification codes.

For development teams, using an API instead of manual sending means notifications can be triggered automatically from existing systems: a booking is confirmed, an order ships, a password reset is requested. Python is a common choice for these backend workflows because it integrates easily with web frameworks, databases, and scheduling tools already in use across many Australian businesses.

Building SMS sending in Python also keeps the logic close to the rest of the application. Message content, sending rules, retry logic, and error handling can all live in the same codebase as the feature that triggers them, which makes the system easier to maintain over time.

There is also a compliance side to sending SMS in Australia. Businesses need to identify themselves clearly to recipients and provide a way to opt out of marketing messages. Handling this correctly from the start, using a registered Sender ID and a maintained opt-out list, avoids problems later as your sending volume grows.

Key Benefits

Fast integration: A single HTTP POST request from Python is enough to send a message, so most teams have a working integration running within an hour.

Works with any Python framework: Whether the codebase uses Django, Flask, FastAPI, or a plain script, the same HTTP call structure applies.

No telecom infrastructure to manage: DataFlows handles carrier connections, message routing, and delivery across Australian networks.

Scales from one message to bulk campaigns: The same API used for a single OTP message also supports Bulk SMS and SMS Campaigns for larger sends.

Clear delivery visibility: API responses let a Python application track whether a message was delivered, failed, or is still pending.

Step-by-Step Guide: Sending SMS with Python

The steps below walk through sending your first SMS message from Python, then extending that script into a real application workflow.

Step 1: Get Your API Token

Sign in to your DataFlows dashboard and open the Developer section. Generate an API token there and store it as an environment variable rather than hardcoding it in your script, so it stays out of source control.

Step 2: Install the Requests Library

pip install requests

Step 3: Write a Basic Send Script

import os import requests API_TOKEN = os.environ["DATAFLOWS_API_TOKEN"] response = requests.post( "https://api.dataflows.com.au/v1/sms/send", headers={ "Authorization": f"Bearer {API_TOKEN}", "Content-Type": "application/json", }, json={ "to": "+61400000000", "from": "YourBrand", "message": "Hi Sam, your appointment is confirmed for 10am tomorrow.", }, ) print(response.status_code, response.json())

Replace the to, from, and message values with your recipient's number, your registered Sender ID, and the text you want to send. Confirm the exact endpoint path in your dashboard's API documentation, since it can vary slightly depending on your account setup.

Step 4: Handle the Response

DataFlows returns a JSON response that includes a message ID and status. Store the message ID if you want to check delivery status later, and check the HTTP status code before assuming the message was delivered rather than just accepted.

Step 5: Trigger Messages from a Web Application

Most Python SMS integrations do not run as a standalone script. They are triggered by an event, such as a booking confirmation or an order update, inside a Flask or Django view.

from flask import Flask, request import requests import os app = Flask(__name__) API_TOKEN = os.environ["DATAFLOWS_API_TOKEN"] @app.route("/booking-confirmed", methods=["POST"]) def booking_confirmed(): data = request.json requests.post( "https://api.dataflows.com.au/v1/sms/send", headers={"Authorization": f"Bearer {API_TOKEN}"}, json={ "to": data["phone"], "from": "YourBrand", "message": f"Hi {data['name']}, your booking is confirmed.", }, ) return {"status": "sent"}

Step 6: Register a Sender ID

Register a custom Sender ID in your dashboard so recipients see your business name instead of a random number. Once approved, reference it in the from field of every request instead of a generic number.

Step 7: Send an OTP Verification Code

If your Python application needs to verify a phone number during sign-up or login, you can use the same request pattern to send a one-time passcode instead of a fixed message. Generate a random code in your application, store it against the user's session, and send it as the message text.

import os import random import requests API_TOKEN = os.environ["DATAFLOWS_API_TOKEN"] def send_otp(phone_number): code = str(random.randint(100000, 999999)) requests.post( "https://api.dataflows.com.au/v1/sms/send", headers={"Authorization": f"Bearer {API_TOKEN}"}, json={ "to": phone_number, "from": "YourBrand", "message": f"Your verification code is {code}. It expires in 10 minutes.", }, ) return code # store this against the user's session to check later

This pattern covers most sign-up and login flows, though DataFlows also offers a dedicated OTP Verification product if you want code generation, expiry, and attempt limits handled for you instead of writing that logic yourself.

Step 8: Send to Multiple Recipients

For reminders or announcements that go to more than one person, loop over a list of recipients and send a request for each one. For larger sends, such as a promotional campaign to your full customer list, use Bulk SMS or SMS Campaigns from your dashboard instead of looping in your own script, since these are built to handle large recipient lists and Contact Lists directly.

recipients = ["+61400000001", "+61400000002", "+61400000003"] for phone in recipients: requests.post( "https://api.dataflows.com.au/v1/sms/send", headers={"Authorization": f"Bearer {API_TOKEN}"}, json={ "to": phone, "from": "YourBrand", "message": "Reminder: your class starts at 6pm tonight.", }, )

How DataFlows Helps

DataFlows gives Python developers a single API for SMS API sending, OTP Verification, and Virtual Numbers, so the same integration can grow from sending appointment reminders to running full SMS Campaigns.

Contact Lists in the dashboard make it straightforward to manage recipients for SMS Marketing sends without building your own database from scratch, while SMS Automation rules can trigger follow-up messages based on delivery status.

A Virtual Number lets your Python application receive replies as well as send messages, which is useful if you want customers to confirm a booking or reply STOP to opt out directly from the same conversation thread. Incoming messages can be delivered to a webhook endpoint in your application, so your code stays in control of how replies are handled.

If your Python application already uses Zapier, Supabase, or Auth0, DataFlows connects to each of these directly, which means some workflows can be built without writing custom integration code for every step.

Best Practices

Store your API token as an environment variable: Never commit it to source control or hardcode it in a script that might be shared or copied.

Validate phone numbers before sending: Check that numbers are in the correct international format to avoid failed sends and wasted requests.

Handle errors and retries: Wrap your request in a try/except block and log failures so you can investigate delivery issues quickly.

Register a Sender ID for business messages: This builds trust with recipients and helps meet Australian requirements for identifiable sender information.

Respect opt-outs: Keep an unsubscribe list and check it before sending marketing messages, particularly for SMS Marketing and SMS Campaigns.

Monitor delivery status: Use the message ID returned by the API to confirm delivery rather than assuming success from the initial response alone.

Conclusion

Sending SMS from Python does not need to be complicated. A single HTTP request through the DataFlows SMS API is enough to add appointment reminders, order updates, or verification codes to an existing application, and the same integration scales up to bulk campaigns as your needs grow.

Sign up at dataflows.com.au to get your API token from the Developer section and start sending your first message today.

You May Also Like

SMS API Integration Guide

OTP SMS Verification

How to Send Bulk SMS in Australia

SMS Verification Using the DataFlows API

How to Send SMS with DataFlows and Zapier