Clean up Python tool caches

.pytest_cache.mypy_cache.ruff_cachenext topyproject.tomlsetup.pyrequirements.txt

Quick answer

Yes, .pytest_cache, .mypy_cache and .ruff_cache are safe to delete. pytest, mypy and Ruff rebuild them on their next run. Virtual environments (.venv) are not caches; keep them.

Rebuild with Run pytest, mypy or ruff again

What is it?

Each tool keeps a per-project cache: pytest stores last-failed test data, mypy stores incremental type-checking results, and Ruff caches lint results.

Why does it get so big?

  • .mypy_cache stores type information for your code and its dependencies
  • Caches for every Python version you've checked against
  • Large monorepos multiply all of the above

How to clean it from the command line

pytest --cache-clear
ruff clean
rm -rf .mypy_cache

Review what a command matches before you run anything with rm -rf. These deletions are permanent.

What not to delete

  • .venv, venv and conda environments
  • pyproject.toml, requirements.txt and lockfiles
  • Your global pip cache, unless you mean to purge it

How Gigaflush handles Python

Gigaflush lists .pytest_cache and .mypy_cache and .ruff_cache only when one of pyproject.toml, setup.py, requirements.txt sits right beside it, shows each folder's size, preselects nothing, and re-checks the folder immediately before deleting it. Symlinks and parent-directory paths are refused.

FAQ

Is it safe to delete .mypy_cache?

Yes. mypy recreates it; the first run afterwards is slower.

Can I delete .pytest_cache?

Yes. You lose the last-failed history used by --lf until tests run again.

Should I delete __pycache__?

You can; Python regenerates bytecode on import. It's usually small, so Gigaflush leaves it alone.

Further reading