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

# Batch Processing

> Convert multiple documents efficiently with parallel processing.

**Before you begin**, make sure you have:

1. A [Datalab account](https://www.datalab.to/auth/sign_up) with an [API key](https://www.datalab.to/app/keys)
2. Python 3.11+ installed
3. The Datalab SDK: `pip install datalab-python-sdk`
4. Your `DATALAB_API_KEY` environment variable set

Process directories of documents with the SDK or CLI. Both handle rate limiting and retries automatically.

## SDK Batch Processing

Process multiple files using Python's async capabilities:

### Async Batch Processing

For higher throughput:

```python Python SDK theme={null}
import asyncio
from pathlib import Path
from datalab_sdk import AsyncDatalabClient, ConvertOptions

async def process_directory(input_dir: str, output_dir: str, concurrency: int = 5):
    if concurrency < 1:
        raise ValueError("concurrency must be positive")
    output = Path(output_dir)
    output.mkdir(parents=True, exist_ok=True)
    files = iter(Path(input_dir).glob("*.pdf"))

    # Reuse one HTTP session and start only a fixed number of workers.
    async with AsyncDatalabClient() as client:
        async def worker():
            for pdf in files:
                try:
                    result = await client.convert(
                        str(pdf), options=ConvertOptions(mode="balanced")
                    )
                    if not result.success:
                        raise RuntimeError(result.error or "Conversion failed")
                    if result.markdown is None:
                        raise RuntimeError("No Markdown returned")
                    output_path = output / f"{pdf.stem}.md"
                    output_path.write_text(result.markdown, encoding="utf-8")
                    print(f"Saved: {output_path}")
                except Exception as error:
                    print(f"Error processing {pdf.name}: {error}")

        await asyncio.gather(*(worker() for _ in range(concurrency)))

asyncio.run(process_directory("./documents/", "./output/"))
```

## CLI Batch Processing

The CLI handles directory processing automatically:

```bash theme={null}
# Convert all PDFs in a directory
datalab convert ./documents/ --output_dir ./output/

# Filter by extension
datalab convert ./documents/ --extensions pdf,docx

# Control concurrency
datalab convert ./documents/ --max_concurrent 10

# With processing options
datalab convert ./documents/ \
  --mode balanced \
  --format markdown \
  --output_dir ./output/
```

See [CLI Reference](https://documentation.datalab.to/docs/welcome/sdk/cli.md) for all options.

## REST API Batch Processing

Start with the complete [Python requests example](https://documentation.datalab.to/docs/welcome/quickstart.md#convert-a-document) for submitting a document, checking failures, and retrieving inline or downloaded results. Use a bounded worker pool to process multiple documents and reuse a session within each worker.

> [!WARNING]
>
> A timed-out submission may have been accepted. Avoid automatically replaying a POST after a connection error or timeout: it can create another job. Poll a known request ID when available. See [SDK retry behavior](https://documentation.datalab.to/docs/welcome/sdk.md#automatic-retries).

## Rate Limits

* **Request rate limit:** 25 requests per minute on Free, 400 on Launch and Team (429 on exceed)
* **Concurrent request limit:** 25 on Free, 400 on Launch and Team (429 on exceed)
* **Page concurrency limit:** 5,000 pages in flight across all requests — this is enforced during processing, not at submission. Results return with `success: false` if exceeded. Always check the `success` field when polling for results.
* The SDK and CLI retry supported transient submission and polling errors; [retry behavior](https://documentation.datalab.to/docs/welcome/sdk.md#automatic-retries) depends on the request type
* For higher limits, contact [support@datalab.to](mailto:support@datalab.to)

See [API Limits](https://documentation.datalab.to/docs/common/limits.md) for details.

## Tips

1. **Use async for high throughput** - Async processing handles many concurrent requests efficiently
2. **Limit concurrency** - Start with 5-10 concurrent requests and adjust based on your rate limits
3. **Handle failures gracefully** - Check `success` for each result and record failed files so you can retry them selectively
4. **Save progress** - Write results incrementally to avoid losing work on long batches

## Next Steps

> [card] [Document Conversion](https://documentation.datalab.to/docs/recipes/conversion/conversion-api-overview.md)
>
> Learn more about Marker's conversion API and output formats.

> [card] [API Limits](https://documentation.datalab.to/docs/common/limits.md)
>
> Understand rate limits and how to optimize throughput.

> [card] [Pipelines](https://documentation.datalab.to/docs/recipes/pipelines/pipeline-overview.md)
>
> Chain processors into versioned, reusable pipelines.

> [card] [Webhooks](https://documentation.datalab.to/platform/webhooks.md)
>
> Get notified when batch conversions complete via webhooks.


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