Reducto Python SDK
The Reducto Python SDK provides a type-safe interface for convenient access to the Reducto REST API from any Python 3.9+ application. It handles authentication, request formatting, and response parsing automatically. The library is currently at version 0.22.0 and has a frequent release cadence, with multiple updates often occurring within a single month.
Warnings
- breaking The `file` parameter for the `client.upload()` method in `v0.22.0` and later now expects binary file-like objects (e.g., `Path`, `bytes`, or a `(filename, contents, media_type)` tuple) instead of a `str` file path.
- gotcha Uploaded files to Reducto's servers (identified by `reducto://` URIs) are temporary and expire after 24 hours. Attempting to use an expired `file_id` will result in an error.
- gotcha Direct file uploads via `client.upload()` are limited to 100MB. For files larger than 100MB (up to 5GB), you must use the presigned URL upload method.
- gotcha The SDK automatically reads the API key from the `REDUCTO_API_KEY` environment variable by default. If it's not set, client initialization might fail or requests will be unauthenticated.
- gotcha While the async client uses `httpx` by default, for improved concurrency performance, it's recommended to install `aiohttp` and configure the client to use it.
Install
-
pip install reductoai -
pip install reductoai[aiohttp]
Imports
- Reducto
from reducto import Reducto
- AsyncReducto
from reducto import AsyncReducto
- Path
from pathlib import Path
Quickstart
import os
from pathlib import Path
from reducto import Reducto
# Ensure REDUCTO_API_KEY is set in your environment
# export REDUCTO_API_KEY="your_api_key_here"
api_key = os.environ.get('REDUCTO_API_KEY', '')
if not api_key:
print("Warning: REDUCTO_API_KEY environment variable not set.")
print("Please set it to run the quickstart example.")
exit(1)
# Initialize the client
client = Reducto(api_key=api_key)
# Create a dummy file for upload example
dummy_file_path = Path("dummy_document.txt")
dummy_file_path.write_text("This is a dummy document for Reducto.")
try:
# Upload a document
upload_response = client.upload(file=dummy_file_path)
print(f"Uploaded file with ID: {upload_response.file_id}")
# Parse the document using the uploaded file_id
parse_result = client.parse.run(input=upload_response.file_id)
# Access the extracted content (example: print first chunk content)
if parse_result.result and parse_result.result.chunks:
print(f"First chunk content: {parse_result.result.chunks[0].content}")
else:
print("No chunks found in the parsed result.")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Clean up the dummy file
if dummy_file_path.exists():
dummy_file_path.unlink()