Codeflash is installed and configured on a per-project basis.

Prerequisites

Before installing Codeflash, ensure you have:
  1. Python 3.9 or above installed
  2. A Python project with a virtual environment
  3. Project dependencies installed in your virtual environment
Good to have (optional):
  1. 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.
source venv/bin/activate  # On Linux/Mac
# or
venv\Scripts\activate     # On Windows
1

Install Codeflash

You can install Codeflash locally for a project by running the following command in the projectโ€™s virtual environment:
pip install codeflash
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.
uv add --dev codeflash
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.
  1. Visit the Codeflash Web App
  2. Sign up with your GitHub account (free)
  3. 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 pyproject.toml file is or should be) and run:
codeflash init
If you donโ€™t have a pyproject.toml file yet, the codeflash init command will ask you to create one
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.
When running codeflash init, you will see the following prompts:
1. Enter your Codeflash API key:
2. Install the GitHub app.
3. Which Python module do you want me to optimize going forward? (e.g. my_module)
4. Where are your tests located? (e.g. tests/)
5. Which test framework do you use? (pytest/unittest)
6. Install GitHub actions for Continuous optimization?
After you have answered these questions, the Codeflash configuration will be saved in the 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:
# Optimize a specific function
codeflash --file path/to/your/file.py --function function_name

# Or optimize all functions in your codebase
codeflash --all

Troubleshooting

Next Steps