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

# delete_document_by_filename

> Delete a document by its filename

## Usage

> [tab] Sync
>
> ```python theme={null}
> from morphik import Morphik
>
> db = Morphik()
>
> # Delete a document by its filename
> result = db.delete_document_by_filename("report.pdf")
> print(result["message"])  # "Document doc_123456 deleted successfully"
> ```

> [tab] Async
>
> ```python theme={null}
> from morphik import AsyncMorphik
>
> async with AsyncMorphik() as db:
>     # Delete a document by its filename
>     result = await db.delete_document_by_filename("report.pdf")
>     print(result["message"])  # "Document doc_123456 deleted successfully"
> ```

## Parameters

* `filename` (str): Filename of the document to delete

## Returns

A dictionary containing information about the deletion operation:

* `message` (str): A success message indicating the document was deleted
* `document_id` (str): The ID of the deleted document
* Additional fields may be present with more details about the operation

## Description

This method is a convenience wrapper that:

1. Retrieves the document ID by filename using [get\_document\_by\_filename](https://morphik.ai/docs/python-sdk/get_document_by_filename.md)
2. Deletes the document using [delete\_document](https://morphik.ai/docs/python-sdk/delete_document.md)

This operation is permanent and cannot be undone.

## Multiple Documents with Same Filename

If multiple documents have the same filename, this method will delete the most recently updated one. To delete a specific document when duplicates exist, use [delete\_document](https://morphik.ai/docs/python-sdk/delete_document.md) with the exact document ID instead.

> [tab] Sync
>
> ```python theme={null}
> # To handle multiple documents with the same filename
> docs = db.list_documents()
>
> # Find all documents with a specific filename
> matching_docs = [doc for doc in docs if doc.filename == "report.pdf"]
>
> # Review them
> for doc in matching_docs:
>     print(f"ID: {doc.external_id}, Created: {doc.system_metadata.get('created_at')}")
>
> # Delete a specific one by ID
> result = db.delete_document(matching_docs[0].external_id)
> ```

> [tab] Async
>
> ```python theme={null}
> # To handle multiple documents with the same filename
> docs = await db.list_documents()
>
> # Find all documents with a specific filename
> matching_docs = [doc for doc in docs if doc.filename == "report.pdf"]
>
> # Review them
> for doc in matching_docs:
>     print(f"ID: {doc.external_id}, Created: {doc.system_metadata.get('created_at')}")
>
> # Delete a specific one by ID
> result = await db.delete_document(matching_docs[0].external_id)
> ```

## Notes

* This operation requires appropriate permissions for the document.
* If no document exists with the specified filename, a `ValueError` will be raised.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.