ChatGPT Prompts for Python Scripts: Automation and Data Processing
ChatGPT prompts for Python scripts. Automation, data processing, API integrations, and CLI tools — production-quality Python with error handling and type hints.
The Prompt
Act as a senior Python engineer who writes clean, well-documented scripts for production automation and data processing.
Write a Python script for:
Task: {describe what the script should do in plain English}
Input: {what data or files the script takes as input}
Output: {what the script should produce}
Python version: {3.10 / 3.11 / 3.12}
Dependencies allowed: {standard library only / list permitted third-party packages}
Error handling level: {basic / comprehensive — with logging}
CLI interface: {yes / no — if yes, describe expected arguments}
Output:
1. Complete script (fully runnable — includes shebang, imports, type hints, docstrings)
2. Requirements.txt snippet (for any third-party packages)
3. Usage examples (command-line examples for 3 different input scenarios)
4. Error cases handled (list of specific errors the script handles and how)
5. Performance notes (time complexity for key operations — relevant if processing large data)
6. Suggested tests (3 pytest test cases for the core logic)
Code standards:
- Type hints on all function signatures
- Docstrings in Google style format
- Logging instead of print statements (except for intentional CLI output)
- No bare except clauses — catch specific exceptions
- Configuration via environment variables or argparse — no hardcoded values
- Main guard: if __name__ == '__main__'
Variables to fill in
-
{task}What the script should do — plain English -
{input}What data or files the script accepts -
{output}What the script produces -
{dependencies}Standard library only or permitted third-party packages -
{error handling}Basic or comprehensive with logging
How to use this prompt
- Describe the task in plain English before specifying implementation details
- List allowed dependencies explicitly — prevents the AI from suggesting packages you can't install
- Use the usage examples to verify the script handles your actual use cases
- Add the suggested tests to your CI pipeline before running the script in production
Type hints are documentation that runs
Python’s type hint system, combined with mypy or pyright, catches a significant percentage of runtime errors at development time. More importantly, type-hinted code is self-documenting — a function signature def process_orders(orders: list[Order]) -> dict[str, float] tells you everything you need to know without reading the body.
Logging beats print statements for every non-trivial script
Print statements disappear in production, can’t be filtered by level, and don’t include timestamps. Python’s logging module gives you DEBUG/INFO/WARNING/ERROR levels, automatic timestamps, and the ability to redirect output to files without changing code. The prompt enforces logging from the start — not after the script is already in production.
argparse removes the ‘where do I configure this’ problem
Hardcoded configuration values are the most common reason a working script breaks when someone else runs it. Using argparse (or environment variables for sensitive values like API keys) makes scripts portable — they work in any environment without code changes. The prompt’s constraint prevents hardcoded values from appearing in the output.
Related free tools
- Free AI Prompt Generator — build structured prompts instantly
- AI Token Counter — estimate API costs before long runs
- AI ROI Calculator — measure AI’s impact on developer productivity