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)
reporter = ScriptReporter("My Automation Task")

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

except Exception:
    # 4. Report failure with traceback
    reporter.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")
]

reporter = ScriptReporter("Manual Config Task", adapters=adapters)
reporter.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 reporter.stage("NAME") to track progress. If reporter.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.0.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.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: script_reporter-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 db0e55034b69e4e3aa29a730b23ebe90ee9af7d634fe0ba892f4177e9d3d22b8
MD5 5e9965b1c5cea130bdb3b5e738a3ac55
BLAKE2b-256 f2f0894524332a98d343aa61a2213354144756b1c1e0c9c6be989c05946cfb25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for script_reporter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae4b0e8ec81d87be976895f02a33515b9ebf31fe47c45ea97057965ff86a36f7
MD5 b081c9a690b3fb72dc072da918476ba4
BLAKE2b-256 108a4386419bffb22a22f4c61fdfc0bfa1de26bd0214893c47866cd8d423d99e

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