Setup
Welcome to the official Python SDK documentation for Nanonets. This guide will help you integrate Nanonets into your Python applications for intelligent document processing, data extraction, and workflow automation.
The Nanonets Python SDK provides a simple and intuitive interface to interact with the Nanonets API.
Installation
Install the SDK using pip:
pip install nanonetsclient
Authentication
Sign up and get your API key from your Nanonets dashboard.
The SDK uses your API key for authentication. You can set it in two ways:
- Environment variable:
export NANONETS_API_KEY='your_api_key'
- Direct initialization:
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
Quick Start
Here's a quick example of how to use the SDK:
from nanonetsclient import NanonetsClient
# Initialize client
client = NanonetsClient(api_key='your_api_key')
# Create a workflow
workflow = client.workflows.create(
name="Invoice Processing",
description="Extract data from invoices",
workflow_type="invoice"
)
# Process a document
result = workflow.process_document(
file_path="invoice.pdf",
async_mode=True
)
# Get results
if result.status == "completed":
print(f"Extracted data: {result.data}")
Features
The SDK provides comprehensive functionality for:
Error Handling
The SDK provides custom exceptions for better error handling:
from nanonetsclient.exceptions import NanonetsError, AuthenticationError, ValidationError
try:
workflow = client.workflows.create(...)
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except ValidationError as e:
print(f"Invalid input: {e}")
except NanonetsError as e:
print(f"An error occurred: {e}")
Best Practices
Resource Management
# Use context manager for automatic cleanup
with NanonetsClient(api_key='your_api_key') as client:
workflow = client.workflows.create(...)Batch Processing
# Process documents in batches
for batch in workflow.process_documents_batch(documents, batch_size=10):
results.extend(batch)Error Recovery
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
def process_with_retry(workflow, document):
return workflow.process_document(document)
For more detailed information about specific features, please refer to the following sections: