iamnotacoder is a powerful toolkit, fueled by Large Language Models (LLMs), that automates the process of improving and generating Python code. It's designed to be flexible, robust, and easy to integrate into your workflow. The suite includes:
scraper.py (The Finder 🔍): Discovers and filters Python repositories on GitHub based on your criteria (e.g., code quality, lines of code, update date).iamnotacoder.py (The Optimizer 🛠️): Your primary tool for enhancing existing Python code within GitHub repositories. It combines static analysis, LLM-powered refactoring, automated testing, and seamless GitHub integration (including safe forking).process.py (The Orchestrator ⚙️): Automates the execution of iamnotacoder.py on multiple repositories identified by scraper.py.Bonus
* create_app_from_scratch.py (The Team 🏗️): A code generation tool that builds basic Python applications from natural language descriptions. It leverages a team of specialized LLM "actors" to handle different development tasks. Can be useful to prototype apps.
This README focuses primarily on iamnotacoder.py (the optimizer) and provides an overview of create_app_from_scratch.py (the creator).
iamnotacoder.py: The Code Optimizer 🛠️
scraper.py and process.py: The Finder and Orchestrator 🔍⚙️
iamnotacoder.py: The Code Optimizer 🛠️iamnotacoder.py is your go-to tool for automatically improving the quality of existing Python code. It's designed to be a comprehensive solution for:
pytest.rich library.Clone the Repository:
bash
git clone <your_iamnotacoder_repo_url>
cd iamnotacoder
Install Dependencies:
bash
pip install -r requirements.txt
pip install black isort pylint flake8 mypy pytest pytest-cov # Static analysis & testing tools
Your requirements.txt should include at least:
click
openai
toml
GitPython
rich
PyGithub
requests
Basic Command Structure:
python iamnotacoder.py --repo <repository_url> --files <file_paths> --branch <target_branch> --token <github_token> [options]
Required Arguments:
--repo (-r): 🐙 The URL of the GitHub repository (e.g., https://github.com/user/repo).--files (-f): 📄 Comma-separated paths to the Python files you want to improve (e.g., src/module1.py,src/module2.py).--branch (-b): 🌿 The target branch in the repository (e.g., main, develop).--token (-t): 🔑 Your GitHub Personal Access Token (PAT) with the repo scope.Common Options:
--config (-c): ⚙️ Path to a TOML configuration file.--tools (-T): 🛠️ Comma-separated list of static analysis tools to use (default: black,isort,pylint,flake8,mypy).--exclude-tools (-e): ❌ Comma-separated list of tools to exclude.--llm-model (-m): 🧠 The LLM model to use (default: qwen2.5-coder-14b-instruct-mlx). Supports both OpenAI and local LLM models.--llm-temperature (-temp): 🔥 The temperature for the LLM (default: 0.2). Higher values increase randomness.--llm-custom-prompt (-p): 📝 Path to a directory containing your custom prompt files (e.g., prompt_style.txt).--min-coverage (-c): 📊 Minimum code coverage threshold (as a percentage).--no-dynamic-analysis: 🚫 Disable test generation and execution.--dry-run: 👀 Perform a dry run without making any actual changes (no commits, pushes, or pull requests).--local-commit: 💾 Only commit changes locally, don't create a pull request.--openai-api-base: 🌐 Base URL for local LLMs (e.g., http://localhost:1234/v1 for LM Studio).--categories (-C): 🏷️ Comma-separated list of improvement categories (default: style,maintenance,security,performance).--output-file (-o): 💾 Path to save the modified file. Defaults to overwriting the original file.--output-info: 📝 Path to save the text report (default: report.txt).--fork-repo: 🍴 Automatically fork the repository to your account before making changes.--fork-user: 👤 Your GitHub username (if forking and your username cannot be inferred from the token).--line-length: 📏 Maximum line length for code formatting (default: 79).--debug: 🐛 Prints verbose logs for troubleshooting.--force-push: 💪 Force push the branch if it exists on remote.config.toml - Example)openai_api_key = "none" # Set to "none" when using a local LLM
openai_api_base = "http://localhost:1234/v1" # For LM Studio, if applicable
llm_model = "qwen2.5-coder-14b-instruct-mlx"
llm_temperature = 0.2
tools = "black,isort,pylint,flake8"
min_coverage = 80
coverage_fail_action = "warn"
To customize the LLM's behavior, create a directory (default: .) and place text files named prompt_<category>.txt within it. Use {code} as a placeholder for the code to be improved, and {file_base_name} for the file base name.
Example (prompt_style.txt):
You are a coding assistant tasked with improving the style of the following Python code.
Focus on PEP 8 compliance, readability, and clarity. Return only the improved code,
without any introductory or concluding text. Do not include markdown code fences.
{code}
Example (prompt_tests.txt):
You are a coding assistant tasked with writing test for the following Python code.
Focus on readability, and clarity. Return only the test code,
without any introductory or concluding text. Do not include markdown code fences.
Write test for {file_base_name}.py file:
{code}
Basic Usage (with a configuration file):
bash
python iamnotacoder.py -r https://github.com/user/repo -f src/my_module.py -b main -t YOUR_GITHUB_TOKEN -c config.toml
Dry Run with Debug Logging:
bash
python iamnotacoder.py -r https://github.com/user/repo -f src/my_module.py -b main -t YOUR_GITHUB_TOKEN --dry-run --debug
Using a Local LLM with LM Studio:
bash
python iamnotacoder.py -r https://github.com/user/repo -f src/my_module.py -b main -t YOUR_GITHUB_TOKEN --openai-api-base http://localhost:1234/v1 --llm-model qwen2.5-coder-14b-instruct-mlx
(and set openai_api_key = "none" in config.toml)
Forking and Automatically Generating Tests:
bash
python iamnotacoder.py -r https://github.com/user/repo -f src/my_module.py -b main -t YOUR_GITHUB_TOKEN --fork-repo --fork-user yourusername
Running on Multiple Files and exclude mypy tool:
bash
python iamnotacoder.py --repo https://github.com/user/repo --files "src/module1.py,src/module2.py,tests/test_module1.py" --branch development --token YOUR_GITHUB_TOKEN --exclude-tools mypy --fork-repo
--cache-dir is specified).--no-dynamic-analysis is not set), tests are generated using the LLM. Syntax errors are automatically corrected.--min-coverage is specified.--fork-repo is used).report.txt or as specified by --output-info) and a JSON log file are generated.--debug is enabled).Example
```python
export OPENAI_API_KEY=none export OPENAI_API_BASE=http://localhost:1234/v1
python3 iamnotacoder.py --repo https://github.com/fabriziosalmi/testrepo --files script2.py -b main -t $GITHUB_TOKEN --config config.toml --fork-repo
Forking repository to user: fabriziosalmi
Forked repository to: https://github.com/fabriziosalmi/testrepo.git
Cloning repository (shallow): https://github.com/fabriziosalmi/testrepo.git
Repository cloned to: /var/folders/h8/6y19287n1sx6t9r4nmxwmpgw0000gn/T/tmp74ks4vg9 in 0.63 seconds
Creating branch: improvement-script2_py-code_improvements-20250218-080049-b68c5b8f
Created branch: improvement-script2_py-code_improvements-20250218-080049-b68c5b8f in 0.02 seconds
Checking out branch: main
Checked out branch: main in 0.40 seconds
Checking out branch: improvement-script2_py-code_improvements-20250218-080049-b68c5b8f
Checked out branch: improvement-script2_py-code_improvements-20250218-080049-b68c5b8f in 0.41 seconds
Running static analysis...
⣽ Running analysis... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Running black 0:00:00
⢿ Running analysis... ━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━ Running pylint 0:00:00
Test generation phase...
LLM test generation request took 17.47 seconds.
Test file written to: /var/folders/h8/6y19287n1sx6t9r4nmxwmpgw0000gn/T/t
$ claude mcp add iamnotacoder \
-- python -m otcore.mcp_server <graph>