{"id":9649,"library":"deadcode","title":"Dead Code Finder","description":"The `deadcode` library is a static analysis tool for Python that identifies unused functions, classes, and variables within a codebase. It helps developers clean up projects by pinpointing code that is no longer reachable or imported. As of version 2.4.1, it focuses on providing a robust CLI experience with programmatic API access. The project maintains an active development cycle, with major releases incorporating significant refactors and minor releases for bug fixes and feature enhancements.","status":"active","version":"2.4.1","language":"python","source_language":"en","source_url":"https://github.com/deadcode-io/deadcode","tags":["code analysis","static analysis","dead code","linting","code quality"],"install":[{"cmd":"pip install deadcode","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Logging functionality","package":"loguru"},{"reason":"Building the command-line interface","package":"typer[all]"},{"reason":"Rich terminal output","package":"rich"},{"reason":"Data validation and settings management","package":"pydantic"},{"reason":"YAML configuration parsing","package":"pyyaml"},{"reason":"TOML configuration parsing","package":"toml"},{"reason":"Code complexity and analysis","package":"radon"},{"reason":"Git repository interaction (e.g., ignoring untracked files)","package":"dulwich"}],"imports":[{"wrong":"from deadcode.finder import find_dead_code","symbol":"importlib","correct":"from deadcode import importlib"}],"quickstart":{"code":"import subprocess\nimport json\nimport tempfile\nfrom pathlib import Path\nimport shutil\n\n# Create a temporary directory to simulate a project\ntemp_dir = Path(tempfile.mkdtemp())\n\n# Create dummy Python files within the temporary project\n# my_module.py contains an unused function\n(temp_dir / \"my_module.py\").write_text(\"\"\"\ndef used_func():\n    return \"hello\"\n\ndef unused_func():\n    return \"world\"\n\"\"\")\n\n# main.py imports and uses 'used_func', leaving 'unused_func' dead\n(temp_dir / \"main.py\").write_text(\"\"\"\nfrom my_module import used_func\nprint(used_func())\n\"\"\")\n\n# Define the output report file path\noutput_file = temp_dir / \"deadcode_report.json\"\n\ntry:\n    print(f\"Scanning directory: {temp_dir}\")\n    # Run the deadcode CLI tool\n    result = subprocess.run(\n        [\"deadcode\", \"--path\", str(temp_dir), \"--output\", str(output_file)],\n        capture_output=True,\n        text=True,\n        check=True # Will raise CalledProcessError if command fails\n    )\n\n    print(\"\\n--- CLI STDOUT ---\")\n    print(result.stdout)\n    if result.stderr:\n        print(\"\\n--- CLI STDERR ---\")\n        print(result.stderr)\n\n    # Check if the report file was generated and print its content\n    if output_file.exists():\n        with open(output_file, 'r') as f:\n            report = json.load(f)\n        print(\"\\n--- DEAD CODE REPORT ---\")\n        print(json.dumps(report, indent=2))\n    else:\n        print(\"\\nNo dead code report file generated.\")\n\nexcept subprocess.CalledProcessError as e:\n    print(f\"\\nERROR: deadcode command failed with exit code {e.returncode}\")\n    print(f\"Stdout: {e.stdout}\")\n    print(f\"Stderr: {e.stderr}\")\nexcept FileNotFoundError:\n    print(\"\\nERROR: 'deadcode' command not found. Please ensure the 'deadcode' package is installed and its executable is in your system's PATH.\")\nfinally:\n    # Clean up the temporary directory and its contents\n    if temp_dir.exists():\n        print(f\"\\nCleaning up temporary directory: {temp_dir}\")\n        shutil.rmtree(temp_dir)\n","lang":"python","description":"This quickstart demonstrates how to use the `deadcode` command-line interface (CLI) to scan a temporary Python project for unused code. It creates two dummy Python files, one with a dead function, then executes `deadcode` and prints its output and the generated JSON report. This illustrates the typical workflow of using `deadcode` on a project."},"warnings":[{"fix":"Review the official changelog and documentation for 2.x versions. The configuration file was changed from `pyproject.toml` (for `[tool.deadcode]`) to a dedicated `deadcode.toml`.","message":"Version 2.0.0 introduced significant breaking changes, including a major refactor of the internal parsing logic, CLI arguments, and configuration. If upgrading from pre-2.0.0 versions, direct code and config might break.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Replace usage of `--exclude-dirs` with `--exclude-patterns` in CLI calls, or update programmatic calls to use `config.exclude_patterns` for directory exclusion (e.g., `['**/tests/', '**/docs/']`).","message":"The `exclude_dirs` argument was removed from both the CLI and programmatic `find_dead_code` function in version 2.0.0. Its functionality has been merged into `exclude_patterns`.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Carefully review the reports. Use the `--exclude-patterns` option in `deadcode.toml` or via CLI arguments to fine-tune analysis for specific project structures, dynamically generated files, or known false positives.","message":"Static analysis tools like `deadcode` may produce false positives or negatives, especially with highly dynamic code, complex import mechanisms (e.g., `__import__`, `importlib`), or when code is generated at runtime.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"search_vec":"'2.4.1':43 'access':55 'activ':60 'analysi':10,79,81 'api':54 'bug':73 'class':18 'clean':27 'cli':50 'code':2,32,78,83,85 'codebas':23 'cycl':62 'dead':1,82 'deadcod':5 'develop':26,61 'enhanc':77 'experi':51 'featur':76 'finder':3 'fix':74 'focus':45 'function':17 'help':25 'identifi':15 'import':39 'incorpor':66 'librari':6 'lint':84 'longer':36 'maintain':58 'major':64 'minor':70 'pinpoint':31 'programmat':53 'project':29,57 'provid':47 'python':13 'qualiti':86 'reachabl':37 'refactor':68 'releas':65,71 'robust':49 'signific':67 'static':9,80 'tool':11 'unus':16 'variabl':20 'version':42 'within':21","created_at":"2026-04-17T01:20:00.114669+00:00","updated_at":"2026-04-17T01:20:00.114669+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.4.1","cli_name":"deadcode","cli_version":"2.4.1","type":"library","homepage":null,"github":"https://github.com/albertas/deadcode","docs":"https://deadcode.readthedocs.io/","changelog":null,"pypi":"https://pypi.org/project/deadcode/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":null}}