Hugging Face datasets

Delete

The Delete API allows you to permanently remove a repository (dataset, model, or space) from your Hugging Face account or organization.


Code

use Partitech\PhpMistral\Clients\HuggingFace\HuggingFaceDatasetClient;
use Partitech\PhpMistral\MistralClientException;

$apiKey = getenv('HF_TOKEN');     // Hugging Face API token
$datasetUser = getenv('HF_USER'); // Hugging Face username or organization

$client = new HuggingFaceDatasetClient(apiKey: (string) $apiKey);

try {
    // Delete the 'rotten_tomatoes' dataset repository
    $repository = $client->delete(
        name: 'rotten_tomatoes',                                   // Repository name (without user prefix)
        type: HuggingFaceDatasetClient::REPOSITORY_TYPE_DATASET    // Repository type (dataset, model, or space)
    );

    print_r($repository);  // Should output 'OK' if successful

} catch (MistralClientException $e) {
    print_r($e);  // Handle errors (e.g., repository not found)
}

Result

OK
  • OK: Indicates that the repository has been successfully deleted from Hugging Face.

Use Cases

  • Cleanup: Remove obsolete or test repositories.
  • Automated workflows: Integrate repository deletion into your CI/CD pipelines or data lifecycle management.

Common Pitfalls