PitchHut logo
x-python
A seamless solution for running Python code in the browser.
Pitch

x-python offers a powerful and clean API to execute Python code directly in the browser. It supports features like code completions, formatting, and package installation. Designed for modern web applications, it addresses challenges often encountered with existing solutions, providing a more efficient and user-friendly experience.

Description

Overview

x-Python offers a comprehensive solution for executing Python code directly in the browser, making it an ideal choice for developers looking to integrate Python functionalities into web applications. By leveraging WebAssembly, x-Python allows seamless interaction with Python through a clean API that supports execution, code completion, formatting, and package installations.

Key Features

  • Clean API: Simple and intuitive methods for executing Python code, obtaining code completions, and automatic code formatting.
  • WebAssembly Support: Utilizes Pyodide, enabling an extensive Python standard library without the need for additional installations.
  • Multithreaded Executions: Runs in a dedicated web worker, ensuring smooth user experiences by offloading heavy computations.
  • Auto-completion: Code suggestions are available for Python syntax in real-time, enhancing productivity during development.
  • Package Management: Installs Python packages on-demand with minimal setup, pulling directly from PyPI and accommodating a variety of use cases.

Motivation

The motivation behind x-Python stems from the complexities encountered in implementing Python solutions within browser environments effectively. This includes navigating challenges such as error handling, threading, and communication protocols between the main application and Python worker threads. x-Python is designed to address these issues, offering a robust framework for executing Python code and handling edge cases seamlessly.

Example Usage

Initializing x-Python

To initialize the x-Python environment:

import * as xPython from '@x-python/core';

await xPython.init();

Executing Python Code

Execute a simple expression:

await xPython.exec({ code: '1 + 1' });

Multiline Execution

For more complex code, including multiline support:

await xPython.exec({
  code: `
import sys
sys.version
`,
});

Code Completion

Utilizing the completion feature:

await xPython.complete.repl({ code: 'import sys; sys.ver' });

Additional Features

  • Code Formatting: Improve code quality with built-in formatting capabilities:
const { result } = await xPython.format({
  code: `
def add(a, b):
  return a + b
`,
});
console.log(result);
  • Package Installation: Easily install additional Python packages:
await xPython.install(['nicelog']);

Conclusion

The x-Python project represents a significant advancement in integrating Python into web applications. By providing a complete solution for running Python code in the browser, it equips developers with the tools necessary to create dynamic and interactive web applications seamlessly.

0 comments

No comments yet.

Sign in to be the first to comment.