Python CSV and Excel Report Generator Prompt
Build a script that pulls data from an API or database and produces clean, formatted CSV and Excel reports with headers, types, totals, and safe file handling.
- Target user
- Engineers and analysts automating recurring data exports and reports
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior Python engineer who builds reliable, scheduled reporting jobs that finance and ops teams actually trust. I will provide: - The data source (REST API endpoint or SQL query + connection) - The desired report columns, ordering, and any computed/summary rows - Output formats needed (CSV, XLSX, or both) and where files go - How often it runs and who consumes it Build a script that: 1. **Fetches data robustly** — for APIs, page through results and handle empty/partial responses; for DBs, use parameterized queries (never string-formatted SQL) and a context-managed connection. Stream/iterate rather than loading huge result sets all at once when possible. 2. **Normalizes into a tabular structure** — explicit column order and types; format dates, decimals (money to 2 places), booleans, and nulls consistently. Decide and document timezone handling. 3. **Writes CSV correctly** — use `csv`/`pandas` with explicit encoding (UTF-8 with BOM only if Excel users need it), quoting for fields with commas/newlines, and a stable header row. 4. **Writes Excel well** — with `openpyxl`/`xlsxwriter`: bold frozen header row, auto-ish column widths, number/date cell formats, a totals row, and a metadata sheet (generated-at, source, row count, query params). 5. **Is idempotent and safe** — write to a temp file then atomically rename to the final path; never leave a half-written report. Include the report date in the filename; don't clobber prior runs unless told to. 6. **Validates output** — assert non-empty (or explicitly allow empty), expected column set present, row count sane; exit non-zero on failure so schedulers notice. 7. **Logs a summary** — rows written, file paths, byte sizes, elapsed time. Output: (a) the full script with type hints and a `main()`, (b) config for source + output paths, (c) a dry-run/`--limit` flag for testing, (d) a small sample dataset and the expected CSV/XLSX shape, (e) a note on scheduling (cron/systemd timer). Bias toward: parameterized queries, atomic writes, explicit formatting, and reports that are diffable run-to-run.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Python CSV Data-Quality Validator Prompt
Build a Python CLI that validates and cleans CSV/tabular data against declarative quality rules — types, ranges, required fields, uniqueness, referential checks — and emits a structured report of every violation
-
Python Environment Config Drift Detector Prompt
Build a Python tool that compares configuration or environment-variable sets across environments (dev/staging/prod) and reports missing, extra, and mismatched keys while masking secret values
-
Python Multi-Log Merge and Timeline Correlator Prompt
Build a Python tool that merges several log files with different timestamp formats into one time-ordered timeline, tags each line with its source, and correlates events across services for incident analysis
-
Python Prometheus Pushgateway Batch-Job Metrics Reporter Prompt
Build a Python module that reports batch-job and cron metrics (success, duration, records processed, last-success timestamp) to a Prometheus Pushgateway with correct grouping keys and failure-safe pushing
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.