Skip to main content

Automatically fix Python code using ChatGPT

Project description

Auto Code Fixer

Auto Code Fixer is a CLI tool that detects runtime failures and automatically fixes Python code using OpenAI.

It is designed for real projects where an entry script imports multiple local modules. The tool runs your code in an isolated sandbox + venv, installs missing external dependencies, and applies fixes only after the code executes successfully.


Installation

pip install auto-code-fixer

Quick start

auto-code-fixer path/to/main.py --project-root . --ask

If you want it to overwrite without asking:

auto-code-fixer path/to/main.py --project-root . --no-ask

What it fixes (core behavior)

✅ Local/internal imports are treated as project code

If your entry file imports something like:

from mylib import add

…and mylib.py exists inside the project, Auto Code Fixer will:

  • copy main.py + mylib.py into a sandbox
  • execute inside the sandbox
  • if the traceback points to mylib.py, it will fix mylib.py
  • then apply the fix back to your repo (with backups)

✅ External imports are auto-installed

If execution fails with:

ModuleNotFoundError: No module named 'requests'

…it will run:

pip install requests

…but only inside the sandbox venv (so your system env isn’t polluted).


Safety

Backups

Before overwriting any file, it creates a backup:

  • file.py.bak (or .bak1, .bak2, ...)

Dry run

auto-code-fixer path/to/main.py --project-root . --dry-run

Advanced options

Run a custom command (pytest, etc.)

Instead of python main.py, run tests:

auto-code-fixer . --project-root . --run "pytest -q" --no-ask

Model selection

export AUTO_CODE_FIXER_MODEL=gpt-4.1-mini
# or
auto-code-fixer main.py --model gpt-4.1-mini

Max retries / timeout

auto-code-fixer main.py --max-retries 8 --timeout 30

Optional AI planning (which file to edit)

auto-code-fixer main.py --ai-plan

This enables a helper that can suggest which local file to edit. It is best-effort.


Environment variables

  • OPENAI_API_KEY (required unless you always pass --api-key)
  • AUTO_CODE_FIXER_MODEL (default model)
  • AUTO_CODE_FIXER_ASK=true|false
  • AUTO_CODE_FIXER_VERBOSE=true|false

Notes

  • This tool edits code. Use it on a git repo so you can review diffs.
  • For maximum safety, run with --ask and/or --dry-run.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_code_fixer-0.3.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

auto_code_fixer-0.3.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file auto_code_fixer-0.3.2.tar.gz.

File metadata

  • Download URL: auto_code_fixer-0.3.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for auto_code_fixer-0.3.2.tar.gz
Algorithm Hash digest
SHA256 3df53d2ec28abd75f07a26e8b44927a52e761a7a85aabe950b5c16a7ae830a27
MD5 9607f3fced9f72617d5c2310765c14d4
BLAKE2b-256 cad6621e0e5641e8a61ce934185771378e35c6c055819e27d6d5f580de13cfe6

See more details on using hashes here.

File details

Details for the file auto_code_fixer-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for auto_code_fixer-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 faec266047e52bf16ca093f419794f8e6ea48e473d697ec54d348dd931ec1ded
MD5 20d891ea1b2ecd5e9daf5c5032e22001
BLAKE2b-256 cc5ec878551f577bb5b335fa381a47f714021e5aac1113b3b0ad85bc03d5a11b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page