Reducto Python SDK

0.22.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Reducto` client, upload a local file, and then parse its content. It assumes your Reducto API key is set as an environment variable `REDUCTO_API_KEY`. A dummy file is created for demonstration purposes and then cleaned up.

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()

view raw JSON →