Registry / web-framework / groovy

groovy

JSON →
library0.1.2pypypi✓ verified 23d ago

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 groovy
INSTALL
IMPORT
SIG · GROOVY
G
groovy
web-frameworkpythonv0.1.2
Install
1.6s avg
Import
46ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.046s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.046s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

transpile
from groovy import transpile

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; # }
Debug
Known issues
gotchaThis 'groovy' library (version 0.1.2) is a Python-to-JavaScript transpiler. Be aware of potential name collisions with other Python packages also named 'groovy' on PyPI that serve different purposes (e.g., a workflow automation tool or a Groovy language parser). Ensure you are installing and using the correct library for your needs.
fix
Verify the library's description on PyPI or its GitHub repository before installation to confirm it matches the intended functionality.
affects: All versions
gotchaGroovy does not provide full Python feature coverage; it supports only a subset of the Python standard library and some Gradio-specific classes. Attempting to transpile unsupported Python syntax will result in a `TranspilationError`.
fix
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.
affects: All versions
gotchaWhile Groovy aims to guarantee identical return values for transpiled functions, the internal JavaScript implementation may differ slightly from the Python version (e.g., Python tuples might be converted to JavaScript arrays). This can lead to unexpected behavior if introspection or strict type checking of the transpiled JavaScript's internal structure is performed.
fix
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.
affects: All versions
Errors
Common errors & fixes
TranspilationError: Unsupported syntax: The '...' feature is not supported by groovy.
The Python function you are attempting to transpile uses syntax or a standard library feature that the `groovy` transpiler (Python-to-JavaScript) does not support. `groovy` prioritizes clear error reporting over full Python feature coverage, supporting only a subset of Python.
fix
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.
Ambiguous operation: ... Please add type hints to resolve this ambiguity.
The `groovy` transpiler encountered an operation (e.g., the `+` operator) where its behavior in JavaScript is ambiguous without explicit type information. Python's dynamic typing can lead to situations where an operation could mean different things (e.g., string concatenation vs. numeric addition) in JavaScript.
fix
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.
ModuleNotFoundError: No module named 'groovy'
The `groovy` Python package is not installed in your current Python environment, or your environment's PYTHONPATH does not include the directory where it's installed.
fix
Install the `groovy` library using pip: `pip install groovy`
TranspilationError: Cannot transpile function with side effects that don't have a JS equivalent (e.g., 'print').
The Python function includes a call to a function that has a side effect (like `print()`) for which there is no direct or supported JavaScript equivalent that can run purely client-side within the `groovy`'s transpilation model. `groovy` will explicitly reject such functions to prevent unexpected behavior in the client.
fix
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.
Upgrade
Version history
0.1.2latest on PyPI · released Feb 28, 2025
Audit
Dependencies
pythonrequiredRequires Python 3.9 or higher for execution.
Agent activity
11 hits · last 30 days
node
10
Resources