Skip to main content

ds-cache-cleaner

Clean up cached data from ML/data science libraries.

Supported Caches

  • HuggingFace Models - ~/.cache/huggingface/hub (models)
  • HuggingFace Datasets (Hub) - ~/.cache/huggingface/hub (datasets)
  • Transformers - ~/.cache/huggingface/transformers
  • HF Datasets - ~/.cache/huggingface/datasets
  • ir_datasets - ~/.ir_datasets
  • datamaestro (cache) - ~/datamaestro/cache (partial downloads, processing)
  • datamaestro (data) - ~/datamaestro/data (downloaded datasets)

Installation

pip install ds-cache-cleaner

Or with uv:

uv pip install ds-cache-cleaner

Usage

List caches

ds-cache-cleaner list

Show cache entries

ds-cache-cleaner show
ds-cache-cleaner show -c "HuggingFace Hub"

Clean caches

# Interactive mode
ds-cache-cleaner clean

# Clean specific cache
ds-cache-cleaner clean -c "HuggingFace Hub"

# Clean all without prompting
ds-cache-cleaner clean --all

# Dry run
ds-cache-cleaner clean --dry-run

Interactive TUI

ds-cache-cleaner tui

Library Integration

ML libraries can integrate with ds-cache-cleaner to provide rich metadata about their cached data. This enables better descriptions, accurate last-access times, and custom library-specific metadata.

Metadata Format

The metadata is stored in a ds-cache-cleaner/ folder inside each cache directory:

~/.cache/mylib/
├── ds-cache-cleaner/
│   ├── lock                    # Lock file for concurrent access
│   ├── information.json        # Cache info and parts list
│   └── part_models.json        # Entries for "models" part
└── ... (actual cache data)

Using the CacheRegistry API

from ds_cache_cleaner import CacheRegistry

# Initialize once for your library
registry = CacheRegistry(
    cache_path="~/.cache/mylib",
    library="mylib",
    description="My ML Library cache",
)

# Register a part (e.g., models, datasets)
registry.register_part("models", "Downloaded model weights")

# When downloading a new model
registry.register_entry(
    part="models",
    path="bert-base",  # relative path within cache
    description="BERT base model",
    size=438_000_000,
)

# When accessing an existing entry (updates last_access time)
registry.touch("models", "bert-base")

# When deleting an entry (removes from metadata)
registry.remove("models", "bert-base")

Custom Metadata

You can store library-specific metadata using the metadata parameter:

# Store custom metadata when registering an entry
registry.register_entry(
    part="models",
    path="bert-base-uncased",
    description="BERT base uncased model",
    size=438_000_000,
    metadata={
        "model_type": "bert",
        "revision": "main",
        "tags": ["encoder", "uncased", "english"],
        "framework": "pytorch",
    },
)

# Retrieve entry with its metadata
entry = registry.get_entry("models", "bert-base-uncased")
if entry:
    print(entry.metadata)  # {"model_type": "bert", ...}

Full API Reference

CacheRegistry

Method Description
register_part(name, description="") Register a new part (e.g., "models", "datasets")
register_entry(part, path, description="", size=None, metadata=None) Register or update a cache entry
touch(part, path) Update last access time for an entry
remove(part, path) -> bool Remove entry from metadata (returns True if found)
update_size(part, path, size) Update the size of an entry
get_entry(part, path) -> EntryMetadata | None Get metadata for a specific entry
list_entries(part) -> list[EntryMetadata] List all entries in a part
list_parts() -> list[PartInfo] List all parts in the cache
parts.<name> Access a part via attribute notation (see below)

Parts Accessor

The parts property provides a convenient attribute-style API:

# Instead of:
registry.register_entry("models", entry)
registry.get_entry("models", "bert")
registry.list_entries("models")

# You can use:
registry.parts.models.register(entry)
registry.parts.models.get("bert")
registry.parts.models.list()

PartAccessor methods:

