Python client library for Nutrient Document Web Services API
Project description
Nutrient DWS Python Client
A Python client library for Nutrient Document Web Services (DWS) API. This library provides a fully async, type-safe, and ergonomic interface for document processing operations including conversion, merging, compression, watermarking, OCR, and text extraction.
Note: This package is published as
nutrient-dwson PyPI. The package provides full type support and is designed for async Python environments (Python 3.10+).
Features
- ๐ Powerful document processing: Convert, OCR, edit, compress, watermark, redact, and digitally sign documents
- ๐ค LLM friendly: Built-in support for popular Coding Agents (Claude Code, GitHub Copilot, JetBrains Junie, Cursor, Windsurf) with auto-generated rules
- ๐ 100% mapping with DWS Processor API: Complete coverage of all Nutrient DWS Processor API capabilities
- ๐ ๏ธ Convenient functions with sane defaults: Simple interfaces for common operations with smart default settings
- โ๏ธ Chainable operations: Build complex document workflows with intuitive method chaining
- ๐ Fully async: Built from the ground up with async/await support for optimal performance
- ๐ Flexible authentication and security: Support for API keys and async token providers with secure handling
- โ Highly tested: Comprehensive test suite ensuring reliability and stability
- ๐ Type-safe: Full type annotations with comprehensive type definitions
- ๐ Pythonic: Follows Python conventions and best practices
Installation
pip install nutrient-dws
Integration with Coding Agents
This package has built-in support with popular coding agents like Claude Code, GitHub Copilot, Cursor, and Windsurf by exposing scripts that will inject rules instructing the coding agents on how to use the package. This ensures that the coding agent doesn't hallucinate documentation, as well as making full use of all the features offered in Nutrient DWS Python Client.
# Adding code rule to Claude Code
dws-add-claude-code-rule
# Adding code rule to GitHub Copilot
dws-add-github-copilot-rule
# Adding code rule to Junie (Jetbrains)
dws-add-junie-rule
# Adding code rule to Cursor
dws-add-cursor-rule
# Adding code rule to Windsurf
dws-add-windsurf-rule
The documentation for Nutrient DWS Python Client is also available on Context7
Quick Start
from nutrient_dws import NutrientClient
client = NutrientClient(api_key='your_api_key')
Direct Methods
The client provides numerous async methods for document processing:
import asyncio
from nutrient_dws import NutrientClient
async def main():
client = NutrientClient(api_key='your_api_key')
# Convert a document
pdf_result = await client.convert('document.docx', 'pdf')
# Extract text
text_result = await client.extract_text('document.pdf')
# Add a watermark
watermarked_doc = await client.watermark_text('document.pdf', 'CONFIDENTIAL')
# Merge multiple documents
merged_pdf = await client.merge(['doc1.pdf', 'doc2.pdf', 'doc3.pdf'])
asyncio.run(main())
For a complete list of available methods with examples, see the Methods Documentation.
Workflow System
The client also provides a fluent builder pattern with staged interfaces to create document processing workflows:
from nutrient_dws.builder.constant import BuildActions
async def main():
client = NutrientClient(api_key='your_api_key')
result = await (client
.workflow()
.add_file_part('document.pdf')
.add_file_part('appendix.pdf')
.apply_action(BuildActions.watermark_text('CONFIDENTIAL', {
'opacity': 0.5,
'fontSize': 48
}))
.output_pdf({
'optimize': {
'mrcCompression': True,
'imageOptimizationQuality': 2
}
})
.execute())
asyncio.run(main())
The workflow system follows a staged approach:
- Add document parts (files, HTML, pages)
- Apply actions (optional)
- Set output format
- Execute or perform a dry run
For detailed information about the workflow system, including examples and best practices, see the Workflow Documentation.
Error Handling
The library provides a comprehensive error hierarchy:
from nutrient_dws import (
NutrientClient,
NutrientError,
ValidationError,
APIError,
AuthenticationError,
NetworkError
)
async def main():
client = NutrientClient(api_key='your_api_key')
try:
result = await client.convert('file.docx', 'pdf')
except ValidationError as error:
# Invalid input parameters
print(f'Invalid input: {error.message} - Details: {error.details}')
except AuthenticationError as error:
# Authentication failed
print(f'Auth error: {error.message} - Status: {error.status_code}')
except APIError as error:
# API returned an error
print(f'API error: {error.message} - Status: {error.status_code} - Details: {error.details}')
except NetworkError as error:
# Network request failed
print(f'Network error: {error.message} - Details: {error.details}')
asyncio.run(main())
Testing
The library includes comprehensive unit and integration tests:
# Run all tests
python -m pytest
# Run with coverage report
python -m pytest --cov=nutrient_dws --cov-report=html
# Run only unit tests
python -m pytest tests/unit/
# Run integration tests (requires API key)
NUTRIENT_API_KEY=your_key python -m pytest tests/test_integration.py
The library maintains high test coverage across all API methods, including:
- Unit tests for all public methods
- Integration tests for real API interactions
- Type checking with mypy
Development
For development, install the package in development mode:
# Clone the repository
git clone https://github.com/PSPDFKit/nutrient-dws-client-python.git
cd nutrient-dws-client-python
# Install in development mode
pip install -e ".[dev]"
# Run type checking
mypy src/
# Run linting
ruff check src/
# Run formatting
ruff format src/
Contributing
We welcome contributions to improve the library! Please follow our development standards to ensure code quality and maintainability.
Quick start for contributors:
- Clone and setup the repository
- Make changes following atomic commit practices
- Use conventional commits for clear change history
- Include appropriate tests for new features
- Ensure type checking passes with mypy
- Follow Python code style with ruff
For detailed contribution guidelines, see the Contributing Guide.
Project Structure
src/
โโโ nutrient_dws/
โ โโโ builder/ # Builder classes and constants
โ โโโ generated/ # Generated type definitions
โ โโโ types/ # Type definitions
โ โโโ client.py # Main NutrientClient class
โ โโโ errors.py # Error classes
โ โโโ http.py # HTTP layer
โ โโโ inputs.py # Input handling
โ โโโ workflow.py # Workflow factory
โ โโโ __init__.py # Public exports
โโโ nutrient_dws_scripts/ # CLI scripts for coding agents
โโโ tests/ # Test files
Python Version Support
This library supports Python 3.10 and higher. The async-first design requires modern Python features for optimal performance and type safety.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and feature requests, please use the GitHub issue tracker.
For questions about the Nutrient DWS Processor API, refer to the official documentation.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nutrient_dws-3.0.0.tar.gz.
File metadata
- Download URL: nutrient_dws-3.0.0.tar.gz
- Upload date:
- Size: 65.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d97e9df18609bb890e8bf6ccf9fe015444c7cf56b963e2f34ec0546b8bb88909
|
|
| MD5 |
79762c02a98276e5fa2c660254e03817
|
|
| BLAKE2b-256 |
c0eab36378a22e1c9badba3549b985e0cd6cec4e3b8e6dbf4e412e8f930760d6
|
Provenance
The following attestation bundles were made for nutrient_dws-3.0.0.tar.gz:
Publisher:
publish.yml on PSPDFKit/nutrient-dws-client-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nutrient_dws-3.0.0.tar.gz -
Subject digest:
d97e9df18609bb890e8bf6ccf9fe015444c7cf56b963e2f34ec0546b8bb88909 - Sigstore transparency entry: 962163723
- Sigstore integration time:
-
Permalink:
PSPDFKit/nutrient-dws-client-python@7457a5294e8971ecec54e666e59b08fda5e4a61e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/PSPDFKit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7457a5294e8971ecec54e666e59b08fda5e4a61e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file nutrient_dws-3.0.0-py3-none-any.whl.
File metadata
- Download URL: nutrient_dws-3.0.0-py3-none-any.whl
- Upload date:
- Size: 74.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ac99567c8b3ecfaa0a53541ba569f26a761398e0e021cbae89072aa6fd29873
|
|
| MD5 |
0b1b3d222bc3fd22cdfc3327b9998ba3
|
|
| BLAKE2b-256 |
c2c19ee696e4a077f531ecd48542fa1cc73fd0ee024430204fffe46b0c928376
|
Provenance
The following attestation bundles were made for nutrient_dws-3.0.0-py3-none-any.whl:
Publisher:
publish.yml on PSPDFKit/nutrient-dws-client-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nutrient_dws-3.0.0-py3-none-any.whl -
Subject digest:
4ac99567c8b3ecfaa0a53541ba569f26a761398e0e021cbae89072aa6fd29873 - Sigstore transparency entry: 962163733
- Sigstore integration time:
-
Permalink:
PSPDFKit/nutrient-dws-client-python@7457a5294e8971ecec54e666e59b08fda5e4a61e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/PSPDFKit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7457a5294e8971ecec54e666e59b08fda5e4a61e -
Trigger Event:
workflow_dispatch
-
Statement type: