Workflow Management
The Nanonets Python SDK provides comprehensive functionality for managing workflows. This guide covers all available methods for workflow management, fully aligned with the Nanonets API.
Setup
Minimum Python version required: 3.7
Install the Nanonets Python SDK using pip:
pip install nanonets
Workflow Schema & Limits
- Workflow fields and table headers must be alphanumeric with underscores only, unique within the workflow, and cannot contain spaces or special characters.
- Limits:
- Max 20 workflows per account
- Max 30 fields per workflow
- Max 20 table headers per workflow
List Workflows
Retrieves a list of all workflows in your account.
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
workflows = client.workflows.list()
Get Workflow by ID
Retrieves detailed information about a specific workflow, including its configuration, fields, table headers, and settings.
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
workflow = client.workflows.get(workflow_id="workflow_123")
Get Available Workflow Types
Retrieves a list of all available workflow types you can use when creating a new workflow. Each type represents a different document processing model (e.g., invoice, receipt, passport).
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
workflow_types = client.workflows.get_types()
for t in workflow_types:
print(f"ID: {t['id']}, Name: {t['name']}, Description: {t['description']}")
Create Workflow
Creates a new workflow with the specified type. For instant learning workflows, you must configure fields after creation.
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
# Create instant learning workflow (requires field configuration after creation)
workflow = client.workflows.create(
description="Extract data from custom documents",
workflow_type="" # Empty string for instant learning
)
# Create pre-trained workflow (fields are pre-configured, can be modified later)
workflow = client.workflows.create(
description="Extract data from invoices",
workflow_type="invoice"
)
Set Fields and Table Headers
Configures the fields and table headers to extract from documents. This replaces all existing fields and table headers.
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
workflow = client.workflows.set_fields(
workflow_id="workflow_123",
fields=[
{"name": "invoice_number"},
{"name": "total_amount"},
{"name": "invoice_date"}
],
table_headers=[
{"name": "item_description"},
{"name": "quantity"},
{"name": "unit_price"},
{"name": "total"}
]
)
Update Field or Table Header
Modifies an existing field or table header configuration. Only the name can be updated, and it must remain unique and valid.
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
workflow = client.workflows.update_field(
workflow_id="workflow_123",
field_id="field_123",
name="invoice_number"
)
Delete Field or Table Header
Removes a specific field or table header from the workflow.
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
client.workflows.delete_field(
workflow_id="workflow_123",
field_id="field_123"
)
Update Workflow Metadata
Modifies the workflow's description. (Name is not a supported property in the API.)
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
workflow = client.workflows.update_metadata(
workflow_id="workflow_123",
description="Updated workflow description"
)
Update Workflow Settings
Configures table capture settings for the workflow.
from nanonetsclient import NanonetsClient
client = NanonetsClient(api_key='your_api_key')
workflow = client.workflows.update_settings(
workflow_id="workflow_123",
table_capture=True # Enable or disable table capture
)
Error Handling & Common Scenarios
The SDK provides custom error classes for better error handling. API error codes:
- 200 OK: Request successful
- 201 Created: Resource created
- 400 Bad Request: Invalid parameters, exceeded limits, or invalid field/table header names
- 401 Unauthorized: Invalid/missing API key
- 404 Not Found: Workflow or field not found
- 409 Conflict: Resource already exists
- 500 Internal Server Error: Server-side error
Common error scenarios:
- Invalid field/table header names (must be alphanumeric/underscore, unique)
- Exceeding workflow/field/table header limits
- Missing field configuration for instant learning workflows
from nanonets.exceptions import NanonetsError, AuthenticationError, ValidationError
from nanonetsclient import NanonetsClient
try:
client = NanonetsClient(api_key='your_api_key')
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
- Use clear, descriptive, and unique field/table header names (e.g., "invoice_number")
- For instant learning, always configure fields after workflow creation
- Use table capture settings as needed for your use case
- Monitor limits and handle errors gracefully
For more detailed information about specific features, see: