Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/reductoai/reducto-python-sdk/llms.txt

Use this file to discover all available pages before exploring further.

Quick Start

This guide will help you parse your first document using the Reducto Python SDK in just a few minutes.

Basic Usage

Here’s a simple example of parsing a PDF document from a URL:
import os
from reducto import Reducto

client = Reducto(
    api_key=os.environ.get("REDUCTO_API_KEY"),  # This is the default and can be omitted
    # or 'production' | 'au'; defaults to "production".
    environment="eu",
)

response = client.parse.run(
    input="https://pdfobject.com/pdf/sample.pdf",
)
The api_key parameter is optional if you’ve set the REDUCTO_API_KEY environment variable.

Async Usage

For asynchronous operations, use AsyncReducto instead of Reducto:
import os
import asyncio
from reducto import AsyncReducto

client = AsyncReducto(
    api_key=os.environ.get("REDUCTO_API_KEY"),  # This is the default and can be omitted
    # or 'production' | 'au'; defaults to "production".
    environment="eu",
)


async def main() -> None:
    response = await client.parse.run(
        input="https://pdfobject.com/pdf/sample.pdf",
    )
    print(response)


asyncio.run(main())
The async and sync clients have identical APIs - just add await to method calls when using AsyncReducto.

Using aiohttp Backend

For improved concurrency performance, you can use the aiohttp backend:
1

Install aiohttp support

pip install reductoai[aiohttp]
2

Configure the client

import os
import asyncio
from reducto import DefaultAioHttpClient
from reducto import AsyncReducto


async def main() -> None:
    async with AsyncReducto(
        api_key=os.environ.get("REDUCTO_API_KEY"),  # This is the default and can be omitted
        http_client=DefaultAioHttpClient(),
    ) as client:
        response = await client.parse.run(
            input="https://pdfobject.com/pdf/sample.pdf",
        )
        print(response)


asyncio.run(main())

Working with Nested Parameters

You can pass additional options using nested TypedDict parameters:
from reducto import Reducto

client = Reducto()

response = client.parse.run(
    input="string",
    enhance={},
)
print(response.enhance)

File Uploads

Upload files from your local filesystem using PathLike instances:
from pathlib import Path
from reducto import Reducto

client = Reducto()

client.upload(
    file=Path("/path/to/file"),
)
File uploads work identically for both sync and async clients. Files are read asynchronously when using AsyncReducto.

Error Handling

Handle API errors gracefully with exception handling:
import reducto
from reducto import Reducto

client = Reducto()

try:
    client.parse.run(
        input="https://pdfobject.com/pdf/sample.pdf",
    )
except reducto.APIConnectionError as e:
    print("The server could not be reached")
    print(e.__cause__)  # an underlying Exception, likely raised within httpx.
except reducto.RateLimitError as e:
    print("A 429 status code was received; we should back off a bit.")
except reducto.APIStatusError as e:
    print("Another non-200-range status code was received")
    print(e.status_code)
    print(e.response)

Error Types

Status CodeError Type
400BadRequestError
401AuthenticationError
403PermissionDeniedError
404NotFoundError
422UnprocessableEntityError
429RateLimitError
>=500InternalServerError
N/AAPIConnectionError

Response Types

All responses are Pydantic models with helpful methods:
# Serialize to JSON
json_str = response.to_json()

# Convert to dictionary
data_dict = response.to_dict()
Enable type checking in VS Code by setting python.analysis.typeCheckingMode to basic to catch errors early.

Next Steps

API Reference

Explore all available methods and parameters

Advanced Usage

Learn about retries, timeouts, and streaming

Main Features

Learn about parsing, extraction, and splitting

Error Handling

Deep dive into error handling patterns

Build docs developers (and LLMs) love