This PR adds 8 new direct API methods that were missing from the Python client, bringing it to feature parity with the Nutrient DWS API capabilities.
create_redactions_preset()- Use built-in patterns for common sensitive data- Presets: social-security-number, credit-card-number, email-address, international-phone-number, north-american-phone-number, date, time, us-zip-code
create_redactions_regex()- Custom regex patterns for flexible redactioncreate_redactions_text()- Exact text matches with case sensitivity options
optimize_pdf()- Reduce file size with multiple optimization options:- Grayscale conversion (text, graphics, images)
- Image optimization quality (1-4, where 4 is most optimized)
- Linearization for web viewing
- Option to disable images entirely
password_protect_pdf()- Add password protection and permissions- User password (for opening)
- Owner password (for permissions)
- Granular permissions: print, modification, extract, annotations, fill, etc.
set_pdf_metadata()- Update document properties- Title, author, subject, keywords, creator, producer
apply_instant_json()- Import Nutrient Instant JSON annotations- Supports file, bytes, or URL input
apply_xfdf()- Import standard XFDF annotations- Supports file, bytes, or URL input
- ✅ All methods have comprehensive docstrings with examples
- ✅ Type hints are complete and pass mypy checks
- ✅ Code follows project conventions and passes ruff linting
- ✅ All existing unit tests continue to pass (167 tests)
- Methods that require file uploads (apply_instant_json, apply_xfdf) handle them directly
- Methods that use output options (password_protect_pdf, set_pdf_metadata) use the Builder API
- All methods maintain consistency with existing Direct API patterns
- Comprehensive integration tests added for all new methods (28 new tests)
- Tests cover success cases, error cases, and edge cases
- Tests are properly skipped when API key is not configured
src/nutrient_dws/api/direct.py- Added 8 new methods (565 lines)tests/integration/test_new_tools_integration.py- New test file (481 lines)
# Redact social security numbers
client.create_redactions_preset(
"document.pdf",
preset="social-security-number",
output_path="redacted.pdf"
)
# Custom regex redaction
client.create_redactions_regex(
"document.pdf",
pattern=r"\b\d{3}-\d{2}-\d{4}\b",
appearance_fill_color="#000000"
)
# Then apply the redactions
client.apply_redactions("redacted.pdf", output_path="final.pdf")# Aggressive optimization
client.optimize_pdf(
"large_document.pdf",
grayscale_images=True,
image_optimization_quality=4,
linearize=True,
output_path="optimized.pdf"
)# Password protect with restricted permissions
client.password_protect_pdf(
"sensitive.pdf",
user_password="view123",
owner_password="admin456",
permissions={
"print": False,
"modification": False,
"extract": True
}
)None - all changes are additive.
No migration needed - existing code continues to work as before.
- Code follows project style guidelines
- Self-review of code completed
- Comments added for complex code sections
- Documentation/docstrings updated
- No warnings generated
- Tests added for new functionality
- All tests pass locally
- Integration tests pass with live API (requires API key)
After merging:
- Update README with examples of new methods
- Consider adding more tools: HTML to PDF, digital signatures, etc.
- Create a cookbook/examples directory with common use cases