Asynchronous SMS gateway using Gammu with RESTful API interface
Project description
pySMSGateway
pySMSGateway is an asynchronous Python microservice that interacts with a GSM modem using Gammu. It provides a REST API for sending and receiving SMS messages and retrieving real-time modem and network details such as IMEI, signal quality, and carrier name. Incoming SMS messages can optionally be forwarded to any external service via a configurable webhook.
🚀 Features
- 📤 Send SMS via REST API
- 📥 Receive and decode incoming SMS messages
- 📶 Query modem details (IMEI, model, firmware, signal, operator, etc.)
- 🔁 Poll modem periodically for new messages
- 🔧 Easily integrates with automation, IoT, or monitoring systems
⚙️ Configuration
Set the following environment variables to configure the gateway:
| Variable | Description | Default |
|---|---|---|
WEBHOOK_URL |
URL to forward incoming SMS as a JSON payload (optional) | http://localhost:8123/webhook/sms |
WEBHOOK_TOKEN |
Optional bearer token for secure webhook POSTs | — |
GSM_DEVICE |
Path to GSM modem serial port (e.g. /dev/ttyUSB0) |
/dev/ttyUSB0 |
GSM_CONNECTION |
Modem connection string (e.g. at19200, at115200) |
at115200 |
POLL_INTERVAL |
Interval (seconds) to poll modem for new messages | 10 |
📡 API Endpoints
POST /api/sms/send
Send an SMS message via modem.
Request:
{
"number": "+15551234567",
"text": "Hello from pySMSGateway!"
}
Response:
{ "status": "SMS sent" }
GET /api/sms/info
Retrieve modem metadata and network diagnostics.
Response:
{
"manufacturer": "Quectel",
"model": "EC25",
"firmware": "01.000.01.001",
"imei": "867322032XXXXX",
"signal_quality": { "SignalStrength": 21, "SignalPercent": 55 },
"network_info": {
"NetworkCode": "310260",
"NetworkName": "T-Mobile",
"LAC": "0001",
"CID": "0A2B"
}
}
🔁 Webhook Forwarding
When an incoming SMS is received, a POST request is sent to your WEBHOOK_URL containing:
{
"phone": "+15559876543",
"date": "2025-06-22 11:30:00",
"message": "Your gateway is working!"
}
The Authorization: Bearer WEBHOOK_TOKEN header is included if configured.
🐳 Running via Docker
docker build -t pysmsgateway .
docker run --rm -it \
-e GSM_DEVICE=/dev/ttyUSB0 \
-e GSM_CONNECTION=at115200 \
-e WEBHOOK_URL=https://your-service.example.com/sms \
-e WEBHOOK_TOKEN=your-secret-token \
--device=/dev/ttyUSB0 \
-p 3000:3000 \
pysmsgateway
🛠️ Development
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt # include aiohttp, python-gammu, etc.
python sms_gateway.py
📝 License
MIT License
🤝 Contributing
Bug reports, feature suggestions, and pull requests are welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_smsgateway_async-0.1.2.tar.gz.
File metadata
- Download URL: py_smsgateway_async-0.1.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92c897771dc17bfb96b24d6874166df229f018ede7e6fe6a002aa101b0de57c4
|
|
| MD5 |
c4cc617a9f4504aa23a68a703c5f7739
|
|
| BLAKE2b-256 |
663b57ac8cb537d08bbe94b493d75f7fb25668c5ba833f7bc99673512abdf811
|
File details
Details for the file py_smsgateway_async-0.1.2-py3-none-any.whl.
File metadata
- Download URL: py_smsgateway_async-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5aeb1e792d0fc5ac7611d77d78b90847909d433cccaf870d4392dba44dd25370
|
|
| MD5 |
811ccde8454e7cb50914ab87bfbfeda2
|
|
| BLAKE2b-256 |
4207df397262b546084b6fa43393bf54f37f22018751731d70e4849aacd090ea
|