{"id":51196843,"url":"https://github.com/albertas/deadcode","last_synced_at":"2026-06-27T21:08:06.358Z","repository":{"id":178363561,"uuid":"655400820","full_name":"albertas/deadcode","owner":"albertas","description":"Find and fix unused Python code using command line.","archived":false,"fork":false,"pushed_at":"2025-08-27T16:32:05.000Z","size":268,"stargazers_count":128,"open_issues_count":24,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-04T08:22:59.764Z","etag":null,"topics":["auto-fix","code-quality","deadcode","lithuanian","python","unused-code"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/albertas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-06-18T19:24:56.000Z","updated_at":"2025-09-29T03:40:53.000Z","dependencies_parsed_at":"2024-01-13T09:16:22.642Z","dependency_job_id":"cb933d79-6840-4851-afc7-6cafd90115ce","html_url":"https://github.com/albertas/deadcode","commit_stats":null,"previous_names":["albertas/deadcode"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/albertas/deadcode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertas%2Fdeadcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertas%2Fdeadcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertas%2Fdeadcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertas%2Fdeadcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/albertas","download_url":"https://codeload.github.com/albertas/deadcode/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertas%2Fdeadcode/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34867839,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-27T02:00:06.362Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto-fix","code-quality","deadcode","lithuanian","python","unused-code"],"created_at":"2026-06-27T21:08:05.624Z","updated_at":"2026-06-27T21:08:06.353Z","avatar_url":"https://github.com/albertas.png","language":"Python","funding_links":["https://ko-fi.com/V7V21681GD'"],"categories":[],"sub_categories":[],"readme":"[![Deadcode Logo](https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/deadcode-logo-readme.png)](https://deadcode.readthedocs.io/en/stable/)\n\n\u003ch2 align=\"center\"\u003eFind and Fix Unused Python Code\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/pre-commit/pre-commit\"\u003e\u003cimg src=\"https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\" alt=\"pre-commit\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/deadcode/\"\u003e\u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/deadcode\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pepy.tech/project/deadcode\"\u003e\u003cimg alt=\"Downloads\" src=\"https://static.pepy.tech/badge/deadcode\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/albertas/deadcode/blob/main/LICENSE\"\u003e\u003cimg alt=\"License: AGPLv3\" src=\"https://raw.githubusercontent.com/albertas/deadcode/main/docs/_static/AGPLv3-license.svg\"\u003e\u003c/a\u003e\n\u003cbr/\u003e\u003ca href='https://ko-fi.com/V7V21681GD' target='_blank'\u003e\u003cimg height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi3.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n## Installation\n```shell\npip install deadcode\n```\n\n## Usage\nTo see unused code findings:\n```shell\ndeadcode .\n```\n\nTo see suggested fixes for all files:\n```shell\ndeadcode . --fix --dry\n```\n\nTo see suggested fixes only for `foo.py` file:\n```shell\ndeadcode . --fix --dry --only foo.py\n```\n\nTo fix:\n```shell\ndeadcode . --fix\n```\n\nTune out some of the false positives, e.g.:\n```\ndeadcode . --exclude=venv,tests --ignore-names=BaseTestCase,*Mixin --ignore-names-in-files=migrations\n```\n\nThe same options can be provided in `pyproject.toml` settings file:\n```\n[tool.deadcode]\nexclude = [\"venv\", \"tests\"]\nignore-names = [\"BaseTestCase\", \"*Mixin\"]\nignore-names-in-files = [\"migrations\"]\n```\n\n## Pre-commit hook\nCreate a `.pre-commit-config.yaml` file in the root of your project directory, if it doesn't exist, and add the following to the file:\n\n```\n# See https://pre-commit.com for more information\n# See https://pre-commit.com/hooks.html for more hooks\nrepos:\n  - repo: https://github.com/albertas/deadcode\n    rev: 2.4.1\n    hooks:\n      - id: deadcode\n```\n\n## Command line options\n\n| Option\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; | Type | Meaning  |\n|-------------------------------------------|------|----------------------------------------------------------------------|\n|`--fix`                                    | -    | Automatically remove detected unused code expressions from the code base. |\n|`--dry`                                    | -    | Show changes which would be made in files. |\n|`--only`                                   | list | Filenames (or path expressions), that will be reflected in the output (and modified if needed). |\n|`--exclude`                                | list | Filenames (or path expressions), which will be completely skipped without being analysed. |\n|`--ignore-names`                           | list | Removes provided list of names from the output. Regexp expressions to match multiple names can also be provided, e.g. `*Mixin` will match all classes ending with `Mixin`. |\n|`--ignore-names-in-files`                  | list | Ignores unused names in files, which filenames match provided path expressions. |\n|`--ignore-names-if-inherits-from`          | list | Ignores names of classes, which inherit from provided class names. |\n|`--ignore-names-if-decorated-with`         | list | Ignores names of an expression, which is decorated with one of the provided decorator names. |\n|`--ignore-bodies-of`                       | list | Ignores body of an expression if its name matches any of the provided names. |\n|`--ignore-bodies-if-decorated-with`        | list | Ignores body of an expression if its decorated with one of the provided decorator names. |\n|`--ignore-bodies-if-inherits-from`         | list | Ignores body of a class if it inherits from any of the provided class names. |\n|`--ignore-definitions`                     | list | Ignores definition (including name and body) if a name of an expression matches any of the provided ones. |\n|`--ignore-definitions-if-inherits-from`    | list | Ignores definition (including name and body) of a class if it inherits from any of the provided class names. |\n|`--ignore-definitions-if-decorated-with`   | list | Ignores definition (including name and body) of an expression, which is decorated with any of the provided decorator names. |\n|`--no-color`                               | -    | Removes colors from the output. |\n|`--count`                                  | -    | Provides the count of the detected unused names instead of printing them all out. |\n|`--quiet`                                  | -    | Does not output anything. Makefile still fails with exit code 1 if unused names are found. |\n\n\n##### Glossory\n- `name` - variable, function or class name.\n- `body` - code block which follows after `:` in function or class definition.\n- `definition` - whole class or function definition expression including its name and body.\n\n\n## Rules\n| Code   | Name               | Message        |\n|--------|--------------------|----------------|\n| DC01  | unused-variable      | Variable `{name}` is never used\n| DC02  | unused-function      | Function `{name}` is never used\n| DC03  | unused-class         | Class `{name}` is never used\n| DC04  | unused-method        | Method `{name}` is never used\n| DC05  | unused-attribute     | Attribute `{name}` is never used\n| DC06  | unused-name          | Name `{name}` is never used\n| DC07  | unused-import        | Import `{name}` is never used\n| DC08  | unused-property      | Property `{name}` is never used\n| DC09  | unreachable-if-block | Unreachable conditional statement block\n| DC11  | empty-file           | Empty Python file\n| DC12  | commented-out-code   | Commented out code\n| DC13  | unreachable-code     | Code after terminal statement, e.g. `return`, `raise`, `continue`, `break`\n| DC    | ignore-expression    | Do not show any findings for an expression, which starts on current line (this code can only be used in `# noqa: DC` comments)\n\n## Ignoring checks with noqa comments\nInline `# noqa` comments can be used to ignore `deadcode` checks.\nE.g. unused `Foo` class wont be detected/fixed because `# noqa: DC03` comment is used:\n\n```python\nclass Foo:  # noqa: DC03\n    pass\n```\n\n## Contributing\n- `make check` - runs unit tests and other checks using virtual environment.\n\n## Rationale\n[ruff](https://pypi.org/project/ruff/) and\n[flake8](https://pypi.org/project/flake8/) - don't have rules for unused global\ncode detection, only for local ones `F823`, `F841`, `F842`. `deadcode` package\ntries to add new `DCXXX` checks for detecting variables/functions/classes/files\nwhich are not used in a whole code base.\n\n`deadcode` - is supposed to be used inline with other static code checkers like `ruff`.\n\nThere is an alternative [vulture](https://pypi.org/project/vulture/) package.\n\n## Known limitations\nIn case there are several definitions using the same name - they all wont be\nreported if at least one usage of that name is being detected.\n\nFiles with syntax errors will be ignored, because `deadcode` uses `ast` to\nbuild abstract syntax tree for name usage detection.\n\nIt is assumed that `deadcode` will be run using the same or higher Python version as the\ncode base is implemented in.\n\n## Feature requests\n- [x] Replace `.*` with only `*` in regexp matching.\n- [x] Add unused class method detection DC04 check.\n- [x] Add `--fix` option to automatically remove detected dead code occourencies\n- [x] Add a check for empty python files.\n- [x] Split error codes into DC01, DC02, DC03 for variables, functions, class.\n    - [x] Should have different codes for ignoring name and ignoring whole definition (reserved DCxx0 - ignore name, DCxx1 - ignore definition).\n    - [ ] Allow to disable each check separately using:\n        - [ ] inline comment.\n        - [ ] pyproject.toml file\n- [ ] Add a check for code in comments.\n- [ ] Add target python version option, if specified it will be used for code base check.\n- [ ] Add a `--depth` parameter to ignore nested code.. (To only check global scope use 0).\n- [ ] Add options:\n    - [x] --ignore-definitions\n    - [x] --ignore-definitions-if-inherits-from\n    - [ ] --ignore-definitions-if-decorated-with\n    - [ ] --ignore-names-if-inherits-from\n    - [ ] --ignore-names-if-decorated-with\n    - [ ] --ignore-bodies-of\n    - [ ] --ignore-bodies-if-decorated-with\n    - [ ] --ignore-bodies-if-inherits-from\n    - [ ] --ignore-definitions\n    - [ ] --ignore-definitions-if-inherits-from\n    - [ ] --ignore-definitions-if-decorated-with\n        - Question: would it be possible to ignore only certain types of checks for a body, e.g. only variable attributes of TypedDict and still check usage of methods and properties?\n        - What expression would allow this type of precission?\n- [ ] Distinguish between definitions with same name, but different files.\n- [ ] Repeated application of `deadcode` till the output stops changing.\n- [ ] Unreachable code detection and fixing: this should only be scoped for if statements and only limited to primitive variables.\n- [ ] Benchmarking performance with larger projects (time, CPU and memory consumption) in order to optimize.\n- [ ] `--fix` could accept a list of filenames as well (only those files would be changed, but the summary could would be full).\n    (This might be confusing, because filenames, which have to be considered are provided without any flag, --fix is expected to not accept arguments)\n- [ ] pre-commit-hook.\n- [ ] language server.\n- [ ] DC10: remove code after terminal statements like `raise`, `return`, `break`, `continue` and comes in the same scope.\n- [ ] Add `ignore` and `per-file-ignores` command line and pyproject.toml options, which allows to skip some rules.\n- [ ] Make sure that all rules are being skipped by `noqa` comment and all rules react to `noqa: rule_id` comments.\n- [ ] Include package names into code item scope (dot-separated path), e.g. \"package1.package2.module.class.method.variable\".\n- [ ] All options should be able to accept dot-separated path or a generic name, e.g. \"marshmallow.Schema\" vs \"Schema\",\n  documentation should cleary demonstrate the behaviour/example that \"Schema\" means \"*.Schema\".\n- [ ] Redefinition of an existing name makes previous name unreachable, unless it is assigned somehow.\n- [ ] Check if file is still valid/parsable after automatic fixing, if not: halt the change and report error.\n- [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.\n\n## Release notes\n- v2.4.1:\n    - Add `--version` option to show `deadcode` version.\n    - Use stdout for `deadcode` output.\n- v2.4.0:\n    - Add `--only` option that accepts filenames only which will be reflected in the output and modified.\n      This option can be used with `--fix` and `--fix --dry` options as well as for simple unused code detection without fixing.\n- v2.3.2:\n    - Add `pre-commit` hook support.\n    - Drop support for Python 3.8 and 3.9 versions, since their `ast` implementation is lacking features.\n- v2.3.1:\n    - Started analysing files in bytes instead of trying to convert them into UTF-8 encoded strings.\n    - Improved automatic removal of unused imports.\n- v2.3.0:\n    - Add `--dry` option.\n    - Update error codes to use DCXX format instead of DCXXX.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertas%2Fdeadcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbertas%2Fdeadcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertas%2Fdeadcode/lists"}