Skip to main content

Python framework for building VS Code extensions

Project description

pyxend

PyPI Version License Last Commit GitHub Stars VS Code Compatible Written in Python Downloads

pyxend is a Python-based framework and CLI tool for building Visual Studio Code extensions entirely in Python. It allows to define VS code extension commands using simple Python decorators and handle VS Code actions like modifying editor content, showing modals, and running terminal commands.

⚡️ No JavaScript required for extension logic — write VS Code extensions in pure Python.

Preview

✨ Features

  • 🧠 Simple Python API for defining commands
  • ⚙️ CLI tool to scaffold, sync, build, and publish extensions
  • 🧩 Template-based generation of extension.js and package.json
  • 🔁 Context-aware Python execution with editor data (selected text, cursor, file)
  • 📦 Easy packaging using vsce

📦 Installation

pip install pyxend

Or using git repository:

git clone https://github.com/codeflane/pyxend
cd pyxend
pip install -e .

Make sure Node.js and vsce are installed:

npm install -g vsce

🚀 Getting Started

1. Create a new extension

pyxend init "My Extension Name" myextension

2. Add logic in Python

Edit main.py:

from pyxend import Extension, ModalType

ext = Extension()

@ext.command('hello')
def say_hello(ctx):
    ext.show_modal("Hello from Python!", type=ModalType.INFO)

ext.run()

3. Sync the metadata

pyxend sync

4. Build and install the extension

pyxend build
code --install-extension your-extension.vsix

📚 CLI Options

All CLI commands accept a --target (or -t) option to specify the working directory (defaults to current folder).

Init

pyxend init "Display Name" extension_name

Init new project.

Arguments:

  • Display Name: extension display name (that showing in extension hub)
  • Extension Name: extension name (defaults to display name)

Creates:

  • main.py (logic)
  • extension.js (bridge)
  • package.json (extension metadata)
  • .vscodeignore

Sync

pyxend sync

Sync Python decorators in main.py with extension.js and package.json

Metadata

pyxend metadata -v 0.0.1 -e 1.70.0 -d desc -t title -n name -g git

Update package.json metadata

Options:

Option Description
--engine / -e VS Code engine version
--description / -d Description of your extension
--git / -g GitHub repo URL
--name / -n Display name
--version / -v Extension version

License

pyxend license author

Create LICENSE file (now only MIT support). License is required for creating extensions

🧩 Extension API

The core API is exposed via the Extension class.

Command decorator

Decorator to register a command that can be invoked from VS Code.

Arguments:

  • name – The command name (e.g., "sayHello").
  • title – Title to display in the Command Palette. Defaults to name

Context:

When the command is invoked, it receives a context dictionary with useful metadata:

{
  "selected_text": "Hello", // Currently selected text
  "language": "python", // Opened file language
  "cursor_pos": {"line": 3, "character": 15}, // CUrrent cursor position
  "file_path": "D:/projects/example.py", // Opened file path
  "all_text": "Hello World", // File content
  "cursor_word": "Hello", // the word under the cursor
  "lines": 3, // Lines count in file
  "file_size": 12 // File size in bytes
}

Example:

@ext.command("sayHello", title="Say Hello")
def say_hello(context):
    ext.show_modal(f"Hi! You selected: {context['selected_text']}")

Show modal

Show modal popup

Arguments:

  • message – The message to display.
  • type – Must be one of the ModalType values:
    • ModalType.INFO
    • ModalType.WARNING
    • ModalType.ERROR

Make sure to import ModalType:

from pyxend import ModalType

Example:

ext.show_modal("This is an error", type=ModalType.error) #Show error modal with text "This is an error"

Replace selected text

Replace the currently selected text in the editor.

Arguments:

  • text – The text that will replace the current selection.

Example:

ext.replace_selected_text("Replaced content.") #Replace currently selected text to "Replace content."

Insert text

Insert text at the current cursor position.

Arguments:

  • text – The text to insert.

Example:

ext.insert_text("Inserted text.") #Insert text "Inserted text." after cursor position

Open file

Open a file in the editor by its path.

Arguments:

  • path – Full path to the file.

Example:

ext.open_file("D:/projects/example.py") #open "D:/projects/example.py" in editor

Set cursor position

Move the editor’s cursor to the specified position.

Arguments:

  • line – Line number.
  • character – Character number.

Example:

ext.set_cursor_pos(5, 10) #move cursor to line 5, character 10

Save file

Save the current file.

Example:

ext.save_file() #save current file

Replace all text

Replace the entire content of the file.

Arguments:

  • text – The new content for the whole file.

Example:

ext.replace_text("print('Hello, World!')\n") #replace all file text to "print('Hello, World!')"

Run terminal command

ext.run_terminal_command(command: str, name: str = 'pyxend terminal') Execute a command in a new or existing terminal.

Arguments:

  • command – The terminal command to execute.
  • name (optional) – Name of the terminal instance. Default is "pyxend terminal"

Example:

ext.run_terminal_command("echo 'Hello World'") #create new terminal and echo "Hello World"

📄 Changelog

See ful change log in CHANGELOG.md

Latest (0.1.2)

Added 3 new values in context, renamed manifestmetadata

Previous (0.1.1)

Fixed packaging bug, improved error modals, typo fixes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyxend-0.1.2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyxend-0.1.2-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file pyxend-0.1.2.tar.gz.

File metadata

  • Download URL: pyxend-0.1.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pyxend-0.1.2.tar.gz
Algorithm Hash digest
SHA256 58a01f4cd7cefe995bcf06996723e29e07badc900694f450dedce5d33b84b1ec
MD5 c628c13d0f6a2fd0e2f796664a6c4891
BLAKE2b-256 80dde8dd886fd09dc3280a3960f31c20a5d988d90d6e23fdc69139cb23df386d

See more details on using hashes here.

File details

Details for the file pyxend-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyxend-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pyxend-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c531b975aa66db4ced4b9b9e915435478f41f5bc9de90e413d1fece95d9a934
MD5 a888256ef18ff753fd9537e90d1a524e
BLAKE2b-256 1a431bd27f05460a8dc5e99a5d7f26f3bd503233239618db29d0d74b2010eca5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page