P
BeginnerAll AIs

Write a Python automation script

Generate a production-ready Python automation script with argparse, logging, error handling, idempotence and complete documentation.

Paste in your AI

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

Tu es un expert Python. Écris un script d'automatisation robuste et bien structuré.

**Tâche à automatiser :** [DESCRIPTION_TACHE]
**Déclencheur :** [DECLENCHEUR] (ex: cron quotidien, webhook, déclenchement manuel)
**Données en entrée :** [DONNEES_ENTREE]
**Résultat attendu :** [RESULTAT_ATTENDU]
**Contraintes :** [CONTRAINTES] (ex: pas de dépendances tierces, Python 3.11+)

Le script doit inclure :
1. **Argparse** : arguments en ligne de commande avec --help documenté
2. **Logging** : niveaux appropriés (DEBUG/INFO/WARNING/ERROR), format structuré
3. **Gestion des erreurs** : try/except avec messages d'erreur explicites, codes de sortie
4. **Configuration** : fichier config ou variables d'environnement
5. **Idempotence** : le script peut être relancé sans effet de bord
6. **Tests** : fonction principale testable isolément
7. **Documentation** : docstring module, fonctions principales

Ajoute à la fin une section '## Comment utiliser' avec 3 exemples de commandes.

Why this prompt works

Idempotence is an essential property of automation scripts that is often overlooked: a script run twice should not cause damage. The request for concrete command examples at the end ensures immediate hands-on experience. Exit codes enable integration into shell pipelines.

Use Cases

Automate repetitive maintenance tasksCreate data migration scriptsBuild internal CLI tools

Expected Output

Complete Python script with argparse, structured logging, error handling, configuration, idempotence, tests and usage section with examples.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide