Python SDK
Quickly integrate Docflow document workflow management capabilities with docflow-sdk Python SDK
docflow-sdk is the official Python SDK for TextIn Docflow, providing workspace management, document classification, intelligent review, type-safe response models, and comprehensive error handling.
Installation
System Requirements: Python >= 3.8
Authentication and Initialization
The SDK supports multiple authentication methods (priority: constructor parameters > environment variables > .env file):
Using environment variables is recommended to avoid hardcoding credentials in your code.
API Overview
Workspace Management
Workspaces are the top-level organizational unit in Docflow, used to isolate document processing workflows for different business scenarios.
Create Workspace
List Workspaces
Method Chaining (Recommended)
Simplify code through context binding, reducing repetitive parameter passing:
Document Category Management
Categories define structured fields and extraction rules for documents.
Create Category (with Sample Files)
Category keyword rules
Use category_keyword_rules when creating or updating a category. Positive rule groups are combined with OR; a negative rule group match excludes the category.
By default, the SDK paginates through enabled categories in the workspace and prechecks cross-category, same-type rule-group conflicts before sending the request. Set check_keyword_rule_conflicts=False to skip this extra client-side check; the server always performs the final conflict validation.
- On create, omitting this parameter leaves rules unconfigured; dual empty arrays have the same effect.
- On update, omit it or pass
None for no change; a valid object replaces all rules; only dual empty arrays clear them. {} and blank strings are invalid.
- In the SDK, a rule group’s
group_name is optional: positive groups default to group_1, group_2, and so on, while a negative group defaults to exclude. It is display/tracking metadata only and does not affect matching or conflict detection; names returned by the API are preserved on a subsequent update.
- Keywords preserve their original case and whitespace. Each keyword must be non-empty and at most 50 characters, and the same original string cannot appear twice within a group. A group has at most 20 keywords; a category has at most 10 positive and 1 negative group;
min_hit must be from 1 to the number of group keywords.
- Positive and negative rules in the same category cannot contain the same original keyword string. Other enabled categories in the workspace cannot have a same-type rule group with the same original keyword set. The SDK pre-validates rules it can determine locally; the service performs final validation, and a cross-category conflict returns
1005015019.
Field Management
Table Management
Sample Management
File Processing
Upload and Recognize Files
Get Recognition Results
Intelligent Review
Docflow provides LLM-based intelligent review capabilities, supporting single-document rule validation and cross-document review.
Create Review Rule Repository
Cross-Document Review
Submit Review Task
Get Review Results
Enumeration Types
The SDK provides complete enumeration type definitions to avoid parameter errors:
Use iterators to automatically handle pagination without manual looping:
Error Handling
The SDK provides comprehensive error classification for precise handling of different exception scenarios.
Error Types
Error Handling Example
Internationalization (i18n)
The SDK supports multilingual error messages:
Advanced Configuration
Timeout and Retry
Custom Retry Configuration
Custom API Address
Resource Management
Use context manager to automatically close connections:
Debug Logging
Enable DEBUG level logging to view request details:
Complete Examples
See the examples directory for complete usage examples:
FAQ