Turn Ideas into Working Python Scripts
The difference between a script that works and a script thatβs maintainable comes down to a handful of engineering standards: type hints, proper error handling, modular structure, and clear documentation. This recipe applies all of them by default.
The Recipe
Act as an expert Python Automation Engineer and Solutions Architect. I have an idea for a script/tool, and I want you to write a clean, production-ready, Pythonic script to implement it.
My idea/requirements are: [INSERT DETAILS HERE]
Please write the script adhering to the highest professional software standards:
- Type Hinting & Docstrings: Use explicit type hints (PEP 484) and clear Google-style docstrings for every function.
- Error Handling: Avoid bare except: blocks. Wrap external I/O, API calls, or data transformations in robust try-except blocks with meaningful logging or fallback mechanisms.
- Modular Design: Break the logic into single-responsibility functions or classes rather than one giant procedural script.
- Virtual Environment & Dependencies: Include a commented-out section at the very top listing the required external libraries and the exact command to install them.
Ensure the code is clean, deeply commented, and ready to copy-paste into an IDE.
What each standard actually does for you
| Standard | Why it matters |
|---|---|
| Type hints | Catches errors in your IDE before runtime; makes function signatures self-documenting |
| Google-style docstrings | Tells the next person (or future-you) what every function expects and returns |
| Specific exceptions | Bare except: swallows bugs silently; named exceptions make failures debuggable |
| Single-responsibility functions | Each function does one thing β easier to test, easier to change |
| Dependencies block at top | Nobody has to grep the file to figure out what to pip install |
How to write a good requirements description
Vague: βA script that processes CSV files.β
Good: βA script that reads a CSV file of customer records, validates that the email column is a valid email format, deduplicates rows by email address, and writes the cleaned output to a new CSV. Should log how many rows were removed and why.β
The more specific the input, the more directly the script maps to your actual problem.
π Leftover Remixes
πΆοΈ Spicy: βNow add a CLI interface using argparse so I can pass the input file path and output path as command-line arguments, with sensible defaults and a βverbose flag.β
π§ Mild: βWrite just the core processing function β not the full script. Iβll wire it in myself.β
π° Budget: βWhatβs the Pythonic way to handle [specific pattern] β with and without a library?β