Groovy (Python-to-JavaScript Transpiler)

0.1.2 · active · verified Thu Apr 09

Groovy is a Python-to-JavaScript transpiler that converts Python functions to their JavaScript equivalents. It is primarily used within the Gradio library, allowing developers to write Python functions that execute efficiently as client-side JavaScript. The library prioritizes clear error reporting for unsupported Python code over full Python feature coverage. The current version is 0.1.2, with development appearing active due to its integration with Gradio.

Warnings

Install

Imports

Quickstart

This example demonstrates how to transpile a simple Python function into its JavaScript equivalent using the `transpile` function.

from groovy import transpile

def sum_range(n: int) -> int:
    total = 0
    for i in range(n):
        total = total + i
    return total

js_code = transpile(sum_range)
print(js_code)
# Expected output (may vary slightly in formatting):
# function sum_range(n) {
#   let total = 0;
#   for (let i of Array.from({length: n}, (_, i) => i)) {
#     total = (total + i);
#   }
#   return total;
# }

view raw JSON →