Skip to content

Commit bc44a35

Browse files
committed
refactor: rename package from nutrient to nutrient_dws
- Changed source directory from src/nutrient to src/nutrient_dws - Updated all imports throughout the codebase - Fixed all unit tests to use new package name - Updated pyproject.toml package configuration - Fixed test expectations for new API URLs and authentication - Applied linting fixes from ruff - Updated type annotations to fix mypy errors The package is now correctly named nutrient-dws for PyPI distribution while using nutrient_dws as the import name (following Python conventions).
1 parent cce6898 commit bc44a35

19 files changed

+102
-93
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pip install nutrient-dws
2121
## Quick Start
2222

2323
```python
24-
from nutrient import NutrientClient
24+
from nutrient_dws import NutrientClient
2525

2626
# Initialize the client
2727
client = NutrientClient(api_key="your-api-key")
@@ -173,7 +173,7 @@ client.import_from_url("https://example.com/document.pdf")
173173
The library provides specific exceptions for different error scenarios:
174174

175175
```python
176-
from nutrient import (
176+
from nutrient_dws import (
177177
NutrientError,
178178
AuthenticationError,
179179
APIError,

SPECIFICATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The library is architected around a central `NutrientClient` class, which is the
8181
The client will be initialized with an optional API key and timeout. It will follow modern Python library best practices for configuration.
8282

8383
```python
84-
from nutrient import NutrientClient, AuthenticationError
84+
from nutrient_dws import NutrientClient, AuthenticationError
8585

8686
# Option 1: API key passed directly (takes precedence)
8787
client = NutrientClient(api_key="YOUR_DWS_API_KEY", timeout=300)
@@ -143,7 +143,7 @@ The Builder API provides a more elegant and efficient solution for multi-step wo
143143

144144
**Example Usage:**
145145
```python
146-
from nutrient import APIError
146+
from nutrient_dws import APIError
147147

148148
# User Story: Convert a DOCX to PDF and rotate it (Builder version)
149149
try:

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Repository = "https://github.com/jdrhyne/nutrient-dws-client-python"
5959
where = ["src"]
6060

6161
[tool.setuptools.package-data]
62-
nutrient = ["py.typed"]
62+
nutrient_dws = ["py.typed"]
6363

6464
[tool.ruff]
6565
target-version = "py38"
@@ -110,7 +110,7 @@ testpaths = ["tests"]
110110
addopts = [
111111
"-ra",
112112
"--strict-markers",
113-
"--cov=nutrient",
113+
"--cov=nutrient_dws",
114114
"--cov-report=term-missing",
115115
"--cov-report=html",
116116
"--cov-report=xml",
@@ -120,7 +120,7 @@ markers = [
120120
]
121121

122122
[tool.coverage.run]
123-
source = ["src/nutrient"]
123+
source = ["src/nutrient_dws"]
124124
branch = true
125125

126126
[tool.coverage.report]

scripts/generate_api_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def generate_api_methods(spec_path: Path, output_path: Path) -> None:
337337
'',
338338
'from typing import List, Optional',
339339
'',
340-
'from nutrient.file_handler import FileInput',
340+
'from nutrient_dws.file_handler import FileInput',
341341
'',
342342
'',
343343
'class DirectAPIMixin:',

src/nutrient/__init__.py renamed to src/nutrient_dws/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
A Python client library for the Nutrient Document Web Services API.
44
"""
55

6-
from nutrient.client import NutrientClient
7-
from nutrient.exceptions import (
6+
from nutrient_dws.client import NutrientClient
7+
from nutrient_dws.exceptions import (
88
APIError,
99
AuthenticationError,
1010
FileProcessingError,
@@ -15,11 +15,11 @@
1515

1616
__version__ = "0.1.0"
1717
__all__ = [
18-
"NutrientClient",
19-
"NutrientError",
2018
"APIError",
2119
"AuthenticationError",
2220
"FileProcessingError",
21+
"NutrientClient",
22+
"NutrientError",
2323
"TimeoutError",
2424
"ValidationError",
2525
]
File renamed without changes.

src/nutrient/api/direct.py renamed to src/nutrient_dws/api/direct.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
from typing import TYPE_CHECKING, Any, List, Optional
88

9-
from nutrient.file_handler import FileInput
9+
from nutrient_dws.file_handler import FileInput
1010

1111
if TYPE_CHECKING:
12-
from nutrient.client import NutrientClient
12+
from nutrient_dws.client import NutrientClient
1313

1414

1515
class DirectAPIMixin:
@@ -60,7 +60,9 @@ def convert_to_pdf(
6060
# Use builder with no actions - implicit conversion happens
6161
return self.build(input_file).execute(output_path) # type: ignore
6262

63-
def flatten_annotations(self, input_file: FileInput, output_path: Optional[str] = None) -> Optional[bytes]:
63+
def flatten_annotations(
64+
self, input_file: FileInput, output_path: Optional[str] = None
65+
) -> Optional[bytes]:
6466
"""Flatten annotations and form fields in a PDF.
6567
6668
Converts all annotations and form fields into static page content.
@@ -106,7 +108,7 @@ def rotate_pages(
106108
"""
107109
options = {"degrees": degrees}
108110
if page_indexes is not None:
109-
options["page_indexes"] = page_indexes
111+
options["page_indexes"] = page_indexes # type: ignore
110112
return self._process_file("rotate-pages", input_file, output_path, **options)
111113

112114
def ocr_pdf(
@@ -174,19 +176,19 @@ def watermark_pdf(
174176
"""
175177
if not text and not image_url:
176178
raise ValueError("Either text or image_url must be provided")
177-
179+
178180
options = {
179181
"width": width,
180182
"height": height,
181183
"opacity": opacity,
182184
"position": position,
183185
}
184-
186+
185187
if text:
186188
options["text"] = text
187189
else:
188190
options["image_url"] = image_url
189-
191+
190192
return self._process_file("watermark-pdf", input_file, output_path, **options)
191193

192194
def apply_redactions(
@@ -246,35 +248,35 @@ def merge_pdfs(
246248
"""
247249
if len(input_files) < 2:
248250
raise ValueError("At least 2 files required for merge")
249-
250-
from nutrient.file_handler import prepare_file_for_upload, save_file_output
251-
251+
252+
from nutrient_dws.file_handler import prepare_file_for_upload, save_file_output
253+
252254
# Prepare files for upload
253255
files = {}
254256
parts = []
255-
257+
256258
for i, file in enumerate(input_files):
257259
field_name = f"file{i}"
258260
file_field, file_data = prepare_file_for_upload(file, field_name)
259261
files[file_field] = file_data
260262
parts.append({"file": field_name})
261-
263+
262264
# Build instructions for merge (no actions needed)
263265
instructions = {
264266
"parts": parts,
265267
"actions": []
266268
}
267-
269+
268270
# Make API request
269-
result = self._http_client.post( # type: ignore
271+
result = self._http_client.post(
270272
"/build",
271273
files=files,
272274
json_data=instructions,
273275
)
274-
276+
275277
# Handle output
276278
if output_path:
277279
save_file_output(result, output_path)
278280
return None
279281
else:
280-
return result
282+
return result

src/nutrient/builder.py renamed to src/nutrient_dws/builder.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any, Dict, List, Optional
44

5-
from nutrient.file_handler import FileInput, prepare_file_for_upload, save_file_output
5+
from nutrient_dws.file_handler import FileInput, prepare_file_for_upload, save_file_output
66

77

88
class BuildAPIWrapper:
@@ -127,7 +127,7 @@ def _build_instructions(self) -> Dict[str, Any]:
127127

128128
# Add output options if specified
129129
if self._output_options:
130-
instructions["output"] = self._output_options
130+
instructions["output"] = self._output_options # type: ignore
131131

132132
return instructions
133133

@@ -169,7 +169,7 @@ def _map_tool_to_action(self, tool: str, options: Dict[str, Any]) -> Dict[str, A
169169
# Map common language codes to API format
170170
lang_map = {
171171
"en": "english",
172-
"de": "deu",
172+
"de": "deu",
173173
"eng": "eng",
174174
"deu": "deu",
175175
"german": "deu",
@@ -181,15 +181,15 @@ def _map_tool_to_action(self, tool: str, options: Dict[str, Any]) -> Dict[str, A
181181
# Watermark requires width/height
182182
action["width"] = options.get("width", 200) # Default width
183183
action["height"] = options.get("height", 100) # Default height
184-
184+
185185
if "text" in options:
186186
action["text"] = options["text"]
187187
elif "image_url" in options:
188-
action["image"] = {"url": options["image_url"]}
188+
action["image"] = {"url": options["image_url"]} # type: ignore
189189
else:
190190
# Default to text watermark if neither specified
191191
action["text"] = "WATERMARK"
192-
192+
193193
if "opacity" in options:
194194
action["opacity"] = options["opacity"]
195195
if "position" in options:

src/nutrient/client.py renamed to src/nutrient_dws/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import os
44
from typing import Any, Optional
55

6-
from nutrient.api.direct import DirectAPIMixin
7-
from nutrient.builder import BuildAPIWrapper
8-
from nutrient.file_handler import FileInput, prepare_file_for_upload, save_file_output
9-
from nutrient.http_client import HTTPClient
6+
from nutrient_dws.api.direct import DirectAPIMixin
7+
from nutrient_dws.builder import BuildAPIWrapper
8+
from nutrient_dws.file_handler import FileInput
9+
from nutrient_dws.http_client import HTTPClient
1010

1111

1212
class NutrientClient(DirectAPIMixin):
@@ -29,7 +29,7 @@ class NutrientClient(DirectAPIMixin):
2929
AuthenticationError: When making API calls without a valid API key.
3030
3131
Example:
32-
>>> from nutrient import NutrientClient
32+
>>> from nutrient_dws import NutrientClient
3333
>>> client = NutrientClient(api_key="your-api-key")
3434
>>> # Direct API
3535
>>> pdf = client.convert_to_pdf(input_file="document.docx")
File renamed without changes.

0 commit comments

Comments
 (0)