Method Description
register(path, ...) Register an entry (same args as register_entry)
get(path) Get an entry by path
get_entry(path) Alias for get()
list() List all entries
touch(path) Update last access time
remove(path) Remove an entry
update_size(path, size) Update entry size

Data Classes

The metadata system uses standard Python dataclasses with pydantic validation:

from ds_cache_cleaner import EntryMetadata, PartInfo

# EntryMetadata fields
@dataclass
class EntryMetadata:
    path: str                           # Relative path within cache (required)
    description: str = ""               # Human-readable description
    created: datetime | None = None     # When the entry was created
    last_access: datetime | None = None # Last access time
    size: int | None = None             # Size in bytes
    metadata: dict[str, Any] = {}       # Library-specific metadata

# PartInfo fields
@dataclass
class PartInfo:
    name: str          # Part name (e.g., "models")
    description: str = ""  # Human-readable description

Custom Entry Classes

For type-safe entries, subclass EntryMetadata with your own fields. Extra fields are automatically serialized into the metadata dict and reconstructed on read:

from dataclasses import dataclass, field
from ds_cache_cleaner import CacheRegistry, EntryMetadata

@dataclass
class ModelEntry(EntryMetadata):
    """Custom entry for ML models."""
    model_type: str = ""
    revision: str = ""
    tags: list[str] = field(default_factory=list)

# Create registry with custom entry type
registry = CacheRegistry(
    cache_path="~/.cache/mylib",
    library="mylib",
    entry_types={"models": ModelEntry},  # Map part name to entry type
)

registry.register_part("models", "Model weights")

# Register using custom entry instance
entry = ModelEntry(
    path="bert-base",
    description="BERT model",
    model_type="bert",
    revision="v1.0",
    tags=["encoder", "english"],
)
registry.register_entry("models", entry)

# Get entry returns the correct type
model = registry.get_entry("models", "bert-base")
assert isinstance(model, ModelEntry)
print(model.model_type)  # "bert"
print(model.tags)        # ["encoder", "english"]

# List entries also returns custom types
for entry in registry.list_entries("models"):
    print(f"{entry.path}: {entry.model_type}")

The JSON format remains backward compatible - extra fields are stored in the metadata dict:

{
  "path": "bert-base",
  "description": "BERT model",
  "metadata": {
    "model_type": "bert",
    "revision": "v1.0",
    "tags": ["encoder", "english"]
  }
}

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
hatch run test

# Lint
hatch run lint:check

# Format
hatch run lint:fix

License

MIT

Metadata

Release files for ds-cache-cleaner 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ds-cache-cleaner 0.4.1
File Size Uploaded Provenance Actions
ds_cache_cleaner-0.4.1.tar.gz 23.0 kB With provenance Details for ds_cache_cleaner-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ds-cache-cleaner 0.4.1
File Interpreter ABI Platform Actions
ds_cache_cleaner-0.4.1-py3-none-any.whl Python 3 none any Details for ds_cache_cleaner-0.4.1-py3-none-any.whl

Total release size: 51.4 kB

Release files / ds_cache_cleaner-0.4.1.tar.gz

Download URL ds_cache_cleaner-0.4.1.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f42c9150e5a4c5f82653ca880d5f177fa6dd4c5b703277f6f59cedae1d8cc18
BLAKE2b-256 checksum
How to use checksums
0dddbd4bb25fec7336be47006a7e50165ec9d4c7ec38e046da178018c9fcfe62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / ds_cache_cleaner-0.4.1-py3-none-any.whl

Download URL ds_cache_cleaner-0.4.1-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c5d81207f34a586190d9c0e72e9f59aebc24da0f6c020a280700fca4391fdf7
BLAKE2b-256 checksum
How to use checksums
5b72f52a32ba537db4c498d88caaba6846d687aae8c35441f2ef89264543a600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for ds-cache-cleaner 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ds_cache_cleaner-0.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page