DeepSeek Python Task Automation Script Builder Prompt
Build complete, production-ready Python automation scripts for any repetitive task with full error handling and tests.
Category
💻 Coding
Difficulty
Intermediate
Models
3
Last Updated
2026-06-28
Works with
📄 Example output
⚠️ Common Mistakes
❓ FAQ
⚙️ Fill in your variables
📋 Prompt
You are a senior Python developer specialising in task automation.
Task: [detailed description of what to automate]
Input: [what data/files/sources the script receives]
Output: [what the script produces]
Environment: [local Mac/Windows/Linux/cloud]
Python: [3.10+/3.12/latest]
Write a complete production-ready script:
1. OVERVIEW: What it does, inputs, outputs, runtime estimate
2. COMPLETE CODE: Full imports, type hints, docstrings, inline comments, try/except for ALL external ops, logging, argparse if applicable, constants at top
3. DEPENDENCIES: requirements.txt + pip install command
4. USAGE: 3 command-line examples with expected output
5. TESTS: 3 pytest tests for core logic
6. EDGE CASES: What the script handles and what it doesn't
Task: [detailed description of what to automate]
Input: [what data/files/sources the script receives]
Output: [what the script produces]
Environment: [local Mac/Windows/Linux/cloud]
Python: [3.10+/3.12/latest]
Write a complete production-ready script:
1. OVERVIEW: What it does, inputs, outputs, runtime estimate
2. COMPLETE CODE: Full imports, type hints, docstrings, inline comments, try/except for ALL external ops, logging, argparse if applicable, constants at top
3. DEPENDENCIES: requirements.txt + pip install command
4. USAGE: 3 command-line examples with expected output
5. TESTS: 3 pytest tests for core logic
6. EDGE CASES: What the script handles and what it doesn't
```python
#!/usr/bin/env python3
"""Markdown File Analyser — extracts metadata and exports summary CSV.
Usage: python md_analyser.py /path/to/folder [--output results.csv]"""
import argparse, csv, logging, re
from pathlib import Path
from typing import NamedTuple
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
log = logging.getLogger(__name__)
class FileStats(NamedTuple):
filename: str; title: str; word_count: int; heading_count: int
def extract_title(content: str) -> str:
"""Extract first H1."""
m = re.search(r'^#\s+(.+)$', content, re.MULTILINE)
return m.group(1).strip() if m else 'Untitled'
def count_words(content: str) -> int:
"""Count words, excluding code blocks."""
return len(re.sub(r'```[\s\S]*?```', '', content).split())
def analyse_file(fp: Path) -> FileStats | None:
try:
c = fp.read_text(encoding='utf-8')
return FileStats(fp.name, extract_title(c), count_words(c),
len(re.findall(r'^#{1,6}\s', c, re.MULTILINE)))
except (OSError, UnicodeDecodeError) as e:
log.warning('Could not read %s: %s', fp, e); return None
def main() -> None:
p = argparse.ArgumentParser()
p.add_argument('folder', type=Path)
p.add_argument('--output', type=Path, default=Path('summary.csv'))
args = p.parse_args()
stats = [s for f in sorted(args.folder.glob('*.md')) if (s := analyse_file(f))]
with open(args.output, 'w', newline='') as f:
w = csv.writer(f)
w.writerow(['filename','title','word_count','heading_count'])
w.writerows(stats)
log.info('Saved %d rows to %s', len(stats), args.output)
if __name__ == '__main__': main()
```
DEPENDENCIES: stdlib only
USAGE: python md_analyser.py . | python md_analyser.py ./docs | python md_analyser.py ./docs --output out.csv
#!/usr/bin/env python3
"""Markdown File Analyser — extracts metadata and exports summary CSV.
Usage: python md_analyser.py /path/to/folder [--output results.csv]"""
import argparse, csv, logging, re
from pathlib import Path
from typing import NamedTuple
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
log = logging.getLogger(__name__)
class FileStats(NamedTuple):
filename: str; title: str; word_count: int; heading_count: int
def extract_title(content: str) -> str:
"""Extract first H1."""
m = re.search(r'^#\s+(.+)$', content, re.MULTILINE)
return m.group(1).strip() if m else 'Untitled'
def count_words(content: str) -> int:
"""Count words, excluding code blocks."""
return len(re.sub(r'```[\s\S]*?```', '', content).split())
def analyse_file(fp: Path) -> FileStats | None:
try:
c = fp.read_text(encoding='utf-8')
return FileStats(fp.name, extract_title(c), count_words(c),
len(re.findall(r'^#{1,6}\s', c, re.MULTILINE)))
except (OSError, UnicodeDecodeError) as e:
log.warning('Could not read %s: %s', fp, e); return None
def main() -> None:
p = argparse.ArgumentParser()
p.add_argument('folder', type=Path)
p.add_argument('--output', type=Path, default=Path('summary.csv'))
args = p.parse_args()
stats = [s for f in sorted(args.folder.glob('*.md')) if (s := analyse_file(f))]
with open(args.output, 'w', newline='') as f:
w = csv.writer(f)
w.writerow(['filename','title','word_count','heading_count'])
w.writerows(stats)
log.info('Saved %d rows to %s', len(stats), args.output)
if __name__ == '__main__': main()
```
DEPENDENCIES: stdlib only
USAGE: python md_analyser.py . | python md_analyser.py ./docs | python md_analyser.py ./docs --output out.csv
🏆
💡 Pro Tips
Best model for this prompt
DeepSeek
DeepSeek V3 / R1
Add --dry-run to scripts that modify or delete files — run without side effects first
Use pathlib.Path throughout — more readable and cross-platform than os.path
Log at INFO for normal ops, WARNING for recoverable issues, ERROR for failures
Put all configurable constants at the top — hardcoded values buried in functions are maintenance nightmares
No error handling for file I/O — files can be missing, permissions fail, encoding can differ
Hardcoding paths like /home/user/docs — use argparse or Path.home() for portability
No progress indication for long-running scripts — add tqdm for batch operations
Mixing script logic with main() — keep functions small and testable; main() only wires them together
- subprocess vs os.system?subprocess.run() always. Never os.system() — less safe, less flexible, harder to capture output. Use subprocess.run(..., capture_output=True, text=True, check=True) as your default.
- When to use asyncio?When making many overlapping I/O calls (fetching multiple URLs, calling multiple APIs). For sequential automation, asyncio adds complexity without benefit.
- Best model for Python scripts?DeepSeek V3 and R1 reason about edge cases systematically, write idiomatic Python with proper type hints. Claude is also strong and better at explaining architectural decisions.
- Schedule a Python script?Mac/Linux: cron (crontab -e). Windows: Task Scheduler. Cloud: GitHub Actions on a cron schedule, AWS Lambda with EventBridge. For simple cases, cron first.