A Go SDK for the Nanonets API, supporting document processing, workflow management, and moderation workflows.
Nanonets is an AI-powered Intelligent Document Processing platform that helps you:
- Extract structured data from invoices, receipts, forms, and more documents
- Supports pdf, images (jpg, png, tiff), excel files, scanned documents and photos
- Automate data entry and document workflows
- Convert unstructured documents into machine-readable formats
- Integrate advanced OCR and table extraction into your apps
go get github.com/NanoNets/nanonets-go/nanonets
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:
import "github.com/NanoNets/nanonets-go/nanonets" client := nanonets.NewClient("your_api_key")
package main
import (
"fmt"
"github.com/NanoNets/nanonets-go/nanonets"
)
func main() {
client := nanonets.NewClient("YOUR_API_KEY")
// Create a workflow
workflow, err := client.Workflows.Create(nanonets.CreateWorkflowRequest{
Description: "SDK Example Workflow",
WorkflowType: "", // Instant learning
})
if err != nil {
fmt.Println("Error creating workflow:", err)
return
}
workflowID := workflow.ID
fmt.Println("Created workflow:", workflowID)
// Configure fields and table headers
fields := []nanonets.Field{
{Name: "invoice_number"},
{Name: "total_amount"},
{Name: "invoice_date"},
}
tableHeaders := []nanonets.TableHeader{
{Name: "item_description"},
{Name: "quantity"},
{Name: "unit_price"},
{Name: "total"},
}
err = client.Workflows.SetFields(workflowID, nanonets.SetFieldsRequest{
Fields: fields,
TableHeaders: tableHeaders,
})
if err != nil {
fmt.Println("Error setting fields:", err)
return
}
fmt.Println("Configured fields and table headers.")
// Upload a document from file
uploadResult, err := client.Documents.Upload(workflowID, nanonets.UploadDocumentRequest{
File: "/path/to/document.pdf",
Async: false,
Metadata: map[string]string{"test": "true"},
})
if err != nil {
fmt.Println("Error uploading document:", err)
return
}
fmt.Println("Upload result:", uploadResult)
// Upload a document from URL
uploadResultURL, err := client.Documents.UploadFromURL(workflowID, nanonets.UploadDocumentFromURLRequest{
URL: "https://example.com/document.pdf",
Async: false,
Metadata: map[string]string{"test": "true"},
})
if err != nil {
fmt.Println("Error uploading document from URL:", err)
return
}
fmt.Println("Upload from URL result:", uploadResultURL)
// List documents (paginated)
documents, err := client.Documents.ListWithPagination(workflowID, 1, 10)
if err != nil {
fmt.Println("Error listing documents:", err)
return
}
fmt.Println("Documents:", documents)
// Get a document
if len(documents) > 0 {
docID := documents[0].DocumentID
doc, err := client.Documents.Get(workflowID, docID)
if err != nil {
fmt.Println("Error getting document:", err)
} else {
fmt.Println("Document:", doc)
}
}
}
- Workflow Management: Create, list, get, set fields, update/delete fields, update metadata/settings, get types
- Document Processing: Upload (file/URL), list (paginated), get, delete, get fields/tables, get original file
- Moderation: Update/add/delete/verify fields, add/delete/update/verify tables and cells
The SDK provides idiomatic Go error handling. Check errors returned from all SDK methods:
workflow, err := client.Workflows.Create(nanonets.CreateWorkflowRequest{...})
if err != nil {
// Handle error (authentication, validation, etc.)
fmt.Println("Error:", err)
}
- Resource Management
// Use defer for cleanup if needed func processDocument(client *nanonets.Client, document string) error { defer func() { // Cleanup if needed }() return nil }
- Batch Processing
// Process documents in batches func processBatch(client *nanonets.Client, documents []string, batchSize int) error { for i := 0; i < len(documents); i += batchSize { end := i + batchSize if end > len(documents) { end = len(documents) } batch := documents[i:end] // Process batch } return nil }
- Error Recovery
import "github.com/cenkalti/backoff" // Retry with exponential backoff func processWithRetry(client *nanonets.Client, document string) error { operation := func() error { return processDocument(client, document) } return backoff.Retry(operation, backoff.NewExponentialBackOff()) }
For detailed request/response formats, see the Go SDK docs and the Postman collection.