Skip to main content

Production-grade Python script execution engine with comprehensive monitoring, alerting, analytics, and enterprise integrations

Project description

Python Script Runner

A production-grade Python script execution engine with comprehensive monitoring, alerting, analytics, and real-time visualization.

PyPI Downloads


Features

  • Script execution with timeout, retry, and environment management
  • Real-time visualization of the full execution pipeline
  • DAG-based workflow orchestration with parallel execution
  • Metrics collection — CPU, memory, I/O, timing per run
  • Alert management — rule-based triggers via Slack, email, webhooks
  • History & trend analysis — SQLite persistence with anomaly detection
  • CI/CD integration — JUnit XML, TAP output, performance gates
  • Remote execution — SSH, Docker, Kubernetes
  • Web dashboard — FastAPI backend with WebSocket live updates

Visualization

Run any script with real-time orchestration visualization using the --visualize flag:

python runner.py my_script.py --visualize

Execution Flow Visualization

Each step of the pipeline is displayed with elapsed time and per-step duration (e.g. (0.101s)). Status symbols:

Symbol Meaning
Running
Done
Skipped
Error
🚀 Subprocess launched

Output file

Write a clean (ANSI-free) copy to disk:

python runner.py my_script.py --visualize --visualize-output run.log

JSON output format

Machine-readable structured output for CI pipelines and integrations:

python runner.py my_script.py --visualize --visualize-format json

JSON Visualization Output

The JSON document contains a header, a steps list with per-step elapsed_s and duration_s, and a footer. Access it programmatically with get_execution_report():

from runner import ExecutionVisualizer

v = ExecutionVisualizer(enabled=True, output_format="json", output_file="run.log")
v.show_header("pipeline.py")
# ... steps recorded automatically during runner.run_script() ...
v.show_footer(1.23, success=True)

report = v.get_execution_report()
slow_steps = [s for s in report["steps"] if s.get("duration_s", 0) > 0.5]

Workflow Orchestration

Execute multiple scripts as a DAG with optional parallelism:

from runner import ScriptWorkflow

wf = ScriptWorkflow(
    name="data_pipeline",
    max_parallel=2,          # run up to 2 scripts concurrently
    stop_on_failure=True,    # abort if any script fails
    on_step_callback=lambda name, status, result: print(f"{name}: {status}"),
)

wf.add_script("fetch",     "fetch.py")
wf.add_script("transform", "transform.py", dependencies=["fetch"])
wf.add_script("validate",  "validate.py",  dependencies=["fetch"])
wf.add_script("load_db",   "load_db.py",   dependencies=["transform", "validate"])

# Visualize the DAG before running
print(wf.visualize_dag())

result = wf.execute()

Workflow DAG and Parallel Execution

visualize_dag()

Prints an ASCII-art dependency graph showing node names, dependency arrows, and live execution status:

Workflow: data_pipeline
─────────────────────────────────────────────
[fetch       ] (pending)
    └──▶ [transform   ] (pending)
        └──▶ [load_db     ] (pending)
    └──▶ [validate    ] (pending)
─────────────────────────────────────────────

execute() result

{
    "status": "completed",   # or "aborted" if stop_on_failure triggered
    "total_scripts": 4,
    "successful": 4,
    "failed": 0,
    "total_time": 0.054,
    "results": { ... }       # per-script exit codes, timings, success flags
}

CLI Reference

usage: runner.py [-h] [--timeout TIMEOUT] [--visualize]
                 [--visualize-format {text,json}]
                 [--visualize-output FILE]
                 [--retry N] [--retry-strategy {linear,exponential,fibonacci}]
                 [--monitor-interval SECONDS]
                 [--show-history] [--analyze-trend]
                 [--dashboard] ...
                 script [script_args ...]

Key flags:

Flag Description
--visualize Show real-time execution flow
--visualize-format {text,json} Output format (default: text)
--visualize-output FILE Also write visualization to a file
--retry N Retry on failure up to N times
--retry-strategy linear, exponential, fibonacci, exponential_jitter
--timeout SECONDS Kill script after N seconds
--monitor-interval S Metric sampling interval (default: 0.1s)
--show-history Print recent execution history
--analyze-trend Run trend analysis on metric history
--dashboard Start the web dashboard

Installation

pip install python-script-runner

Or from source:

git clone https://github.com/jomardyan/Python-Script-Runner
cd Python-Script-Runner
pip install -e .

👨‍💻 Author

Hayk Jomardyan

License

MIT License - See LICENSE file for 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

python_script_runner-7.4.4.tar.gz (163.5 kB view details)

Uploaded Source

Built Distribution

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

python_script_runner-7.4.4-py3-none-any.whl (181.2 kB view details)

Uploaded Python 3

File details

Details for the file python_script_runner-7.4.4.tar.gz.

File metadata

  • Download URL: python_script_runner-7.4.4.tar.gz
  • Upload date:
  • Size: 163.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for python_script_runner-7.4.4.tar.gz
Algorithm Hash digest
SHA256 f0bccdeb0d03677fb6f47bf14dab52a9a49dc2f79a68c54a1b2939d9187376aa
MD5 0193d1a74c7382d3ec97417c080e7a5c
BLAKE2b-256 9fd62bdebe5d93910706894a02ec41f717927975a59691ee0c21d2c7ac51e0ac

See more details on using hashes here.

File details

Details for the file python_script_runner-7.4.4-py3-none-any.whl.

File metadata

File hashes

Hashes for python_script_runner-7.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7b026b9a6035d9d9563e9858a3eaee274269c185ceaf120b3b496e8904e84ecd
MD5 d9adb8f8b9237d23efc45b88357951b1
BLAKE2b-256 4b1cb7cd4f1f4046ba3370c5763e232e6abc4b540853af9f6d01255ba782732f

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