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 URLREPORTER_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. Ifsr.fail()is called, it identifies the last successful stage. - Duration: Tracks time from
ScriptReporter()initialization tosuccess()/fail()call. - Discord Rich Embeds:
DiscordAdapterautomatically formats details and errors into beautiful rich embeds.
📄 License
MIT License. See LICENSE for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
930a9ad25406ae39185a12879a7365d537605f43810fd68698f6eba4ae7dc37c
|
|
| MD5 |
9820f425e952cf5050130bbb802bad79
|
|
| BLAKE2b-256 |
fd53c8dcd64da8b1a0ccdf79ff290a466ec5e527b27c2002e131e0ab8db2dabb
|
File details
Details for the file script_reporter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: script_reporter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89bb580fdab6b497f8f27aed9231a874e7a6394a7146b44ce6954cbb103fa3d2
|
|
| MD5 |
1dea6697372f3ec50e8f517f0930c217
|
|
| BLAKE2b-256 |
2538ee5dc2309faaff26ac5f80a2498a555099f6d2152d2fbb18412276972b63
|