Skip to main content

A Python package for real-time MQTT data processing with database integration

Project description

๐Ÿ“ฆ mqtt-processor

PyPI version Build Status License: MIT

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mqtt_processor-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mqtt_processor-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

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

Hashes for mqtt_processor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 91c9fc88f5e26a21d3b1500974a4f4e52219a9ff35f41ba632d28901aeaef995
MD5 5a26dd9f8f1edbfbce386a1975d9452f
BLAKE2b-256 331d4e67a01990ba8ee8f0737334c97c53973171196862905e7cdeaa66a8bca2

See more details on using hashes here.

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

Hashes for mqtt_processor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 948d0e1291762b4b875be180fd8400f5506b6d61425dd30eb0b68cb174fad896
MD5 e31561f82a4c7cd0646e3d97fe463d37
BLAKE2b-256 0b875e73e9fd934ad8fd5b7ff18eae69932304d4d6ba091b694b698003962254

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page