Create a Python Automation Script
Create a professional Python automation script with CLI configuration, structured logging, error handling, and tests.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
You are a Python expert specializing in automation and scripting. I need to create a Python script to automate a repetitive task.
Task to automate:
[describe the task: e.g. syncing files between S3 and a local server, emailing PDF reports, extracting and transforming CSV data]
Specifications:
- Run frequency: [e.g. daily via cron, manually on demand]
- Data sources: [e.g. CSV files, REST API, PostgreSQL database]
- Destinations: [e.g. S3 bucket, database, emails]
- Data volume: [e.g. 10,000 rows/day]
- Constraints: [e.g. Python 3.11+, no heavy external dependencies]
Create a professional Python script that includes:
- Architecture: modular structure with separation of concerns (config, models, services, main).
- Configuration: use argparse for CLI arguments and python-dotenv or configparser for configuration, never hardcoded values.
- Logging: structured logging with different levels, log file rotation, production-ready format.
- Error handling: specific exceptions, retry with exponential backoff for network calls, clear error reporting.
- Idempotency: the script can be rerun without side effects if interrupted.
- Tests: pytest unit tests for the main functions with mocking of external dependencies.
- Documentation: docstrings, README with installation and usage instructions.
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
This prompt takes a software engineering approach to Python scripts, often neglected in favor of non-maintainable one-shot code. Requesting a modular architecture ensures reusable and testable code even for seemingly simple automation scripts. Idempotence is a critical property for production scripts: a script that can be rerun without side effects in case of interruption (network failures, timeouts) is infinitely more reliable than one that leaves the database in an inconsistent state if it stops midway. The combination of argparse + python-dotenv for configuration (versus hardcoded values) is a fundamental best practice that makes the script deployable across different environments without modifying the source code, respecting the environment configuration principle (12-factor app).
Use Cases
Expected Output
A modular Python script with CLI configuration, logging, robust error handling, pytest tests, and usage documentation.
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.
Go further
Improve this prompt with the Optimizer
Analyze the prompt, strengthen the context and get a more precise version.
Gemini Prompts
Practical methods to use Gemini more effectively in your prompts.
AI prompts for web developers
Code review and debugging, keeping API keys and secrets out of the prompt.
Security, GDPR & Business Plans
ChatGPT Business, Claude Team, Gemini Workspace and Mistral Vibe compared from vendor sources: training, EU hosting and a GDPR checklist.
Similar Prompts
Task brief for Claude Code: frame a feature end to end
Brief template to delegate a complete feature to Claude Code: goal, starting point, constraints, definition of done, working rules and recap format.
Write a project's CLAUDE.md: the brief Claude Code reads at every session
Turns your project description into a dense CLAUDE.md: commands, structure, conventions, pitfalls, off-limits areas and situations where the agent must ask before acting.
Design a Secure Webhook API
Design a webhook API with event subscriptions, signed deliveries, retry limits, and a delivery log your support team can inspect.
Generate Storybook Stories for UI Components
Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.