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

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un expert Python spécialisé dans l'automatisation et le scripting. Je dois créer un script Python pour automatiser une tâche répétitive.

Tâche à automatiser :
[DÉCRIRE_LA_TÂCHE: ex. synchronisation de fichiers entre S3 et serveur local, envoi de rapports PDF par email, extraction et transformation de données CSV]

Spécifications :

  • Fréquence d'exécution : [EX: quotidiennement via cron, manuellement à la demande]
  • Sources de données : [EX: fichiers CSV, API REST, base de données PostgreSQL]
  • Destinations : [EX: bucket S3, base de données, emails]
  • Volume de données : [EX: 10 000 lignes/jour]
  • Contraintes : [EX: Python 3.11+, pas de dépendances externes lourdes]

Crée un script Python professionnel qui inclut :

  1. Architecture : structure modulaire avec séparation des responsabilités (config, modèles, services, main).
  2. Configuration : utilise argparse pour les arguments CLI et python-dotenv ou configparser pour la configuration, jamais de valeurs hardcodées.
  3. Logging : logging structuré avec différents niveaux, rotation des fichiers de log, format adapté à la production.
  4. Gestion des erreurs : exceptions spécifiques, retry avec backoff exponentiel pour les appels réseau, rapport d'erreurs clair.
  5. Idempotence : le script peut être relancé sans effets de bord en cas d'interruption.
  6. Tests : tests unitaires pytest pour les fonctions principales avec mocking des dépendances externes.
  7. Documentation : docstrings, README avec instructions d'installation et d'utilisation.
100% found this useful

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

<p>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.</p><p>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.</p><p>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).</p>

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

  • 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

💻DeveloppementBeginnerAll AIs

Brand Comment Responses

Consistent and fast social media community management

0219
💻DeveloppementIntermediateClaude

Complete Code Review for Pull Requests

Get an exhaustive code review covering quality, performance, security, and maintainability for any language.

34560
💻DeveloppementAdvancedChatGPT

Master Advanced TypeScript Types

Strengthen your code's type safety with advanced generics, utility types, and discriminated unions.

39548
💻DeveloppementIntermediateAll AIs

Perplexity Prompt for Generating Python Code

Perplexity AI stands out from other AI assistants with its unique ability to combine real-time web search and code generation. When it comes to producing Python code, this advantage is significant: Perplexity can rely on the latest official documentation, current best practices, and up-to-date libraries to generate reliable and modern code. Unlike a classic LLM whose knowledge is frozen at a cutoff date, Perplexity verifies its sources in real time, drastically reducing the risk of obsolete code or deprecated functions. Whether you are a developer looking to speed up your workflow, a data scientist wanting to prototype quickly, or a beginner learning Python, a well-structured prompt turns Perplexity into a true development assistant. The key lies in the precision of your request: by specifying the technical context, constraints, and expected output format, you get production-ready code rather than a generic snippet. This guide offers optimized prompts to get the most out of Perplexity in your Python projects.

0204