Kipt

Python prompts for ChatGPT, Claude and Codex

13 Python prompts for ChatGPT, Claude and Codex: idiomatic code, type hints, asyncio, profiling, large files, packaging, version upgrades, CLIs and pandas.

By the Kipt team · Updated 24 October 2026

The best Python prompts tell the model your Python version, paste the real code and ask for a concrete output it can be checked against. Below are 13 Python prompts for ChatGPT, Claude, Claude Code and Codex covering idiomatic code, type hints, asyncio, profiling, memory, packaging, version upgrades, command line scripts and pandas.

General tasks like explaining code, debugging a stack trace and porting between languages are already in the coding prompts, and test writing has its own unit test prompts. Nothing below repeats those.

How to use these prompts

Copy a prompt, replace each blank in double braces, or keep the default after the colon. {{python_version:3.13}} means Python 3.13 unless you type something else.

Three habits matter most for Python:

  • State the version. The current documentation at docs.python.org is for Python 3.15, but your project may run something older. The version decides which syntax, typing features and standard library modules the model may use.
  • Paste real output. A type checker error, a profiler table or a traceback beats a description of one.
  • Name your tools. Say whether you use mypy or pyright, pytest or unittest, pip or another installer. The model will match them instead of guessing.

In an agent, skip the pasting: name the files and let it run the checker or profiler itself.

How do you get idiomatic Python from AI?

1. Write a typed function from a spec

For new code. Asking for a doctest gives you a runnable example of the function's contract.

Write a Python {{python_version:3.13}} function that {{task}}.

Requirements:
- Full type hints, using built-in generics (list[str], dict[str, int]).
- A docstring with one doctest example that shows normal use.
- Raise {{error_type:ValueError}} with a clear message for invalid input.
- Standard library only unless I say otherwise.

Then list two edge cases you handled and one you chose not to handle.

2. Make code more Pythonic

For code that works but reads like another language. The rule about behavior keeps it from becoming a rewrite.

Review this Python code for idioms a senior Python developer would use:
comprehensions, enumerate and zip, context managers, pathlib, f-strings,
dataclasses, early returns and the standard library instead of hand-written
loops.

Do not change behavior or the public interface. For each change, show
before and after in a few lines and say why it is better. Skip changes
that only matter for style.

{{code}}

3. Pick a data model: dataclass, TypedDict or Pydantic

For a new structure. The answer depends on where the data comes from and whether it needs validation.

I need a Python type for {{thing:an order with line items}}. It comes from
{{source:a JSON API response}} and is used for {{use:pricing calculations}}.

Compare dataclass, TypedDict, NamedTuple and {{validation_lib:Pydantic}} for
this case in a short table: validation, immutability, serialization and
runtime cost. Recommend one, then write it with full type hints and a short
example of creating it from the raw data.

How do you add type hints and fix type errors?

The typing module docs say it plainly: "The Python runtime does not enforce function and variable type annotations." Hints pay off only when a checker reads them.

4. Add type hints to untyped code

For an older module. Banning Any forces real types instead of placeholders.

Add type hints to this Python {{python_version:3.13}} module so it passes
{{checker:mypy --strict}}.

Rules:
- Do not use Any or type: ignore. If a type is truly unknown, explain why
  and suggest how to narrow it.
- Prefer Protocol over concrete classes for parameters that only need a
  few methods.
- Do not change runtime behavior.

Show the typed code, then list any place where adding types revealed a
possible bug.

{{code}}

5. Explain a type checker error

For errors that make sense to the checker and nobody else.

{{checker:mypy}} reports this error:

{{error}}

The code it points to:

{{code}}

Explain in plain language what the checker thinks is wrong and whether it
is a real bug or a typing limitation. Give the smallest fix. If there are
several ways to fix it, rank them and say which one keeps the types most
accurate.

How do you make Python faster with AI?

6. Convert blocking I/O to asyncio

For scripts that wait on many network calls in a row. The asyncio task docs recommend asyncio.TaskGroup (added in 3.11) and warn that the event loop keeps only weak references to tasks from create_task.

Convert this Python code to asyncio so the {{io_kind:HTTP requests}} run
concurrently.

- Use asyncio.TaskGroup, not bare create_task calls.
- Limit concurrency to {{max_concurrency:10}} with a Semaphore.
- Add a timeout of {{timeout_seconds:30}} seconds per call with
  asyncio.timeout.
- Use {{http_client:httpx}} for async HTTP.
- Flag any call that still blocks the event loop.

Explain how errors from one task affect the others.

{{code}}

7. Find hotspots in a profile

For slow code where you don't know which part is slow. Paste the table from python -m cProfile -s cumulative your_script.py; the profiling docs list the -s and -o options.

Here is cProfile output for a Python script that takes {{runtime:40 seconds}}
and should take {{target:under 5 seconds}}.

{{profile_output}}

Relevant code:

{{code}}

