Unref - Python dead code finder built on Ruff's parser
Show HN: Unref – A Python dead code finder built on Ruff's parser

Unref is an open-source static analysis tool that hunts down unreferenced Python code, helping developers clean up dead functions, unused classes, and stale imports before they bloat a codebase. Built on Ruff's fast parser, it delivers quick, accurate results across modern Python versions, including support for Python 3.15 syntax. Whether you're maintaining a large legacy project or keeping a fresh repo tidy, Unref integrates into CI workflows and benchmarks its speed against other dead code finders, making codebase hygiene a painless part of your routine.
Find unreferenced Python code — Unref turns dead code cleanup into a fast, automated part of your workflow.
- tomtom1337
What is the definition of dead code that Unref uses? I distinguish between apps and libraries. In apps I can see how any code not callable from the entrypoint is dead, and for libraries I guess a definition is any code that is not callable from a public api?
Would be nice to see the definition used placed in the docs/github readme.
- selcuka
Cool project. I think false positives are more important than the dead code it misses at this stage. For example, it marks all Django settings as unused variables, probably because settings are typically not imported directly in Django projects. For example:
from django.conf import settings
...
if settings.DEBUG:
...
Currently unref thinks that DEBUG is not used.
Similarly, the `application` variable in asgi.py (or wsgi.py) is passed as an argument to the ASGI/WSGI server executable, but that is also marked as unused.
- athoscouto
I've been trying to do something like this internally too. Also started with Python, then moved onto ruff. My goal is a bit broader though. I want to use the dependency graph to detect changed parts of the project to selectively trigger image builds and run tests.
Results are still poor, specially on the tests side. So far the main learning has been that a tidy codebase (dep graph) is essential for it to work properly.
I'm surprised I didn't find more open source tooling tackling this effectively.