# Is it possible to use pymupdf4llm.to\_markdown with FastAPI UploadFile?

**URL:** <https://forum.mupdf.com/t/is-it-possible-to-use-pymupdf4llm-to-markdown-with-fastapi-uploadfile/141>\
**Category:** PyMuPDF\
**Created:** [August 28, 2025, 2:07pm UTC](https://forum.mupdf.com/t/is-it-possible-to-use-pymupdf4llm-to-markdown-with-fastapi-uploadfile/141 "2025-08-28T14:07:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marsea](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@marsea](https://forum.mupdf.com/u/marsea)\
**Post date:** [August 28, 2025, 2:07pm UTC](https://forum.mupdf.com/t/is-it-possible-to-use-pymupdf4llm-to-markdown-with-fastapi-uploadfile/141/1 "2025-08-28T14:07:55Z")

</div>

Hi,

I’m using FastAPI to upload PDFs, and I want to parse them with `pymupdf4llm.to_markdown` to maintain their structure. This worked fine with file paths during local development and testing, but `UploadFile` gives me bytes (`await file.read()`), and it seems `to_markdown` doesn’t accept in-memory files or `BytesIO`.

Is there a way to use `to_markdown` without saving the file to disk? I’d like to keep everything in-memory if possible.

Thanks!

---

<div class="post-metadata">

**Author:** ![Jamie\_Lemon](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.mupdf.com/jamie_lemon/32/5_2.png) [@Jamie\_Lemon](https://forum.mupdf.com/u/Jamie_Lemon)\
**Post date:** [August 28, 2025, 5:04pm UTC](https://forum.mupdf.com/t/is-it-possible-to-use-pymupdf4llm-to-markdown-with-fastapi-uploadfile/141/2 "2025-08-28T17:04:59Z")

</div>

HI @marsea and welcome to the forum!

I think you can load the document data from a stream and then direct that to pymupdf4llm with the following kind of approach:

```python
import pymupdf
import pymupdf4llm
import requests

r = requests.get(‘https://mupdf.com/docs/mupdf_explored.pdf’) 
data = r.content 
doc = pymupdf.Document(stream=data)

md_text = pymupdf4llm.to_markdown(doc, show_progress = True)

print(md_text)

```

Hopefully I’ve understood what you are looking for here okay - please let me know how that goes for you!
