-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Core components - exceptions, file handling, and HTTP client #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Implement comprehensive exception classes for error handling - Add rich error context with status codes and request IDs - Create dedicated exceptions for auth, validation, timeout, and file errors - Add unit tests for all exception classes with 100% coverage
- Implement HTTPClient with automatic retries for transient errors - Add connection pooling for performance optimization - Handle all API error responses with appropriate exceptions - Support multipart/form-data for file uploads and JSON actions - Add comprehensive unit tests with mocked responses - Include context manager support for proper resource cleanup
- Complete NutrientClient with authentication and configuration - Add Direct API methods generated from common operations - Support both parameter and environment variable API key - Implement _process_file method for handling API requests - Add comprehensive unit tests for client functionality - Include context manager support for proper cleanup
- Complete Builder API with fluent interface for chaining operations - Support multiple document processing steps in a single API call - Map tool names to Build API action types - Add output options configuration (metadata, optimization) - Include comprehensive unit tests for all builder functionality - Support both in-memory and file output options
- Fix file handler to properly extract basenames from Path objects - Update session close tests to match requests library behavior - Add TYPE_CHECKING imports to resolve circular dependencies - Improve type annotations throughout codebase - Fix linting issues identified by ruff - All 82 tests now passing with 92.46% coverage
Test Results Update ✅All tests are now passing! Here's the latest status: Test Suite
Type Checking
Code Quality
Changes Made
The core components implementation is now complete and ready for review! |
- Add CI workflow for testing across Python 3.8-3.12 - Include linting, type checking, and test coverage - Add release workflow for PyPI publishing - Configure Dependabot for dependency updates - Set up caching for faster builds
- Add detailed installation and quick start guide - Include examples for both Direct API and Builder API - Document all available tools and their usage - Add error handling examples - Include development setup instructions - Add contribution guidelines
- Add integration tests for Direct API operations - Add integration tests for Builder API workflows - Test various file input methods (path, bytes, file object) - Test authentication and error handling - Add pytest markers and configuration for test separation - Integration tests require NUTRIENT_API_KEY environment variable
- Change base URL to https://api.pspdfkit.com - Use Bearer token authentication instead of X-Api-Key - Send instructions as JSON string in form data - Update Direct API to use Build API internally - Add Path object support to file handlers - Fix tests passing: 14/22 tests now working
- Remove unsupported methods (convert-to-pdf, export-to-images, etc) - Fix watermark to require width/height parameters - Add OCR language code mapping (en -> english) - Update merge_pdfs to work with Build API - Add comprehensive documentation of supported operations - Update README to reflect only supported features Based on API testing: - Only 6 operations are currently supported - All operations go through the Build API - Watermark requires width/height parameters - OCR supports english/eng/deu languages
- Discovered that the Nutrient API automatically converts Office documents (DOCX, XLSX, PPTX) to PDF - Added convert_to_pdf method that leverages implicit conversion - Updated all Direct API method documentation to reflect Office document support - Updated SUPPORTED_OPERATIONS.md with comprehensive documentation of the discovery - All methods now accept both PDFs and Office documents seamlessly - Updated examples to show mixing PDFs and Office documents in operations like merge This is a significant improvement to the library's capabilities, as users can now: - Convert Office documents to PDF without explicit conversion steps - Use any processing operation (rotate, OCR, watermark, etc.) directly on Office files - Mix PDFs and Office documents in merge operations
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements the core components of the Nutrient DWS Python client library as specified in the Software Design Specification v1.1.
🎯 Major Discovery: Implicit Document Conversion
During implementation and testing with the live API, we discovered that the Nutrient API automatically converts Office documents (DOCX, XLSX, PPTX) to PDF when processing them. This means:
rotate_pages()
,ocr_pdf()
, etc. work seamlessly with DOCX filesThis significantly enhances the library's capabilities beyond the original specification.
Features Implemented
🏗️ Project Structure
src
layout🔧 Core Components
Custom Exception Hierarchy
NutrientError
(base exception)AuthenticationError
(401/403 errors)APIError
(general API errors with status codes)ValidationError
(request validation failures)TimeoutError
(request timeouts)FileProcessingError
(file operation failures)HTTP Client Layer
File Handling Utilities
📚 API Implementation
Supported Operations (via API testing):
convert_to_pdf
- Leverages implicit conversionflatten_annotations
- Flatten PDF annotations and formsrotate_pages
- Rotate specific or all pagesocr_pdf
- Make PDFs searchable (supports English and German)watermark_pdf
- Add text/image watermarksapply_redactions
- Apply existing redaction annotationsmerge_pdfs
- Merge multiple files (PDFs and Office docs)Builder API: Fluent interface for complex workflows
🧪 Testing
📖 Documentation
🚀 CI/CD
Test Results
Usage Examples
Checklist
Next Steps
After this PR is merged, the following tasks remain:
This implementation follows the Software Design Document specifications and includes significant enhancements discovered during API testing.