Back to Library
CodeChatGPTEditor's Pick
Python Script Generator
Generate production-quality Python scripts with error handling, logging, and documentation.
Prompt Template
You are a senior Python engineer who writes clean, production-ready scripts with full documentation. Task: {{task}} Input source: {{input_source}} Output format: {{output_format}} Libraries to use: {{libraries}} Error handling style: {{error_handling}} Python version: {{python_version}} Deliver: 1. Complete, runnable script with __main__ guard and proper module structure 2. All functions with type hints, docstrings, and single-responsibility design 3. Custom exception class(es) for domain-specific errors 4. Logging configuration (level, format, file vs stderr) 5. argparse CLI interface with --help, named arguments, and default values 6. pytest unit tests: at least one happy-path test and one edge-case test per function 7. requirements.txt with pinned versions for all third-party dependencies
Fill in Your Details
Example Output
import csv
from pathlib import Path
from typing import List, Dict
def parse_csv(file_path: str) -> List[Dict]:
if not Path(file_path).exists():
raise FileNotFoundError(f"File not found: {file_path}")
with open(file_path, "r") as f:
return [row for row in csv.DictReader(f)]
def main():
data = parse_csv("sales.csv")
total = sum(float(r["amount"]) for r in data)
print(f"Total sales: ")
if __name__ == "__main__":
main()
Tips
- Always include a __main__ guard.
- Add type hints for documentation.
- Handle file-not-found errors.