Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>SWIG for Python (swigpylint)New to Visual Studio Code? Get it now.
SWIG for Python (swigpylint)

SWIG for Python (swigpylint)

Arthur Nishikawa

|
3 installs
| (0) | Free
SWIG .i files for Python bindings: highlighting with embedded Python/C++, ruff/ty diagnostics and ruff/clang-format formatting via swigpylint
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

SWIG for Python (swigpylint)

Editor support for SWIG interface files (.i, .swg, .swig) with embedded Python and C++. It is powered by the swigpylint command-line tool, which runs ruff, ty and clang-format.

Only SWIG's Python target is supported. Interfaces written for other target languages (Java, C#, …) are out of scope.

Features

  • Highlighting. A SWIG grammar that hands %pythoncode/%pythonbegin/… blocks to the Python grammar and %{ %}/%inline/%typemap/… blocks to the C++ grammar. SWIG variables such as $1, $result and $action are highlighted too. Comment toggling, brackets and folding work inside the blocks.
  • Diagnostics from ruff and ty on open and save, mapped back to the right line and column in the .i file. Ruff rules show as warnings. Syntax errors and undefined names (F821) show as errors, as in the ruff extension.
  • Quick fixes for ruff diagnostics, and Disable for this line, which adds # noqa: CODE.
  • Format Document. Runs ruff format on each Python block and sorts its imports, keeping each block's indentation. Optionally runs clang-format on C++ blocks, with $1, $result and the like left untouched.
  • Pylance in Python blocks: go to definition (Ctrl+click), hover, and semantic highlighting (modules, classes, functions…).
  • Interpreter in the status bar. SWIG (Python 3.x.y) shows the interpreter selected in the Python extension. ty uses the same one. Click it to change it.

How it works

swigpylint builds a shadow Python module from the Python blocks of the .i file. That module includes from <generated module> import *, and wraps each %extend X block in a subclass of X, so self and super() resolve. ruff and ty check .swigpylint/<name>_i.py. Pylance reads a copy, .swigpylint/<name>_i_lsp.py, which is kept in sync with the editor. Every result is mapped back to the .i file. SWIG: Show Shadow Python Module shows the generated module.

Requirements

  • The swigpylint CLI, either in the workspace's .venv or on PATH, for example uv tool install git+https://github.com/arthursn/swigpylint or uv add --dev git+https://github.com/arthursn/swigpylint. ruff and ty come with it. Install clang-format to format C++ blocks.
  • For type checking, the SWIG-generated Python module must be built, because ty and Pylance resolve names from it.
  • Optional: the Python extension and Pylance, for the interpreter, go to definition, hover and semantic highlighting.

Project configuration

In the project's pyproject.toml:

[tool.swigpylint]
files = ["mymodule.i"]         # default targets for `swigpylint check` / `swigpylint format`
cpp = false                    # also clang-format C++ blocks
sort_imports = true            # sort Python imports when formatting
symbols = []                   # names that only exist in SWIG's final output (declared as Any)

[tool.swigpylint.modules]         # .i file -> SWIG-generated Python module
"mymodule.i" = "mypackage.mymodule"

Without a modules entry, names generated by SWIG show up as undefined.

Settings

Setting Default Description
swigpylint.command [] Command to run swigpylint, e.g. ["uv", "run", "--no-sync", "swigpylint"]. Empty: the workspace's .venv/bin/swigpylint if present, otherwise swigpylint on PATH.
swigpylint.checkOnSave true Run swigpylint check when a SWIG file is opened or saved.
swigpylint.formatCpp null Also clang-format C++ blocks. null follows cpp in pyproject.toml.
swigpylint.sortImports null Sort Python imports when formatting. null follows sort_imports in pyproject.toml (default true).
swigpylint.languageFeatures true Forward go to definition, hover and semantic highlighting to Pylance.

swigpylint is set as the default formatter for the swig language.

Commands

  • SWIG: Check Embedded Python (ruff + ty)
  • SWIG: Show Shadow Python Module

Known issues

  • No highlighting in .i files? The Swig(.tpl) extension (zhangciwu.swig-tpl) is for the Swig JavaScript template engine, not SWIG. It claims the same language and the .i extension, and its grammar wins. Disable or uninstall it.
  • Quick fixes are offered only while the file matches the last check. Save to refresh them.
  • Completion, rename and find references aren't forwarded to Pylance yet.
  • C++ blocks get highlighting and formatting, but no IntelliSense.
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft