Skip to main content

Notifio

PyPI version Python Support License: MIT

Universal Telegram notification service for Python applications. Send formatted messages, alerts, and status updates to Telegram with minimal setup.

Features

  • 🚀 Simple Setup - Configure with just two environment variables
  • 📱 Rich Notifications - Send formatted messages with emojis and structured data
  • 🔄 Multiple Message Types - Success, error, warning, info, and custom notifications
  • ⏰ Sleep/Wake Notifications - Perfect for background tasks and scheduled jobs
  • 📊 Summary Reports - Send detailed summaries with statistics
  • 🛡️ Error Handling - Graceful fallback when notifications fail
  • 🔧 Easy Integration - Works with any Python application

Quick Start

Installation

pip install notifio

Basic Usage

from notifio import get_notifio

# Initialize Notifio (uses environment variables)
notifio = get_notifio()

if notifio:
    # Send a simple message
    notifio.send_message("🚀 Application started successfully!")
    
    # Send a formatted success notification
    notifio.send_success("Data Processing Complete", {
        "Records processed": 1500,
        "Processing time": "2.5 minutes",
        "Status": "Success"
    })

Setup

  1. Create a Telegram Bot:

    • Message @BotFather on Telegram
    • Use /newbot command and follow instructions
    • Save the bot token
  2. Get Your Chat ID:

    • Message your bot or add it to a group
    • Use the provided get_chat_id.py script or visit https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
  3. Set Environment Variables:

    export TELEGRAM_BOT_TOKEN="your_bot_token_here"
    export TELEGRAM_CHAT_ID="your_chat_id_here"
    

    Or create a .env file:

    TELEGRAM_BOT_TOKEN=your_bot_token_here
    TELEGRAM_CHAT_ID=your_chat_id_here
    

Message Types

Basic Message

notifio.send_message("Hello from Notifio!")

Success Notification

notifio.send_success("Task Completed", {
    "Items processed": 100,
    "Success rate": "98%",
    "Duration": "5.2 minutes"
})

Error Notification

notifio.send_error("Database Connection Failed", {
    "Error": "Connection timeout",
    "Retry attempts": 3,
    "Last attempt": "2025-01-27 14:30:00"
})

Warning Notification

notifio.send_warning("High Memory Usage", {
    "Current usage": "85%",
    "Threshold": "80%",
    "Action": "Monitoring"
})

Info Notification

notifio.send_info("System Status", {
    "CPU usage": "45%",
    "Memory usage": "2.1GB",
    "Uptime": "5 days"
})

Sleep/Wake Notifications

# Before going to sleep
notifio.send_sleep_notification("Background Task", 8.5, "2025-01-28 08:00:00", {
    "Processed items": 200,
    "Daily limit": 200
})

# When waking up
notifio.send_wake_notification("Background Task", {
    "Resumed at": "2025-01-28 08:00:00",
    "Items to process": 150
})

Summary Notification

notifio.send_summary("Daily Report", {
    "Total tasks": 25,
    "Completed": 23,
    "Failed": 2,
    "Success rate": "92%"
}, "All systems operational")

Advanced Usage

Custom Formatted Messages

notifio.send_formatted_message("Custom Alert", {
    "Level": "CRITICAL",
    "Service": "API Gateway",
    "Response time": "5.2s"
}, "🚨", "Immediate attention required")

Error Handling

from notifio import get_notifio

notifio = get_notifio()

if not notifio:
    print("Notifio not configured - notifications disabled")
    # Your app continues without notifications
else:
    # Send notifications
    notifio.send_message("App started")

Configuration

Environment Variables

Variable Description Required
TELEGRAM_BOT_TOKEN Your Telegram bot token Yes
TELEGRAM_CHAT_ID Target chat ID for notifications Yes

Optional Configuration

You can also initialize Notifio directly:

from notifio import Notifio

notifio = Notifio(
    bot_token="your_bot_token",
    chat_id="your_chat_id"
)

Examples

Background Job Monitoring

import time
from notifio import get_notifio

notifio = get_notifio()

def process_data():
    if notifio:
        notifio.send_info("Data Processing Started", {
            "Start time": time.strftime("%Y-%m-%d %H:%M:%S"),
            "Status": "Running"
        })
    
    try:
        # Your data processing logic here
        result = process_large_dataset()
        
        if notifio:
            notifio.send_success("Data Processing Completed", {
                "Records processed": result['count'],
                "Duration": f"{result['duration']:.1f} seconds",
                "Status": "Success"
            })
            
    except Exception as e:
        if notifio:
            notifio.send_error("Data Processing Failed", {
                "Error": str(e),
                "Status": "Failed"
            })
        raise

System Monitoring

import psutil
from notifio import get_notifio

notifio = get_notifio()

def check_system_health():
    cpu_percent = psutil.cpu_percent()
    memory = psutil.virtual_memory()
    
    if cpu_percent > 80:
        notifio.send_warning("High CPU Usage", {
            "CPU usage": f"{cpu_percent}%",
            "Memory usage": f"{memory.percent}%",
            "Action": "Monitoring"
        })
    
    if memory.percent > 90:
        notifio.send_error("Critical Memory Usage", {
            "Memory usage": f"{memory.percent}%",
            "Available": f"{memory.available / (1024**3):.1f} GB",
            "Action": "Immediate attention required"
        })

Development

Running Tests

python -m pytest tests/

Building Package

python -m build

Publishing to PyPI

python -m twine upload dist/*

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

Changelog

1.0.0

  • Initial release
  • Basic notification functionality
  • Multiple message types
  • Environment variable configuration
  • Error handling and graceful fallback

Metadata

Release files for notifio 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for notifio 1.0.1
File Size Uploaded Provenance Actions
notifio-1.0.1.tar.gz 11.3 kB Without provenance Details for notifio-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for notifio 1.0.1
File Interpreter ABI Platform Actions
notifio-1.0.1-py3-none-any.whl Python 3 none any Details for notifio-1.0.1-py3-none-any.whl

Total release size: 18.7 kB

Release files / notifio-1.0.1.tar.gz

Download URL notifio-1.0.1.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cc42c4731ef3749d26fb9138d2c8a85fcb71a3c0d992bde78393ecd0ee12009f
BLAKE2b-256 checksum
How to use checksums
20c82f6ed2d78f853f686564189eb2254850cab4bc2a91011214a011042dd2fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / notifio-1.0.1-py3-none-any.whl

Download URL notifio-1.0.1-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da82e9c0ba337db4ddb583b500a28ef09964610d471840a430d84507a9366fdf
BLAKE2b-256 checksum
How to use checksums
7d77a3c6a737dd46f13b881f0c59f5331a1ccdd9db2146917921eb8b7765936e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for notifio 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page