A CLI tool that generates Python programs using the OpenAI API, saves the generated code to a file, runs it automatically, and retries up to 5 times if the generated code fails.
This project is based on "a Python program that writes Python programs”.
- Asks the user what Python program to generate (or picks a random idea from a list).
- Calls the OpenAI Chat Completions API to generate Python code only.
- Requires the generated code to include assert-based unit tests (at least 5 test cases).
- Writes the generated code into
code_generate.py. - Runs
code_generate.pyviasubprocess.run. - If errors happen, it feeds the error back into the next prompt and retries up to 5 times.
- On success, formats the file with Black and opens the generated file automatically (Windows).
It also includes:
- Console colors via Colorama
- Auto-formatting via Black
superpythoncoder.py— the main programrequirements.txt— dependencies.env.example— environment variables template.env— your local secret keyprogrammer.ico— icon used for.exefile
- Python 3.10+ recommended
- An OpenAI API key (
OPENAI_API_KEY)
git clone https://github.com/dorhaboosha/Program-Generator.git
cd Program-Generator
Windows (PowerShell)
python -m venv .venv
.\.venv\Scripts\Activate.ps1
Windows (CMD)
python -m venv .venv
.venv\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txt
Create a file named .env next to superpythoncoder.py and add:
OPENAI_API_KEY=your_key_here
python superpythoncoder.py
If generation succeeds, you’ll see:
- A printed success message
- A new file:
code_generate.py - The generated file opens automatically (Windows)
If generation fails, you’ll see:
- Errors printed to the console
- Up to 5 retries
- Final message:
Code generation FAILED after 5 attempts.
A pre-built Windows EXE is available in the GitHub Releases section, so you can run the app without installing Python.
- Download the latest release
.zip - Extract it
- Put a
.envfile in the same folder as the.exeOPENAI_API_KEY=your_key_here - Run the executable (double-click)
The
.envfile must be next to the.exeso the program can load it.
This app executes AI-generated Python code on your machine. Only run it in an environment you trust.