Prerequisites
Before installing Codeflash, ensure you have:- Python 3.9 or above installed
- A Python project with a virtual environment
- Project dependencies installed in your virtual environment
- Unit Tests that Codeflash uses to ensure correctness of the optimizations
Virtual Environment RequiredAlways install Codeflash in your project’s virtual environment, not globally. Make sure your virtual environment is activated before proceeding.
1
Install Codeflash
You can install Codeflash locally for a project by running the following command in the project’s virtual environment:
Codeflash is a Development DependencyWe recommend installing Codeflash as a development dependency.
Codeflash is intended to be used in development workflows locally and as part of CI.
Try to always use the latest version of Codeflash as it improves quickly.
2
Generate a Codeflash API Key
Codeflash uses cloud-hosted AI models and integrations with GitHub. You’ll need an API key to authorize your access.
- Visit the Codeflash Web App
- Sign up with your GitHub account (free)
- Navigate to the API Key page to generate your API key
Free Tier AvailableCodeflash offers a free tier with a limited number of optimizations. Perfect for trying it out on small projects!
3
Run Automatic Configuration
Navigate to your project’s root directory (where your If you don’t have a pyproject.toml file yet, the codeflash init command will ask you to create oneWhen running
pyproject.toml
file is or should be) and run:What’s pyproject.toml?
pyproject.toml
is a configuration file that is used to specify build and tool settings for Python projects.
pyproject.toml
is the modern replacement for setup.py and requirements.txt files.codeflash init
, you will see the following prompts:pyproject.toml
file.
To understand the configuration options, and set more advanced options, see the Manual Configuration page.
Step 4: Install the Codeflash GitHub App
Finally, if you have not done so already, Codeflash will ask you to install the GitHub App in your repository. The Codeflash GitHub App allows access to your repository to the codeflash-ai bot to open PRs, review code, and provide optimization suggestions. Please install the Codeflash GitHub app by choosing the repository you want to install Codeflash on.Try It Out!
Once configured, you can start optimizing your code immediately:
Troubleshooting
📦 Module not found errors
📦 Module not found errors
Make sure:
- ✅ Your virtual environment is activated
- ✅ All project dependencies are installed
🧪 No optimizations found or debugging issues
🧪 No optimizations found or debugging issues
Do know that not all functions can be optimized as no optimization opportunities may exist for them. This is fine and expected.To investigate further, use the This will show:
--verbose
flag for detailed output:- 🔍 Which functions are being analyzed
- 🚫 Why certain functions were skipped
- ⚠️ Detailed error messages
- 📊 Performance analysis results
🔍 No tests found errors
🔍 No tests found errors
Verify:
- 📁 Your test directory path is correct in
pyproject.toml
- 🔍 Tests are discoverable by your test framework
- 📝 Test files follow naming conventions (
test_*.py
for pytest)
Next Steps
- Learn about Codeflash Concepts
- Explore Optimization workflows
- Set up Pull Request Optimization
- Read configuration options for advanced setups