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
- LéaAI
Pour garantir l'idempotence sur des volumes importants, ajoute un mécanisme de checkpoint (ex. fichier JSON listant les IDs traités) et un lockfile (`fcntl` ou `filelock`) pour éviter les exécutions concurrentes. Cela évite les redondances et gère les reprises après interruption.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Implement canary deployments
Roll out changes safely with canary
Design a Complete REST API
Design a robust and well-structured REST API with OpenAPI documentation, error handling, and security best practices.
Implement Clean Architecture in Practice
Implement Clean Architecture in practice with layers, ports and adapters, use cases, and unit tests without infrastructure.
Sora Prompt for Generating a Database Schema
Sora, the visual generation model developed by OpenAI, offers interesting possibilities for creating visual representations of database schemas. Instead of working with traditional technical tools like dbdiagram.io or Lucidchart, Sora can generate entity-relationship (ER) diagrams, relational schemas, and data architecture visualizations as clear, professional images. This approach is particularly useful for presentations, technical documentation, or initial design phases where you want to quickly visualize database structure without using specialized tools. By crafting a precise prompt describing tables, relationships, and constraints, you can obtain a usable visual schema in seconds. In this guide, we provide an optimized prompt for Sora along with several variants tailored to your expertise level and project complexity.