Codeflash
raw JSON → 0.20.5 verified Mon Apr 27 auth: no python
Codeflash is an AI-powered tool that automatically optimizes Python code for performance. It analyzes code, runs test suites, and generates performance improvements with minimal user intervention. Current version: 0.20.5, active development with weekly releases.
pip install codeflash Common errors
error ModuleNotFoundError: No module named 'codeflash' ↓
cause Codeflash not installed or installed in wrong environment.
fix
Run
pip install codeflash in the correct Python environment (e.g., virtualenv). error RunCodeflashError: Authentication failed. Please set CODEFLASH_API_KEY. ↓
cause API key not provided.
fix
Set environment variable
CODEFLASH_API_KEY with your API key from https://app.codeflash.ai. error ValueError: Function must have type hints ↓
cause Codeflash requires functions to have type annotations.
fix
Add type hints to the function parameters and return value.
error UnsupportedPythonVersionError: Python 3.8 is not supported ↓
cause Codeflash requires Python >=3.9.
fix
Upgrade Python to version 3.9 or later.
Warnings
breaking In v0.17.0, the API changed from `codeflash.optimize` to `codeflash.run_codeflash`. Old code using `import codeflash.optimize` will break. ↓
fix Update imports to `from codeflash import run_codeflash`.
gotcha Codeflash requires an API key set via `CODEFLASH_API_KEY` environment variable. Without it, `run_codeflash` raises an authentication error. ↓
fix Set `CODEFLASH_API_KEY` in your environment or pass `api_key` parameter.
deprecated The `verbose` parameter in `run_codeflash` is deprecated since v0.19.0 and will be removed in v0.21.0. Use `logging` level instead. ↓
fix Remove `verbose` parameter and configure Python logging: `logging.basicConfig(level=logging.INFO)`.
gotcha Codeflash only supports Python 3.9 and above. Installing on older Python versions will fail with a `Requires-Python` error. ↓
fix Ensure Python >=3.9 is used.
Imports
- run_codeflash
from codeflash import run_codeflash - CodeOptimizer wrong
from codeflash.optimizer import CodeOptimizercorrectfrom codeflash import CodeOptimizer
Quickstart
from codeflash import run_codeflash
# Example: optimize a simple function
def slow_function(n: int) -> int:
total = 0
for i in range(n):
total += i
return total
# Run codeflash optimization (requires CODEFLASH_API_KEY env var)
optimized_code = run_codeflash(slow_function, api_key=os.environ.get('CODEFLASH_API_KEY', ''))
print(optimized_code)