Python Script Generator Prompt
Turn a plain-language task into a complete Python script with explicit requirements, safe defaults, dependency choices, error handling, tests, and run instructions.
Prompt Template
You are a senior Python developer turning my task description into a complete, testable script. Ask targeted questions when a missing decision would materially change behavior; otherwise state conservative assumptions. Task: [what the script must do] Python version: [version] Runtime: [operating system, local machine, server, container, notebook] Inputs: [arguments, stdin, files, API responses, example values] Expected outputs: [stdout, files, return values, example] Data size and performance needs: [details] Allowed dependencies: [standard library only or approved packages and versions] File and directory rules: [paths, overwrite policy, naming] Network or API details: [documented endpoint, authentication method, rate limits, or none] Error behavior: [skip, retry, fail fast, partial output, exit codes] Security and privacy constraints: [secrets, personal data, untrusted input] Logging needs: [level, destination, redaction] Interface: [single function, CLI, reusable module, scheduled job] Tests required: [unit, integration, sample fixtures] Style and project conventions: [typing, formatter, linter, docstrings] Existing code or schema: [paste] Provide: 1. A concise requirements checklist and clearly labeled assumptions. 2. Any blocking questions whose answers are necessary before safe code can be written. 3. A short design explaining data flow, functions, dependencies, and failure handling. 4. Complete runnable Python code with type hints and no placeholder ellipses. 5. Dependency installation and exact run commands. 6. Tests for normal input, edge cases, invalid input, and failure paths. 7. A sample invocation and expected output derived only from supplied examples. 8. Security notes for paths, subprocesses, SQL, network input, secrets, and personal data when relevant. 9. Limitations and the next changes needed for production use. 10. A final self-review for correctness, portability, destructive behavior, and unsupported APIs. Do not invent a package API, credential, file path, schema field, or successful test result. Never overwrite or delete files unless I explicitly request it and the script includes a safe preview or confirmation path.
Example Output
Requirements
- Read integers from a supplied text file, one value per line.
- Reject invalid lines with their line numbers.
- Print count, minimum, maximum, and mean.
- Use the standard library and never modify the input file.
Script
from pathlib import Path
from statistics import mean
def summarize(path: Path) -> dict[str, float | int]:
values: list[int] = []
for number, raw in enumerate(path.read_text().splitlines(), start=1):
try:
values.append(int(raw.strip()))
except ValueError as exc:
raise ValueError(f"invalid integer on line {number}") from exc
if not values:
raise ValueError("input contains no integers")
return {"count": len(values), "min": min(values), "max": max(values), "mean": mean(values)}
Tests
Cover valid values, negative values, a blank file, and an invalid line. No test result is claimed until the tests are run.
Tips for Best Results
- ๐กSupply concrete input and output examples; they become an executable contract for the generated script.
- ๐กList approved dependencies and Python version so the model does not invent or choose incompatible APIs.
- ๐กState overwrite, deletion, secret, and personal-data rules explicitly before generating automation code.
Frequently Asked Questions
What is the Python Script Generator Prompt prompt?
Turn a plain-language task into a complete Python script with explicit requirements, safe defaults, dependency choices, error handling, tests, and run instructions. It's a free ChatGPT prompt template from our Coding collection โ copy it, fill in the bracketed variables, and paste it into your AI tool.
Which AI tools work with this prompt?
It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.
How do I customize this ChatGPT prompt?
Replace the bracketed variables โ such as [what the script must do], [version], [stdout, files, return values, example] โ with your own details before running it. Supply concrete input and output examples; they become an executable contract for the generated script.
Is this prompt free to use?
Yes. Every prompt on PromptAtlas is free to copy, customize, and use โ no signup required.
Related Prompts
Python FileNotFoundError Debugging Prompt
Debug Python FileNotFoundError from the exact traceback, resolved path, working directory, filesystem context, deployment environment, and failing operation.
Python ZeroDivisionError Debugging Prompt
Debug Python ZeroDivisionError from the exact traceback, operand values and types, data path, numeric semantics, runtime context, and failing input.
Python IndentationError Debugging Prompt
Debug Python IndentationError from the exact parser message, whitespace, block structure, source bytes, formatter settings, and runtime version.
Python SyntaxError: Invalid Syntax Debugging Prompt
Debug Python SyntaxError invalid syntax from the exact parser location, surrounding tokens, Python version, generated code, execution context, and minimal reproduction.
Python AttributeError: Object Has No Attribute Debugging Prompt
Debug Python AttributeError from the exact traceback, runtime object type, attribute contract, construction path, version, imports, and minimal reproduction.
Python UnboundLocalError Debugging Prompt
Debug Python UnboundLocalError from the exact traceback, binding scope, assignments, branches, closures, imports, runtime path, and minimal reproduction.