AI CodingThrive Editorial

25 AI Prompts for Python Programming

Python assistants can draft quickly, but the useful result is a small function with explicit types, examples and tests. These prompts surface assumptions before code is written.

13 min read
Python developer desk with laptop, notebook and abstract code shapes.

The short version

  • Python assistants can draft quickly, but the useful result is a small function with explicit types, examples and tests. These prompts surface assumptions before code is written.
  • Never paste credentials, private customer data or entire proprietary repositories into an unapproved assistant. Run suggested commands and tests in your own environment. A plausible patch is not evidence that the change works.

Python assistants can draft quickly, but the useful result is a small function with explicit types, examples and tests. These prompts surface assumptions before code is written.

Never paste credentials, private customer data or entire proprietary repositories into an unapproved assistant. Run suggested commands and tests in your own environment. A plausible patch is not evidence that the change works.

How to use this collection

Pick the task closest to your work. Copy the prompt, replace the generic scene or code context with your own facts, and keep the constraints that help you judge the result. Change one variable at a time so you can tell what improved.

The approach follows the GitHub Copilot prompt engineering guide: provide concrete context and inspect the output rather than assuming a polished first pass is correct.

Diagnose prompts

This set focuses on diagnose. Supply your real code and test command before accepting the answer.

1. A CSV importer

Copy prompt

Help with a CSV importer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

2. A date normalization utility

Copy prompt

Help with a date normalization utility in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

3. A log parser

Copy prompt

Help with a log parser in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

4. A retrying HTTP client

Copy prompt

Help with a retrying HTTP client in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

5. A command-line report

Copy prompt

Help with a command-line report in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

6. A duplicate detector

Copy prompt

Help with a duplicate detector in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

7. A file renamer

Copy prompt

Help with a file renamer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

8. A data validation layer

Copy prompt

Help with a data validation layer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

9. A background task

Copy prompt

Help with a background task in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

CSV records passing through a Python validation workflow.

10. A notebook-to-module refactor

Copy prompt

Help with a notebook-to-module refactor in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the proposed reproduction before applying a patch.

Implement prompts

This set focuses on implement. Supply your real code and test command before accepting the answer.

11. A CSV importer

Copy prompt

Help with a CSV importer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

12. A date normalization utility

Copy prompt

Help with a date normalization utility in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

13. A log parser

Copy prompt

Help with a log parser in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

14. A retrying HTTP client

Copy prompt

Help with a retrying HTTP client in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

15. A command-line report

Copy prompt

Help with a command-line report in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

16. A duplicate detector

Copy prompt

Help with a duplicate detector in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

17. A file renamer

Copy prompt

Help with a file renamer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

Three-step code workflow: brief the work, inspect the result, edit and verify.

18. A data validation layer

Copy prompt

Help with a data validation layer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

19. A background task

Copy prompt

Help with a background task in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

20. A notebook-to-module refactor

Copy prompt

Help with a notebook-to-module refactor in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Review the diff for unrelated changes and unintended data access.

Test boundaries prompts

This set focuses on test boundaries. Supply your real code and test command before accepting the answer.

21. A CSV importer

Copy prompt

Help with a CSV importer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the tests and check that they fail before the fix when feasible.

22. A date normalization utility

Copy prompt

Help with a date normalization utility in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the tests and check that they fail before the fix when feasible.

23. A log parser

Copy prompt

Help with a log parser in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the tests and check that they fail before the fix when feasible.

24. A retrying HTTP client

Copy prompt

Help with a retrying HTTP client in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the tests and check that they fail before the fix when feasible.

25. A command-line report

Copy prompt

Help with a command-line report in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Review: Run the tests and check that they fail before the fix when feasible.

What to check before you use the result

Never paste credentials, private customer data or entire proprietary repositories into an unapproved assistant. Run suggested commands and tests in your own environment. A plausible patch is not evidence that the change works.

If the output misses the task, shorten the prompt and specify the missing fact or constraint. Keep a record of the version you used so the final asset or code change can be reproduced.

Further reading

Continue with a related guide

Put it into practice

Your next step

Have a question or a correction?

Contact Thrive

Keep reading

More from the journal

All articles