Write a Python Automation Script
Generate a Python automation script with argparse, structured logging, error handling, safe reruns, and usage documentation.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
You are a Python expert. Write a reliable, well-structured automation script.
Task to automate: [TASK_DESCRIPTION]
Trigger: [TRIGGER] (for example, a daily cron job, a webhook, or a manual run)
Input data: [INPUT_DATA]
Expected result: [EXPECTED_RESULT]
Constraints: [CONSTRAINTS] (for example, no third-party dependencies or Python 3.11+)
The script must include:
- argparse for command-line arguments, with documented
--helpoutput - Logging with structured formatting and appropriate levels (DEBUG, INFO, WARNING, ERROR)
- Error handling with try/except blocks, clear error messages, and exit codes
- Configuration through a config file or environment variables
- Idempotence so the script can be rerun without additional side effects
- Testability through a main function that can be tested on its own
- Documentation with a module docstring and docstrings for the main functions
Finish with a "## How to use" section containing 3 example commands.
Personalize this prompt with Léa · AI assistant
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
A scheduled job may run twice, so the prompt asks for a script that can be rerun safely. Exit codes let shell pipelines react to failures. The three example commands show how to run the script for the task you described.
Use Cases
Expected Output
A Python script with argparse, structured logs, error handling, configuration, a main function that can be tested on its own, documentation, and three example commands.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
Be the first to comment on this prompt.
Glossary Terms
📬 Get new prompts every week
Join our newsletter and never miss a prompt.