P
💻DeveloppementIntermediateGemini

Create a Python Automation Script

Create a professional Python automation script with CLI configuration, structured logging, error handling, and tests.

Paste in your AI

Adapt this prompt

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:

  1. Architecture: modular structure with separation of concerns (config, models, services, main).
  2. Configuration: use argparse for CLI arguments and python-dotenv or configparser for configuration, never hardcoded values.
  3. Logging: structured logging with different levels, log file rotation, production-ready format.
  4. Error handling: specific exceptions, retry with exponential backoff for network calls, clear error reporting.
  5. Idempotency: the script can be rerun without side effects if interrupted.
  6. Tests: pytest unit tests for the main functions with mocking of external dependencies.
  7. 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

Automating repetitive tasksETL data transformation scriptsPython DevOps tools

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 Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateClaude

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.

1681
💻DeveloppementIntermediateClaude

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.

640
💻DeveloppementAdvancedAll AIs

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.

411
💻DeveloppementIntermediateAll AIs

Generate Storybook Stories for UI Components

Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.

473