A Python package for real-time MQTT data processing with database integration
Project description
๐ฆ mqtt-processor
A lightweight and extensible Python package for processing MQTT messages and storing them in PostgreSQL. Ideal for IoT data pipelines, sensor networks, and real-time applications.
โจ Features
- ๐ MQTT broker integration
- ๐ ๏ธ Plug-and-play message transformations
- ๐๏ธ PostgreSQL message storage
- โ Clean, testable architecture
- ๐งช Built-in pytest compatibility
- ๐ณ Docker-friendly
๐งฐ Prerequisites โ Mosquitto MQTT Broker Setup
โ Install Mosquitto (Windows) Download from: https://mosquitto.org/download/
Install with default options (add to PATH recommended).
Verify installation:
mosquitto -v ๐ Run Mosquitto Broker Start broker manually (if not running as service):
mosquitto -v
Keep this terminal open.
๐ค Publish Message (PowerShell Admin)
& "C:\Program Files\mosquitto\mosquitto_pub.exe" -h localhost -t sensor/temp -m '{\"temperature\": 44}'
๐ฅ Subscribe to Topic (PowerShell Admin)
mosquitto_sub -h localhost -t sensor/temp
๐ฆ Installation
From PyPI:
pip install mqtt-processor
git clone https://github.com/Deep26011999/mqtt-data-processor.git
cd mqtt-data-processor
pip install .
๐ Basic Usage
from mqtt_processor.client import MQTTClient
client = MQTTClient()
client.start()
# Your app logic here
client.stop()
๐ Custom Message Transformation
def uppercase_payload(topic, payload):
return topic, payload.upper()
client = MQTTClient(process_function=uppercase_payload)
client.start()
โ๏ธ Configuration
You can configure MQTT and PostgreSQL either via environment variables or by editing the default config.py.
# MQTT
export MQTT_BROKER="localhost"
export MQTT_PORT=1883
export MQTT_TOPIC="sensor/#"
# PostgreSQL
export DB_HOST="localhost"
export DB_PORT=5432
export DB_NAME="mqtt_db"
export DB_USER="your_user"
export DB_PASSWORD="your_password"
๐งช Running Tests
Install development requirements:
pip install -r requirements-dev.txt
Run all tests:
pytest tests/
To test a specific file:
pytest tests/test_client.py
๐ Project Structure
arduino
Copy
Edit
mqtt-data-processor/
โโโ src/
โ โโโ mqtt_processor/
โ โโโ __init__.py
โ โโโ client.py
โ โโโ config.py
โ โโโ db_connector.py
โ โโโ processor.py
โ โโโ utils.py
โโโ tests/
โ โโโ test_client.py
โโโ .gitignore
โโโ requirements.txt
โโโ setup.py
โโโ README.md
๐ Security
Always store sensitive credentials like database passwords in environment variables or secure vaults โ avoid hardcoding them in config.py.
๐ License
MIT ยฉ [Deep Shikhar Singh]
See LICENSE for details.
๐ Contributing
Contributions are welcome! Feel free to open issues or pull requests.
If you find this project helpful, give it a โญ on GitHub!
๐ Links
๐ฆ PyPI: mqtt-processor
๐ ๏ธ GitHub Repo
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 mqtt_processor-0.1.0.tar.gz.
File metadata
- Download URL: mqtt_processor-0.1.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91c9fc88f5e26a21d3b1500974a4f4e52219a9ff35f41ba632d28901aeaef995
|
|
| MD5 |
5a26dd9f8f1edbfbce386a1975d9452f
|
|
| BLAKE2b-256 |
331d4e67a01990ba8ee8f0737334c97c53973171196862905e7cdeaa66a8bca2
|
File details
Details for the file mqtt_processor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mqtt_processor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
948d0e1291762b4b875be180fd8400f5506b6d61425dd30eb0b68cb174fad896
|
|
| MD5 |
e31561f82a4c7cd0646e3d97fe463d37
|
|
| BLAKE2b-256 |
0b875e73e9fd934ad8fd5b7ff18eae69932304d4d6ba091b694b698003962254
|