Rank the three biggest hotspots using tottime and cumtime, and explain
what each number tells us. For each one, suggest a fix and estimate how
much time it could save. Do not suggest rewriting in another language.

8. Process a large file without running out of memory

For data that doesn't fit in RAM. Generators keep memory flat no matter the file size.

This Python code loads a {{file_type:CSV}} file of about {{size:20 GB}}
into memory and crashes. Rewrite it to stream the data.

- Use generators or chunked reads so memory stays roughly constant.
- Keep the same output.
- Show how to report progress every {{progress_every:1 million}} rows.
- Tell me what the peak memory should be and how to measure it with
  tracemalloc.

{{code}}

How do you handle packaging, environments and upgrades?

9. Set up a new project

For starting clean. The venv docs note that a virtual environment should not be committed to source control.

Set up a new Python {{python_version:3.13}} project called {{name}} that is
a {{kind:command line tool}}.

Give me:
- A pyproject.toml with project metadata, dependencies and an entry point
- Config for {{linter:Ruff}} and {{test_runner:pytest}}
- The folder layout using a src/ directory
- The exact commands to create a virtual environment, install in editable
  mode and run the tests
- A .gitignore that covers the virtual environment and build output

10. Fix an import or environment error

For ModuleNotFoundError when the package is clearly installed. The usual cause is two interpreters.

I get this error when running my Python project:

{{error}}

How I run it: {{command}}
Output of `python -c "import sys; print(sys.executable, sys.path)"`:
{{sys_output}}

Explain the most likely cause, such as the wrong interpreter, a missing
virtual environment or a package layout problem. Give the commands to
confirm it, then the fix.

11. Upgrade to a newer Python version

For moving a codebase forward. Each release has a What's New page on docs.python.org listing removals and deprecations.

I'm moving this codebase from Python {{from_version:3.9}} to
{{to_version:3.13}}.

Using the What's New pages for each version in between, list:
1. Removed modules, functions or behaviors this code uses
2. Deprecation warnings it will hit
3. Newer features that would simplify it, worth adopting later

For each item, name the file and line. Then give an upgrade order with the
risky steps first.

{{code_or_file_list}}

How do you write scripts and data code?

12. Write a command line script

For one-off tools that end up in production. Exit codes and logging make them safe to run from cron or CI.

Write a Python {{python_version:3.13}} command line script that {{task}}.

- Use argparse with --help text for every option.
- Use the logging module, with --verbose for debug output.
- Exit with code 0 on success, 1 on failure and 2 on bad arguments.
- Add a --dry-run flag that prints what would happen without doing it.
- Standard library only.

13. Clean a dataset with pandas

For messy CSVs. Asking for a report of what changed catches silent data loss.

Write {{library:pandas}} code that cleans this dataset for
{{goal:a monthly revenue report}}.

Columns and sample rows:
{{sample}}

Set explicit dtypes, parse dates, handle missing values and remove exact
duplicates. Use vectorized operations, not row loops. At the end, print a
short report: rows before and after, and how many values each step changed.

Turn your favorite one into a skill

If you run the same Python prompt every week, make it a skill so Claude Code or Codex applies it whenever the task matches. The type hints and project setup prompts are good first picks. Paste one into the free SKILL.md generator and it turns the prompt into a valid SKILL.md in your browser. For broken code, the debugging prompts cover logs, flaky tests and memory leaks in any language.

To keep these one shortcut away, save them in Kipt. Your prompts live as Markdown in a private GitHub repo you own, the {{blanks}} stay fillable, and Cmd+K finds any prompt by name or tag.

Questions

What are good ChatGPT prompts for Python?

Prompts that name your Python version, paste the real code and ask for a specific output, such as typed code plus a doctest, or ranked hotspots from a profile. Prompts for type hints, asyncio, profiling and upgrades save the most time because those are the areas where generic answers go wrong.

Which Python version should I tell the AI to target?

The one your project actually runs, from your pyproject.toml, Dockerfile or CI config. Models often default to older syntax, so stating the version lets them use newer features safely and avoid ones you don't have yet.

Does Python check type hints at runtime?

No. The Python docs say the runtime does not enforce function and variable type annotations; they are used by type checkers, IDEs and linters. Run a checker such as mypy or pyright in CI to get value from the hints.

Can AI convert my Python code to asyncio?

It can write a solid first version, but only I/O-bound code gets faster with asyncio. Ask the model to use asyncio.TaskGroup, add timeouts and a concurrency limit, and to flag any blocking calls that would stall the event loop.

Do these Python prompts work in Claude Code and Codex?

Yes. In an agent you can name the files instead of pasting code, and let it run the type checker, tests or profiler itself. Ask it to show the command output as evidence before and after each change.

More in Coding

All prompts

Keep your prompts and skills in one place, in your own GitHub. Install every skill with one command.

Get started

Kipt is an independent product, not affiliated with or endorsed by Anthropic, OpenAI, Cursor or GitHub. Claude, ChatGPT, Codex, Cursor and GitHub are trademarks of their owners.