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.
pip install groovyVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to transpile a simple Python function into its JavaScript equivalent using the `transpile` function.
Verify the library's description on PyPI or its GitHub repository before installation to confirm it matches the intended functionality.
Consult the official documentation for supported Python features and modify your Python functions accordingly to ensure successful transpilation. The library provides clear error reporting with line numbers.
Focus on the functional equivalence and return values of the transpiled code. Avoid making assumptions about the exact internal structure of the generated JavaScript unless explicitly documented as stable.
Refactor the Python function to use simpler, supported Python constructs. Avoid complex syntax, specific Python standard library modules not listed as compatible, or features like `print()` if running purely client-side without a console equivalent. Consult the `groovy` documentation for supported features.
Add explicit Python type hints to the function parameters and any local variables involved in the ambiguous operation to provide `groovy` with the necessary type information for correct transpilation.
Install the `groovy` library using pip: `pip install groovy`
Remove or replace the problematic side-effecting function call. For example, instead of `print()`, consider returning the value to be displayed in the UI or handling logging through Gradio's specific mechanisms if used within a Gradio application.