A clean and lightweight Python SDK for Termii — send SMS, OTPs, and voice messages effortlessly.
Before anything else, you'll need:
- A Termii account (free to sign up)
- Your Termii API Key — found in your dashboard under Settings → API Keys
- Git installed on your machine
- Python 3.8 or higher
- Go to https://www.python.org/downloads/
- Download the latest Python 3.x installer
- Run the installer — check the box that says "Add Python to PATH" before clicking Install
- Verify the installation:
python --versionmacOS ships with Python 2 (don't touch it). Install Python 3 via Homebrew:
# Install Homebrew if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Python
brew install python
# Verify
python3 --versionsudo apt update
sudo apt install python3 python3-pip python3-venv -y
# Verify
python3 --versiongit clone https://github.com/samdoghor/python-termii.git
cd python-termiiA virtual environment keeps your project dependencies isolated — no global pollution, no version conflicts.
python -m venv venv
source venv/Scripts/activatepython3 -m venv venv
source venv/bin/activateYou'll know it's active when your terminal prompt shows (venv) at the front. To deactivate later, just run
deactivate.
With the virtual environment active, install the project and its dependencies:
The project has a requirements.txt, run this:
pip install -r requirements.txtIf you want to install the package itself in editable mode (so you can import it in your scripts), run:
pip install -e .The -e flag installs it in editable mode, meaning changes you make to the source code are reflected immediately
without reinstalling.
Never hardcode your API key in source files. Use an environment variable instead.
Create a .env file in the project root:
TERMII_API_KEY=your_api_key_here
TERMII_BASE_URL=your_base_url_here
⚠️ The.gitignorealready excludes.envfiles. Do not commit your API key to version control.
Ignore this as test case are not yet pushed to the repo.
The project includes a test/ directory and a test_data.py file. Run the tests to confirm everything is wired up
correctly:
python -m pytest test/Or run the test data file directly:
python test_data.pyIf pytest isn't installed:
pip install pytest
python -m pytest test/Here's a quick example of what using python-termii looks like in practice:
create a file named example.py in the project root with the following content:
import os
from termii_py import Termii # adjust import based on actual module structure
# Initialize with your API key
client = Termii(api_key=os.environ.get("TERMII_API_KEY"), base_url=os.environ.get("TERMII_BASE_URL"))
# Send an SMS
response = client.message.send_message(
to="2348012345678", # recipient phone number (international format)
from_="YourSenderID", # approved sender ID from your Termii dashboard
message="Hello from python-termii!",
type="plain",
channel="generic"
)
print(response)python example.pythere is an already a test_data.py file in the repo that you can use as a reference for how to call the SDK methods.
python test_data.pyNote: Phone numbers must be in international format without the
+sign (e.g.,2348012345678for a Nigerian number).
python-termii/
├── termii_py/ # Core SDK source code
├── test/ # Test files
├── test_data.py # Sample test data / quick test runner
├── pyproject.toml # Project metadata and build config
├── .gitignore
└── LICENSE
ModuleNotFoundError: No module named 'termii_py'
Make sure you ran pip install -e . from the project root with your virtual environment active.
python: command not found (macOS/Linux)
Use python3 instead of python. You can alias it: alias python=python3
API key not being read Double-check that you exported the environment variable in the same terminal session you're running the script from. Each new terminal session starts fresh.
Invalid sender ID Sender IDs must be pre-registered and approved in your Termii dashboard before use.
Built by Samuel Doghor