{"data":{"slug":"github-tmustier-pi-for-excel-skills-python-bridge-0fd28b45556a","title":"Run Python Scripts Locally with Native Bridge","summary":"Execute Python scripts directly on the user's machine using the native Python bridge for advanced capabilities such as accessing the local filesystem, using C extensions, and LibreOffice for document conversion.","url":"https:\/\/skillshunter.net\/skills\/github-tmustier-pi-for-excel-skills-python-bridge-0fd28b45556a","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-tmustier-pi-for-excel-skills-python-bridge-0fd28b45556a","markdown_url":"https:\/\/skillshunter.net\/skills\/github-tmustier-pi-for-excel-skills-python-bridge-0fd28b45556a.md","download_url":"https:\/\/skillshunter.net\/skills\/github-tmustier-pi-for-excel-skills-python-bridge-0fd28b45556a\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"The native bridge requires the user to start a local bridge process using `npx pi-for-excel-python-bridge` and ensure Python is on the PATH. LibreOffice is optional but needed for document conversion tasks.","instructions":"---\nname: python-bridge\ndescription: Native Python execution via the local Python bridge. Use when the user asks about running Python locally, setting up the Python bridge, LibreOffice conversion, or troubleshooting Python connectivity.\ncompatibility: Python tools always work via in-browser Pyodide. The native bridge is optional and requires a local bridge process running on the user's machine.\nmetadata:\n  tool-name: python_run\n  docs: docs\/python-bridge-contract.md\n---\n\n# Python Bridge\n\nThe Python bridge gives Pi access to native Python on the user's machine. It is an opt-in capability that upgrades the default in-browser Pyodide runtime.\n\n## Pyodide (default) vs Native bridge\n\n| | Pyodide (default) | Native bridge |\n|---|---|---|\n| Setup | None \u2014 works out of the box | Requires local bridge process |\n| Packages | Pure-Python only (numpy, pandas, scipy via micropip) | Full ecosystem (C extensions, ML libs, etc.) |\n| Filesystem | No local filesystem access | Full local filesystem |\n| LibreOffice | Not available | Available (`libreoffice_convert` tool) |\n| Long scripts | WebAssembly limits | No limits |\n\n**Prefer Pyodide unless the task requires native-only capabilities.**\n\n## How to set it up\n\n### 1. Start the bridge\n\n```bash\nnpx pi-for-excel-python-bridge\n```\n\nThis defaults to **real execution mode** on `https:\/\/localhost:3340`.\n\nOptions:\n- `--install-missing` \u2014 auto-install Python\/LibreOffice via Homebrew (macOS)\n- `PYTHON_BRIDGE_MODE=stub` \u2014 safe simulated mode\n- `PYTHON_BRIDGE_TOKEN=your-secret` \u2014 require auth token\n- `PYTHON_BRIDGE_PYTHON_BIN=python3.12` \u2014 specify Python binary\n\nRequirements:\n- `python3` must be on `PATH` (or set `PYTHON_BRIDGE_PYTHON_BIN`)\n- LibreOffice (`soffice`) is optional \u2014 only needed for `libreoffice_convert`\n\n### 2. Configure in Pi (optional)\n\nThe default URL (`https:\/\/localhost:3340`) works automatically. Override if needed:\n\n```\n\/experimental python-bridge-url <url>\n\/experimental python-bridge-token <token>\n```\n\nOr use: `\/extensions` \u2192 **Connections** \u2192 **Python bridge**\n\n### 3. First execution\n\nThe first time Python runs through the native bridge, Pi will ask for explicit user confirmation (one-time per bridge URL).\n\n## Tools\n\n- **python_run** \u2014 execute a Python snippet, inspect stdout\/stderr\/result\n- **python_transform_range** \u2014 read Excel range \u2192 run Python \u2192 write result back (single tool call)\n- **libreoffice_convert** \u2014 convert files between formats (xlsx \u2194 csv \u2194 pdf) \u2014 bridge-only\n\n## When the bridge is not running\n\n`python_run` and `python_transform_range` fall back to Pyodide automatically. Only `libreoffice_convert` strictly requires the bridge.\n\n## Security\n\n- Loopback-only (localhost)\n- Origin allowlist\n- Optional bearer token auth\n- Python runs with `-I` isolation flag\n- Code\/input\/output size limits\n- Timeout enforcement\n\n## Troubleshooting\n\n- **Falls back to Pyodide unexpectedly** \u2014 the bridge process isn't running. Start it with `npx pi-for-excel-python-bridge`.\n- **Import errors on Pyodide** \u2014 the package likely has C extensions. Set up the native bridge.\n- **LibreOffice convert fails** \u2014 ensure `soffice` is on PATH. Install with `brew install --cask libreoffice` (macOS).\n- **CORS\/cert errors** \u2014 visit `https:\/\/localhost:3340` in your browser and accept the certificate.\n","use_cases":["Running Python scripts that require C extensions or large computations","Accessing the local filesystem for file operations","Using LibreOffice for document conversion tasks"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/tmustier\/pi-for-excel\/blob\/899295f55e698e3dacad1c45c5ba47f86adc596f\/skills\/python-bridge\/SKILL.md","source_commit":"899295f55e698e3dacad1c45c5ba47f86adc596f","license":null,"version":null,"listing_approved_at":"2026-11-16","created_at":"2026-11-16T06:06:07.000000Z","updated_at":"2026-11-16T08:52:24.000000Z","seo_title":"Run Python Scripts Locally with Native Bridge","seo_description":"Execute Python scripts directly on the user's machine using the native Python bridge for advanced capabilities such as accessing the local filesystem, using C extensions,","seo_keywords":["Run Python locally","Native Python bridge","Execute Python scripts","LibreOffice conversion","Local filesystem access"]}}