{"id":21054,"library":"codeflash","title":"Codeflash","description":"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.","status":"active","version":"0.20.5","language":"python","source_language":"en","source_url":"https://github.com/codeflash-ai/codeflash","tags":["performance","optimization","AI","code-generation","linter-alternative"],"install":[{"cmd":"pip install codeflash","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"","wrong":"","symbol":"run_codeflash","correct":"from codeflash import run_codeflash"},{"note":"CodeOptimizer is directly exposed in the top-level module as of 0.20.x","wrong":"from codeflash.optimizer import CodeOptimizer","symbol":"CodeOptimizer","correct":"from codeflash import CodeOptimizer"}],"quickstart":{"code":"from codeflash import run_codeflash\n\n# Example: optimize a simple function\ndef slow_function(n: int) -> int:\n    total = 0\n    for i in range(n):\n        total += i\n    return total\n\n# Run codeflash optimization (requires CODEFLASH_API_KEY env var)\noptimized_code = run_codeflash(slow_function, api_key=os.environ.get('CODEFLASH_API_KEY', ''))\nprint(optimized_code)","lang":"python","description":"Initialize Codeflash with API key and optimize a function."},"warnings":[{"fix":"Update imports to `from codeflash import run_codeflash`.","message":"In v0.17.0, the API changed from `codeflash.optimize` to `codeflash.run_codeflash`. Old code using `import codeflash.optimize` will break.","severity":"breaking","affected_versions":"<0.17.0"},{"fix":"Set `CODEFLASH_API_KEY` in your environment or pass `api_key` parameter.","message":"Codeflash requires an API key set via `CODEFLASH_API_KEY` environment variable. Without it, `run_codeflash` raises an authentication error.","severity":"gotcha","affected_versions":"all"},{"fix":"Remove `verbose` parameter and configure Python logging: `logging.basicConfig(level=logging.INFO)`.","message":"The `verbose` parameter in `run_codeflash` is deprecated since v0.19.0 and will be removed in v0.21.0. Use `logging` level instead.","severity":"deprecated","affected_versions":">=0.19.0, <0.21.0"},{"fix":"Ensure Python >=3.9 is used.","message":"Codeflash only supports Python 3.9 and above. Installing on older Python versions will fail with a `Requires-Python` error.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `pip install codeflash` in the correct Python environment (e.g., virtualenv).","cause":"Codeflash not installed or installed in wrong environment.","error":"ModuleNotFoundError: No module named 'codeflash'"},{"fix":"Set environment variable `CODEFLASH_API_KEY` with your API key from https://app.codeflash.ai.","cause":"API key not provided.","error":"RunCodeflashError: Authentication failed. Please set CODEFLASH_API_KEY."},{"fix":"Add type hints to the function parameters and return value.","cause":"Codeflash requires functions to have type annotations.","error":"ValueError: Function must have type hints"},{"fix":"Upgrade Python to version 3.9 or later.","cause":"Codeflash requires Python >=3.9.","error":"UnsupportedPythonVersionError: Python 3.8 is not supported"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}