This example project demonstrates how to use the Nutrient DWS Python Client for document processing operations.
assets/- Contains sample files for processing (PDF, DOCX, PNG)src/- Contains Python source filesdirect_method.py- Examples using direct method callsworkflow.py- Examples using the workflow builder patternframework_openai_agents.py- OpenAI Agents SDK integration sketchframework_langchain.py- LangChain/LangGraph integration sketchframework_crewai.py- CrewAI integration sketch
output/- Directory where processed files will be saved.env.example- Example environment variables file
- Python 3.10 or higher
- pip
-
Clone the repository:
git clone https://github.com/pspdfkit-labs/nutrient-dws-client-python.git cd nutrient-dws-client-python -
Build the package from source:
python -m build
-
Navigate to the examples directory:
cd examples -
Set up and activate the virtual environment:
# Set up the virtual environment and install dependencies python setup_venv.py # Activate the virtual environment # On macOS/Linux: source example_venv/bin/activate # On Windows: example_venv\Scripts\activate
-
Create a
.envfile from the example:cp .env.example .env
-
Edit the
.envfile and add your Nutrient DWS Processor API key. You can sign up for a free API key by visiting Nutrient:NUTRIENT_API_KEY=your_api_key_here
-
Clone the repository:
git clone https://github.com/pspdfkit-labs/nutrient-dws-client-python.git cd nutrient-dws-client-python -
Install the main package in development mode:
pip install -e . -
Navigate to the examples directory:
cd examples -
Install dependencies for the example project:
pip install -r requirements.txt
-
Create a
.envfile from the example:cp .env.example .env
-
Edit the
.envfile and add your Nutrient DWS Processor API key. You can sign up for a free API key by visiting Nutrient:NUTRIENT_API_KEY=your_api_key_here
To run the direct method examples:
python src/direct_method.pyThis will:
- Convert a DOCX file to PDF
- Extract text from the PDF
- Add a watermark to the PDF
- Merge multiple documents
To run the workflow examples:
python src/workflow.pyThis will:
- Perform a basic document conversion workflow
- Create a document merging with watermark workflow
- Extract text with JSON output
- Execute a complex multi-step workflow
These examples are intentionally minimal and focus on framework wiring:
Set both NUTRIENT_API_KEY and OPENAI_API_KEY in examples/.env before running them. Each example loads .env and fails clearly when either key is missing. The examples use gpt-6-luna and can make billable DWS and model calls when run normally. CrewAI attaches a real text-extraction tool before planning subsequent processing. The LangChain tool saves the redacted PDF to output/redacted.pdf and returns only its path and byte count to the model.
Choose one framework per fresh virtual environment. Their OpenAI dependency ranges can differ, so installing all three together can cause lengthy dependency backtracking. From examples/, follow only the option you want; use Python 3.10–3.13 for CrewAI. Activation commands below are for macOS/Linux; on Windows use the environment's Scripts\activate.
OpenAI Agents:
python -m venv example_venv_agents
source example_venv_agents/bin/activate
pip install -e '..[dev]' openai-agents
python src/framework_openai_agents.pyLangChain/LangGraph, in a separate environment:
python -m venv example_venv_langchain
source example_venv_langchain/bin/activate
pip install -e '..[dev]' langchain langchain-openai langgraph
python src/framework_langchain.pyCrewAI, in a separate environment:
python -m venv example_venv_crewai
source example_venv_crewai/bin/activate
pip install -e '..[dev]' crewai
python src/framework_crewai.pySyntax-check only:
python -m py_compile src/framework_openai_agents.py
python -m py_compile src/framework_langchain.py
python -m py_compile src/framework_crewai.pyFrom the repository root, after installing the optional frameworks and development dependencies, run the offline framework smoke tests:
python -m pytest tests/unit/test_framework_examples.py -vThese tests register and invoke the actual framework tools with a controlled Nutrient client. They block network connections and do not run an LLM or upload a document. Framework-specific cases skip if their optional dependency is absent.
All processed files will be saved to the output/ directory. You can examine these files to see the results of the document processing operations.
For more information about the Nutrient DWS Python Client, refer to:
- README.md - Main documentation
- METHODS.md - Direct methods documentation
- WORKFLOW.md - Workflow system documentation