Python framework for building VS Code extensions
Project description
🐍 pyxend
⚡️ No JavaScript required for extension logic — write VS Code extensions in pure Python.
✨ Features
- 🧠 Simple Python API for defining commands
- ⚙️ CLI tool to scaffold, sync, build, and publish extensions
- 🧩 Template-based generation of
extension.jsandpackage.json - 🔁 Context-aware Python execution with editor data (selected text, cursor, file)
- 📦 Easy packaging using
vsce
📦 Installation
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
This generates a minimal VS Code extension with:
- extension.js
- package.json
- .vscodeignore
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
This will:
- Regenerate extension.js
- Update package.json commands and activation events
4. Build and install the extension
pyxend build
code --install-extension your-extension.vsix
🧩 Extension API
The core API is exposed via the Extension class.
ext.command(name: str, title: Optional[str] = None)
Decorator to register a command that can be invoked from VS Code.
Arguments:
name– The command name (e.g.,"sayHello").title– Optional title to display in the Command Palette.
Context:
When the command is invoked, it receives a context dictionary with useful metadata:
{
"selected_text": "Hello",
"language": "python",
"cursor_pos": {"line": 3, "character": 15},
"file_path": "D:/projects/example.py",
"all_text": "Hello World"
}
Example:
@ext.command("sayHello", title="Say Hello")
def say_hello(context):
ext.show_modal(f"Hi! You selected: {context['selected_text']}")
ext.show_modal(message: str, type: ModalType = ModalType.INFO)
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"
ext.replace_selected_text(text: str)
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."
ext.insert_text(text: str)
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
ext.open_file(path: str)
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
ext.set_cursor_pos(line: int, character: int)
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
ext.save_file()
Save the current file.
Example:
ext.save_file() #save current file
ext.replace_text(text: str)
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!')"
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"
🤝 Contributing
Pull requests welcome! Open issues or ideas on GitHub.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyxend-0.1.0.tar.gz.
File metadata
- Download URL: pyxend-0.1.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
815a337933a63ae1f7c297dfba31a6fbb9b8df4f92ab2180025efab237f9faac
|
|
| MD5 |
f3057d69e78de48d48f646e683a155f6
|
|
| BLAKE2b-256 |
d6e7ea13a5d144734e0dfad1234a6730770fb6325d205177070d59243ae43400
|
File details
Details for the file pyxend-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyxend-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5ee84804abc5a958e08a4f997b8b3922ba6c88c0aa4815860a3bac05d54bd30
|
|
| MD5 |
ab8df5b948b4bf69d7f6793e64da8358
|
|
| BLAKE2b-256 |
9cc80bcdde5ab915c2d90e10a6938907573b7bcb06c46829f72a0815bc950fc1
|