Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Huggingface Datasets DeleteFromHubCommand

From Leeroopedia

Overview

DeleteFromHubCommand is a CLI command class for removing a dataset configuration from the Hugging Face Hub. It extends BaseDatasetsCLICommand and provides a delete_from_hub subcommand that accepts a dataset ID, configuration name, and optional authentication token and revision. When executed, it delegates the actual deletion to datasets.hub.delete_from_hub.

Source File

Property Value
Repository huggingface/datasets
File src/datasets/commands/delete_from_hub.py
Lines 42
Domain CLI, Hub_Operations

Import

from datasets.commands.delete_from_hub import DeleteFromHubCommand

Class: DeleteFromHubCommand

Inherits from: BaseDatasetsCLICommand

Constructor

def __init__(
    self,
    dataset_id: str,
    config_name: str,
    token: Optional[str],
    revision: Optional[str],
):
Parameter Type Description
dataset_id str The dataset identifier (e.g., USERNAME/DATASET_NAME or ORGANIZATION/DATASET_NAME)
config_name str The name of the configuration to delete
token Optional[str] Access token for the Hugging Face Hub
revision Optional[str] Source revision (branch or commit) to target

Methods

register_subcommand(parser)

Static method. Registers the delete_from_hub subcommand with the argument parser. Defines two positional arguments (dataset_id, config_name) and two optional arguments (--token, --revision). Sets the factory function _command_factory as the default handler.

@staticmethod
def register_subcommand(parser):
    parser: ArgumentParser = parser.add_parser("delete_from_hub", help="Delete dataset config from the Hub")
    parser.add_argument(
        "dataset_id", help="source dataset ID, e.g. USERNAME/DATASET_NAME or ORGANIZATION/DATASET_NAME"
    )
    parser.add_argument("config_name", help="config name to delete")
    parser.add_argument("--token", help="access token to the Hugging Face Hub")
    parser.add_argument("--revision", help="source revision")
    parser.set_defaults(func=_command_factory)

run()

Executes the deletion by calling delete_from_hub() from datasets.hub with the stored dataset ID, config name, revision, and token. Returns None.

def run(self) -> None:
    _ = delete_from_hub(self._dataset_id, self._config_name, revision=self._revision, token=self._token)

Factory Function

def _command_factory(args):
    return DeleteFromHubCommand(
        args.dataset_id,
        args.config_name,
        args.token,
        args.revision,
    )

This factory is invoked by the argument parser to instantiate DeleteFromHubCommand from the parsed CLI arguments.

I/O

Direction Description
Input CLI arguments: dataset_id (positional), config_name (positional), --token (optional), --revision (optional)
Output Deletes the specified dataset configuration from the Hugging Face Hub (side effect)

Dependencies

Module Purpose
argparse.ArgumentParser Argument parsing
datasets.commands.BaseDatasetsCLICommand Abstract base class for CLI commands
datasets.hub.delete_from_hub Hub deletion logic

Usage

# Delete a specific config from a dataset on the Hub
datasets-cli delete_from_hub username/my_dataset config_to_remove --token hf_xxxxx

# Delete with a specific revision
datasets-cli delete_from_hub org/dataset_name old_config --token hf_xxxxx --revision main

Related Pages

Categories

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment