> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moorcheh.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Files

> Delete uploaded file objects from a namespace using the Python SDK

## documents.delete\_files

Deletes one or more **files by name** from a text namespace (storage-backed uploads, for example after `documents.upload_file`). The backend removes the file and associated derived content from the namespace.

This is **not** the same as `documents.delete`, which removes **indexed text documents by ID**.

### Parameters

<ParamField query="namespace_name" type="str" required>
  The name of the target text namespace.
</ParamField>

<ParamField query="file_names" type="list[str]" required>
  Non-empty list of file names to delete (same names as returned by `documents.list_files` or used at upload).
</ParamField>

**Returns:** `Dict[str, Any]` - A dictionary confirming the deletion request.

Common response fields include `success`, `message`, `namespace`, and `results` (each item: `file_name`, `status`, `message`). Keys are **snake\_case** after SDK normalization.

**Raises:** `NamespaceNotFound`, `InvalidInputError`, `AuthenticationError`, `APIError`, `MoorchehError`.

### Example

```python Delete Files Example theme={null}
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    status = client.documents.delete_files(
        namespace_name="my-faq-documents",
        file_names=["old-report.pdf", "draft-notes.txt"],
    )
    print(status)
```

### Async Example

```python Delete Files Async Example theme={null}
import asyncio
from moorcheh_sdk import AsyncMoorchehClient

async def main():
    async with AsyncMoorchehClient() as client:
        status = await client.documents.delete_files(
            namespace_name="my-faq-documents",
            file_names=["old-report.pdf"],
        )
        for row in status.get("results", []):
            print(row["file_name"], row["status"], row.get("message"))

asyncio.run(main())
```

### Complete Example

```python Complete Delete Files Workflow theme={null}
from moorcheh_sdk import MoorchehClient

with MoorchehClient() as client:
    namespace = "my-data"
    listing = client.documents.list_files(namespace_name=namespace)
    names = [f["file_name"] for f in listing.get("files", []) if f["file_name"].endswith(".tmp")]
    if names:
        result = client.documents.delete_files(
            namespace_name=namespace,
            file_names=names,
        )
        print(result.get("message"), result.get("results"))
```

## Important Notes

<Note>
  **Per-file results**: Check `results` for each `file_name`; statuses can differ when some files exist and others do not.
</Note>

<Note>
  **Multi-status (207)**: The API may return **207** when some deletions succeed and others do not; the SDK treats **200** and **207** as success responses.
</Note>

<Warning>
  **Irreversible for storage objects**: Deleting by file name removes that object from the namespace’s file storage workflow; confirm names before calling.
</Warning>

## Best Practices

* Delete only names you intend to remove; prefer listing (`documents.list_files`) to confirm names first
* Inspect `results` and handle `not_found` (or similar statuses) without treating the whole call as a hard failure
* Batch related removals in one call when the API allows your list size
* Use `documents.delete` when you need to remove **documents by ID** from the text pipeline, not raw file names

## Related Operations

* [Upload File](/python-sdk/files/upload-file) - Upload files via pre-signed flow
* [List Files](/python-sdk/files/list-files) - List raw file objects in storage
* [Fetch Text Data](/python-sdk/data/fetch-text-data) - List ingested text and summary chunks
* [Search](/python-sdk/search/query) - Query processed content
* [Delete Data](/python-sdk/data/delete) - Remove indexed documents by ID
