Async API

All static and instance methods have async counterparts. File I/O is truly asynchronous — source files are read and output files are written using async streams, while the CPU-bound conversion itself runs on a worker thread so your event loop stays responsive.

Note
Async methods are designed for use with Python’s built-in asyncio framework. Call them with await from inside a coroutine and run the coroutine with asyncio.run().

Static async methods

import asyncio
from groupdocs.markdown import MarkdownConverter, ConvertOptions

async def async_static():
    """Use the static async API to convert a document and inspect its metadata."""

    # Step 1: Convert to a Markdown string
    md = await MarkdownConverter.to_markdown_async("business-plan.docx")

    # Step 2: Convert and save directly to a file
    await MarkdownConverter.to_file_async("business-plan.docx", "async-static.md", None)

    # Step 3: Convert with options
    options = ConvertOptions()
    options.include_front_matter = True
    await MarkdownConverter.to_file_async("business-plan.docx", "async-static.md", options)

    # Step 4: Retrieve document info without a full conversion
    info = await MarkdownConverter.get_info_async("business-plan.docx", None)
    # info.file_format, info.page_count

if __name__ == "__main__":
    asyncio.run(async_static())

business-plan.docx is sample file used in this example. Click here to download it.

---
title: "Meridian Outdoor Co. — Business Plan"
author: "Meridian Outdoor Co."
format: Docx
pages: 5
---

![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAC0CAYAAABIf1IMAAAABHNCSVQICAgIfAhkiAAADcJJREFUeJzt3VFo3VWeB/BfF2EfdJraSWKkpovabiokaRZcfWiM4jCS0mELjvgwzlZt16fdlUFpKbLCgDKELQ7Oum+yNdYdH4StCLMkdBexSfow7sC0SUA7TZVJW0zbWI1OF/ap+xD+/97k/u/Nze1JbJLPBwo9/3vu/Z1/L5Qv55x7/uumJkauBQAAyfzZdz0AAIDVRsACAEhMwAIASEzAAgBI7Jaii//67/8dZ89dSlbkH576Qdy7+Y4F+6Wqq5566qmnnnrqqbdc9YoUBqyJyYsxevrcDQ2q1LdX/6
[TRUNCATED]

Download full output

Instance async methods

import asyncio
from groupdocs.markdown import MarkdownConverter, ConvertOptions

async def async_instance():
    """Use the instance async API with a context manager."""

    # Step 1: Open the document with a context manager
    with MarkdownConverter("business-plan.docx") as converter:
        # Step 2: Configure conversion options
        options = ConvertOptions()
        options.heading_level_offset = 1

        # Step 3: Convert and save the Markdown output asynchronously
        await converter.convert_async("async-instance.md", options)

        # Step 4: Retrieve document metadata asynchronously
        info = await converter.get_document_info_async()
        # info.file_format, info.page_count

if __name__ == "__main__":
    asyncio.run(async_instance())

business-plan.docx is sample file used in this example. Click here to download it.

![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAC0CAYAAABIf1IMAAAABHNCSVQICAgIfAhkiAAADcJJREFUeJzt3VFo3VWeB/BfF2EfdJraSWKkpovabiokaRZcfWiM4jCS0mELjvgwzlZt16fdlUFpKbLCgDKELQ7Oum+yNdYdH4StCLMkdBexSfow7sC0SUA7TZVJW0zbWI1OF/ap+xD+/97k/u/Nze1JbJLPBwo9/3vu/Z1/L5Qv55x7/uumJkauBQAAyfzZdz0AAIDVRsACAEhMwAIASEzAAgBI7Jaii//67/8dZ89dSlbkH576Qdy7+Y4F+6Wqq5566qmnnnrqqbdc9YoUBqyJyYsxevrcDQ2q1LdX/6+mfqnqqqeeeuqpp5566i1XvSKFAWvL5jti3bp1cXbyYvzpf+v/cACAtWhZZrAAANaSdUUHjf7sF7+eE7D+/qkfxL2t9a1BRszOiN12658v2O
[TRUNCATED]

Download full output

Running concurrent conversions

Use asyncio.gather() to convert multiple documents in parallel while the event loop stays free for other work:

import asyncio
from groupdocs.markdown import MarkdownConverter

async def async_concurrent():
    """Convert several documents concurrently with asyncio.gather()."""

    # Step 1: Define the source files and their output targets
    jobs = [
        ("business-plan.docx", "async-concurrent-docx.md"),
        ("business-plan.pdf",  "async-concurrent-pdf.md"),
        ("cost-analysis.xlsx", "async-concurrent-xlsx.md"),
    ]

    # Step 2: Launch every conversion concurrently
    await asyncio.gather(*(
        MarkdownConverter.to_file_async(src, dst, None) for src, dst in jobs
    ))

if __name__ == "__main__":
    asyncio.run(async_concurrent())

business-plan.docx is sample file used in this example. Click here to download it.

business-plan.pdf is sample file used in this example. Click here to download it.

cost-analysis.xlsx is sample file used in this example. Click here to download it.

![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAC0CAYAAABIf1IMAAAABHNCSVQICAgIfAhkiAAADcJJREFUeJzt3VFo3VWeB/BfF2EfdJraSWKkpovabiokaRZcfWiM4jCS0mELjvgwzlZt16fdlUFpKbLCgDKELQ7Oum+yNdYdH4StCLMkdBexSfow7sC0SUA7TZVJW0zbWI1OF/ap+xD+/97k/u/Nze1JbJLPBwo9/3vu/Z1/L5Qv55x7/uumJkauBQAAyfzZdz0AAIDVRsACAEhMwAIASEzAAgBI7Jaii//67/8dZ89dSlbkH576Qdy7+Y4F+6Wqq5566qmnnnrqqbdc9YoUBqyJyYsxevrcDQ2q1LdX/6+mfqnqqqeeeuqpp5566i1XvSKFAWvL5jti3bp1cXbyYvzpf+v/cACAtWhZZrAAANaSdUUHjf7sF7+eE7D+/qkfxL2t9a1BRszOiN12658v2O
[TRUNCATED]

Download full output

FastAPI example

The async API is a natural fit for ASGI frameworks such as FastAPI — file I/O does not block the event loop, so a single worker can handle many concurrent conversion requests:

import os
import tempfile
from fastapi import FastAPI, UploadFile
from fastapi.responses import PlainTextResponse
from groupdocs.markdown import MarkdownConverter, ConvertOptions, MarkdownFlavor

app = FastAPI()

@app.post("/convert", response_class=PlainTextResponse)
async def async_fastapi(file: UploadFile):
    """Accept an uploaded document and return Markdown without blocking the event loop."""
    # Stream the upload to a temp file so GroupDocs.Markdown can open it
    suffix = os.path.splitext(file.filename)[1]
    with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
        tmp.write(await file.read())
        tmp_path = tmp.name

    options = ConvertOptions()
    options.flavor = MarkdownFlavor.GIT_HUB

    try:
        return await MarkdownConverter.to_markdown_async(tmp_path, convert_options=options)
    finally:
        os.unlink(tmp_path)
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.