- Home
- Plugins
- Tools & Capabilities
- dsh-python-tools
dsh-python-tools
saulgoodman174/dsh-python-tools
Run trusted Python scripts in the workspace, read text from searchable PDFs, and export DOCX to PDF through Microsoft Word on Windows.
Install
dsh plugin --profile web add github:saulgoodman174/dsh-python-toolsREADME
dsh-python-tools
dsh-python-tools turns three everyday desktop chores into host tools the agent can call directly.
python_run executes a script you keep in the workspace's scripts directory. Arguments are passed as an array rather than a shell string, so paths with spaces and non-ASCII characters survive untouched, and every call runs under a timeout with cancellation.
python_pdf_text reads a searchable PDF through pypdf and returns the page count plus the extracted text, truncated to a configurable character limit so a 300-page document cannot flood the conversation.
python_docx_to_pdf exports a DOCX to PDF using the Microsoft Word already installed on Windows. It refreshes fields and the first table of contents only when you ask for it, and it never modifies the source document: the plugin reports the page count and the output path instead.
Interpreter path, scripts directory, an optional allow-list, the pypdf location, timeout, and output limit are all set on the plugin row. Failures come back as stable codes — FILE_NOT_FOUND, SCRIPT_NOT_ALLOWED, TIMEOUT, ABORTED, MISSING_DEPENDENCY, UNSUPPORTED_PLATFORM — so the agent can correct itself instead of guessing what went wrong.
Installation
Choose the route that matches your DSH profile.
- Plugin market (
dshmarket). Open the Plugins page, pick the Plugin Market tab, searchdsh-python-tools, and install it in one click. The same catalog is readable as a market index athttps://cdn.jsdelivr.net/npm/dsh-plugin-catalog/index.json(Plugins → Discover → Index sources). - DSH Desktop, local checkout. Clone the repository. Open Settings → Plugins → Add plugin → Install third-party plugin (设置 → 插件 → 添加插件 → 安装第三方插件). Enter the directory containing
package.json, then enable thedsh-python-toolscomponent. Use this route for the Electron-managed desktop profile. - CLI-managed web profile, local checkout. Run
dsh plugin --profile web add "<workspace>/dsh-python-tools". Replace<workspace>with the absolute parent directory of the checkout. Restartdsh weband enable the component under Settings → Plugins. - CLI-managed web profile, published npm package. After publication, run
dsh plugin --profile web add dsh-python-tools. Restartdsh weband enable the component. If the release uses a scope, supply its full published package name.
Platform support
The plugin requires Node.js ^22.19 || >=24 and a host providing the @deepseek-ai/schemastery peer (^3.18.5).
| Tool | Platform | Requirements |
|---|---|---|
python_run | Windows, macOS, Linux | Python and the dependencies of the selected script |
python_pdf_text | Windows, macOS, Linux | Python and pypdf |
python_docx_to_pdf | Windows | Windows PowerShell and desktop Microsoft Word available through COM to the account running DSH |
Install pypdf into the interpreter configured by pythonPath. For the default interpreter:
python -m pip install pypdf
Alternatively keep it out of the interpreter: run python -m pip install --target .pylibs pypdf in the session workspace. The plugin appends an existing <workspace>/.pylibs to PYTHONPATH when pylibs is empty, and appends the configured directory otherwise.
The Word converter does not require Python. The two document tools find their helpers relative to the installed plugin.
Configuration
| Key | Default | Behavior and security implications |
|---|---|---|
pythonPath | python | Command found on PATH, or a path to a trusted interpreter. A relative path containing a directory separator resolves against the session workspace. |
scriptsDir | tools | Directory used by python_run. The default resolves to <workspace>/tools. Grant write access only to people trusted to run code under the DSH account. |
allowedScripts | [] | An empty array trusts all directly contained .py files in scriptsDir, including files added later. A nonempty list restricts execution to exact filenames. |
pylibs | "" | Optional directory appended to the Python child process's PYTHONPATH. When empty, an existing <workspace>/.pylibs directory is used automatically. Its modules can execute code when imported, so use a trusted directory. |
timeoutMs | 120000 | Per-command time limit in milliseconds. Accepts integers from 1 to 600000. |
outputLimit | 8000 | Maximum Unicode code points returned per output stream, or in extracted PDF text. Temporary files can grow beyond this limit. |
refreshFields | false | When true, python_docx_to_pdf updates document fields and the first table of contents before exporting. Refreshing can reflow pagination, so the PDF may differ from a direct Word export. |
Workspace-relative paths use exec.agent.session.header.cwd. Direct callers should supply an absolute session cwd. Without one, the plugin falls back to the process working directory.
Python receives arguments as individual strings. An allowed script runs with the child process's filesystem and network permissions. Anyone who can replace the script can change its behavior. For example, to expose only the page-count example, copy examples/pdf_pages.py into <workspace>/tools and set allowedScripts to ["pdf_pages.py"].
Tools
Replace <workspace> in these examples with an absolute path. In JSON, escape Windows backslashes or use forward slashes.
python_run
Run the page-count example after copying it into scriptsDir and installing pypdf.
{"script":"pdf_pages.py","args":["<workspace>/sample.pdf"]}
Read stdout for the script's result. The response also reports script, command, exit_code, stderr, duration_ms, timed_out, and truncated after process completion.
Example failure:
{"ok":false,"code":"SCRIPT_NOT_ALLOWED","message":"Select an allowed .py filename directly inside scriptsDir."}
python_pdf_text
{"path":"<workspace>/sample.pdf"}
Returns pages, text, duration_ms, and truncated. Page markers separate the text. A scanned page without a text layer can have an empty body. The tool does not perform OCR.
Example failure when pypdf is unavailable:
{
"ok": false,
"code": "MISSING_DEPENDENCY",
"message": "Install pypdf with the configured interpreter. For the default interpreter run: python -m pip install pypdf.",
"install_args": ["python", "-m", "pip", "install", "pypdf"],
"stderr": "Cannot import pypdf: No module named 'pypdf'\n"
}
python_docx_to_pdf
{"path":"<workspace>/report.docx","out":"<workspace>/report-final.pdf"}
Omit out to create report.pdf beside report.docx. The output directory must exist. Word opens the document in the background, exports a PDF, and leaves the source DOCX untouched. Set refreshFields to true to update fields and the first table of contents before exporting, which can reflow pagination. An existing destination PDF is replaced upon successful export.
The result includes pdf, pages, stdout, stderr, and duration_ms. Starting Word and repaginating a document can take several seconds.
Example failure outside Windows:
{"ok":false,"code":"UNSUPPORTED_PLATFORM","message":"DOCX export requires Windows and desktop Microsoft Word."}
Helper protocols
If you replace a bundled helper, preserve its command-line and output protocol.
runtime/pdf_text.py INPUT.pdfwrites the decimal page count alone on the first stdout line. The body begins on the second line. Page headings are part of the body. Warnings and diagnostics go to stderr. Exit0means success,43means importingpypdffailed, and1means extraction failed. The plugin checks the exit status before parsing stdout.examples/pdf_text.pyimplements the same protocol and can be run directly withpython examples/pdf_text.py x.pdf.runtime/docx_to_pdf.ps1 -Docx INPUT.docx -Pdf OUTPUT.pdfexits0on success. Its last two stdout lines must be exactlypages=Nandpdf ok, with no trailing spaces. The parser accepts LF or CRLF and one final line terminator. Exit43means the helper could not activate Word through COM. Other conversion failures exit1and write details to stderr. A missing PowerShell executable is detected by the plugin before the helper starts.- Exit
43has dependency semantics only for these bundled helpers. A user script selected throughpython_runmay define its own exit codes; a nonzero result is reported asSCRIPT_FAILED.
Error codes
| Code | Meaning | How to fix it |
|---|---|---|
INVALID_ARGUMENT | The supplied fields, types, filename extension, or path form are invalid. | Follow the tool example and use absolute document paths. |
SCRIPT_NOT_ALLOWED | The requested filename violates the script directory or allowlist rules. | Use the actual .py filename directly inside scriptsDir and check allowedScripts. |
FILE_NOT_FOUND | A document, user script, or scripts directory could not be found. | Check the session workspace and the resolved path. |
FILE_ACCESS_FAILED | The plugin could not inspect a required filesystem entry. | Check filesystem permissions and host policy for the DSH account. |
TOOL_NOT_FOUND | The executable or the specified process working directory could not be located. | Verify the workspace exists and check pythonPath or Windows PowerShell. |
MISSING_DEPENDENCY | The PDF helper could not import pypdf, or the Word helper could not activate Word COM. | Run the returned install_args for Python. For Word, install or repair desktop Word and verify COM access under the DSH account. |
UNSUPPORTED_PLATFORM | Word conversion was requested outside Windows. | Run this tool on a Windows host with desktop Word. |
SPAWN_FAILED | Process launch or temporary output handling failed. | Check executable permissions and access to the system temporary directory. |
SCRIPT_FAILED | The started process failed during execution. | Read stderr; check script arguments, document validity, output access, and script-specific dependencies. |
INVALID_OUTPUT | A successful helper returned malformed page metadata or completion markers. | Restore the bundled helper or correct its output protocol. |
TIMEOUT | Execution exceeded timeoutMs. | Inspect blocked dialogs or slow inputs, then adjust timeoutMs if appropriate. |
ABORTED | The caller cancelled the command. | Inspect any output already produced before retrying. |
Troubleshooting
Component fails to load. Look for dsh-python-tools: invalid config: in the component error details or host log. The rest of the message identifies the invalid setting. For example, timeoutMs must be an integer between 1 and 600000. Correct the value and reload the component. Host-side schema validation may also reject a value before apply runs.
Python works in a terminal but cannot import pypdf in DSH. Check the interpreter in the returned install_args. Use that executable to install the package. If using a virtual environment, set pythonPath to its interpreter.
Word starts but conversion fails. Open the source document under the DSH account and check for Protected View, password prompts, read-only access, or a locked destination. The helper needs write access to the output directory.
A conversion was cancelled or timed out. The executor redirects output into temporary files, sends SIGTERM to the immediate child, and 1.5 seconds later terminates the whole process tree when the host permits it: taskkill /T /F on Windows and a process-group kill elsewhere. A host that forbids process enumeration and tree termination can leave the Word instance running after a forced kill; inspect Word and the destination before retrying.
The tests fail with spawn EPERM. Some hosts restrict child-process pipes. Run node test.mjs directly instead of npm test; the assertions are the same.
Tests
From a repository checkout with Node.js, Python, and the declared peer available:
npm install
npm test
The automated tests use a temporary script directory and a registration fixture. They do not require a running DSH host, Microsoft Word, or an installed copy of pypdf. Set PYTHON to a Python executable if python is not on PATH. Real Word conversion and PDF extraction require separate integration checks with the external software installed.
License
MIT. See LICENSE.
Related plugins
archify (deepseek-harness)
tt-a1i/archify
WeKnora (dsh-weknora)
tencent/weknora
next-ai-draw-io (dsh-plugin)
dayuanjiang/next-ai-draw-io
weknora
tencent/weknora