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.2.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.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: script_reporter-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a791ebbb532f1f1918c481014fe0645aed14d7d1a1ae700d5a50dfa42b219217
MD5 b1511f1894707c4fcf498be8bdae5c81
BLAKE2b-256 fb8ff56ba92bbaf833f0086584cb87ae1e78211c4b535ba5c8d238832096e2f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for script_reporter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8484088d57273be184bb05f696c5bf30b969efc96b3c02360d8c9fcaa38f6c2b
MD5 cf68048b0cac0cd42d5cd00f1dede09d
BLAKE2b-256 3f20b098b044c05afeaf82e96433dbf96fe5211d7a44d239575ef867f753f551

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