Unref finds Python definitions that no project entry point reaches. Written in Rust using Ruff’s parser, it targets developers who want unused-code checks in local development and continuous integration. Its November 18 release, v0.3.0, adds Celery rules, recognizes Django migration attributes, and expands Flask handling.

  • Run it: With uv installed, run uvx unref==0.3.0 from the project directory. It reports file locations and unused functions, classes, or variables. Pre-commit and prek hooks are also supported.
  • How it decides: It follows references from top-level code, declared package entry points, recognized framework callbacks, and names listed in __all__. An unused function calling another unused function does not make either reachable.
  • Configure it: Add [tool.unref] to pyproject.toml. The used-names and used-decorators settings preserve dynamically discovered APIs and callbacks. Overrides can apply rules only to selected paths or base classes.
  • Framework support: Built-in rules cover pytest, Pydantic, SQLAlchemy, FastAPI, Flask, Django, and others. They account for definitions that frameworks call without a normal reference in application code.
  • Access and cost: The code is MIT-licensed, with downloadable wheels for Linux, macOS, and Windows. It runs locally without a paid service account.

A library needs special care: callers outside the repository are invisible to this check. The FAQ recommends declaring the public API through __all__ or used-names. Review findings before deleting code or making the check block merges.

Hacker News discussion

The HN thread shows why framework support matters. Commenters reported Django settings and server entry points being marked unused; another reported many false positives in Flask. The submitter acknowledged both gaps. Subsequent release notes document Django support in 0.2.2 and further Flask and migration rules in 0.3.0. Those fixes address the reported patterns, but do not establish accuracy across framework-heavy projects.

The submitter also clarified that the advertised sub-second CPython scan covers its Python files, not its C implementation. That is a project benchmark, not an independently reproduced result.

Caveat: This capture is based on the release notes, documentation, and discussion; framework accuracy and performance have not been tested here.