Skip to main content

A lightweight status reporter for Python scripts with Discord and Telegram support

Project description

script-reporter 🚀

A lightweight, zero-dependency Python status reporter designed for automation scripts and cron jobs. Easily report execution progress, stages, and results to Console, Discord, and Telegram.

✨ Key Features

  • Zero External Dependencies: Uses Python standard library only (urllib).
  • Multi-Channel: Simultaneous reporting to Console, Discord (Webhooks), and Telegram (Bot API).
  • Stage Tracking: Monitor exactly where your script is (e.g., SETUP -> PROCESSING -> COMPLETE).
  • Error Transparency: Automatically attaches tracebacks on failure.
  • Duration Tracking: Automatically calculates and reports execution time.
  • CI/CD & Cron Friendly: Standardized JSON output for logs makes it easy for other tools to parse.

📦 Installation

pip install script-reporter

🚀 Quick Start

1. Simple Usage (Auto-reporitng)

Set simple environment variables to enable channels:

  • REPORTER_DISCORD_WEBHOOK: Discord Webhook URL
  • REPORTER_TELEGRAM_TOKEN & REPORTER_TELEGRAM_CHAT_ID: Telegram Bot Token and Chat ID
from script_reporter import ScriptReporter
import traceback

# Initialize with a title (auto-detects Discord/Telegram from Env)
sr = ScriptReporter("My Automation Task")

try:
    # 1. Start a stage
    sr.stage("DATA_FETCH")
    # ... your logic ...
    
    # 2. Update stage as you progress
    sr.stage("PROCESSING")
    # ... your logic ...
    
    # 3. Report success with optional detail dictionary
    sr.success({"items_processed": 100, "status": "all_good"})

except Exception:
    # 4. Report failure with traceback
    sr.fail(traceback.format_exc())

2. Manual Configuration

Explicitly control adapters without environment variables:

from script_reporter import ScriptReporter, ConsoleAdapter, DiscordAdapter, TelegramAdapter

adapters = [
    ConsoleAdapter(),
    DiscordAdapter(webhook_url="https://discord.com/api/webhooks/..."),
    TelegramAdapter(token="BOT_TOKEN", chat_id="CHAT_ID")
]

sr = ScriptReporter("Manual Config Task", adapters=adapters)
sr.success({"msg": "Hello from code!"})

📊 JSON Log Format

ConsoleAdapter prints a machine-readable JSON line starting with __RESULT__:

__RESULT__ {"title": "My Task", "host": "server-01", "stage": "COMPLETE", "status": "SUCCESS", "duration": "1m 30s", "detail": {"processed": 5}}

🛠 Advanced Concepts

  • Stages: Use sr.stage("NAME") to track progress. If sr.fail() is called, it identifies the last successful stage.
  • Duration: Tracks time from ScriptReporter() initialization to success()/fail() call.
  • Discord Rich Embeds: DiscordAdapter automatically formats details and errors into beautiful rich embeds.

📄 License

MIT License. See LICENSE for more details.

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

script_reporter-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

script_reporter-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file script_reporter-0.1.1.tar.gz.

File metadata

  • Download URL: script_reporter-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for script_reporter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 930a9ad25406ae39185a12879a7365d537605f43810fd68698f6eba4ae7dc37c
MD5 9820f425e952cf5050130bbb802bad79
BLAKE2b-256 fd53c8dcd64da8b1a0ccdf79ff290a466ec5e527b27c2002e131e0ab8db2dabb

See more details on using hashes here.

File details

Details for the file script_reporter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for script_reporter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89bb580fdab6b497f8f27aed9231a874e7a6394a7146b44ce6954cbb103fa3d2
MD5 1dea6697372f3ec50e8f517f0930c217
BLAKE2b-256 2538ee5dc2309faaff26ac5f80a2498a555099f6d2152d2fbb18412276972b63

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