A small Python library created to help developers protect their applications from Server Side Request Forgery (SSRF) attacks.
Project description
🐻 Grompy
Grompy is a Python-to-JavaScript transpiler, meaning that it converts Python functions to their JavaScript equivalents. It is used in the Gradio library, so that developers can write functions in Python and have them run as fast as client-side JavaScript ⚡. Instead of aiming for full coverage of Python features, Grompy prioritizes clear error reporting for unsupported Python code, making it easier for developers to modify their functions accordingly.
🚀 Features
- Converts simple Python functions into JavaScript equivalents.
- Supports a subset of the Python standard library along with some Gradio-specific classes.
- Provides complete error reporting when a function can't be transpiled (either due to no equivalent in JavaScript or ambiguity).
📦 Installation
Install Grompy via pip:
pip install grompy
🔧 Usage
from grompy import transpile
def sum_range(n: int):
total = 0
for i in range(n):
total = total + i
return total
js_code = transpile(sum)
print(js_code)
produces:
function sum_range(n) {
let total = 0;
for (let i of Array.from({length: n}, (_, i) => i)) {
total = (total + i);
}
return total;
Note that the JavaScript function is not necessarily minimized or optimized (yet) but it should return exactly the same value when called with the same arguments.
If Grompy encounters unsupported syntax, it will complain clearly (throw a TranspilationError with all of the issues along with line numbers and the code that caused the issue, making it easy for developers to fix their code.
def example_function(x, y):
z = x + y
if z > 10:
print(z)
else:
print(0)
transpile(example_function)
raises:
TranspilerError: 2 issues found:
* Line 4: Unsupported function "print()"
>> print(z)
* Line 6: Unsupported function "print()"
>> print(0)
🤔 Ambiguity
Grompy takes a conservative approach when encountering ambiguous types. Instead of making assumptions about types, it will raise a TranspilationError. For example, a simple sum function without type hints will fail:
def sum(a, b):
return a + b
transpile(sum) # Raises TranspilationError: Cannot determine types for parameters 'a' and 'b'
This is because + could mean different things in JavaScript depending on the types (string concatenation vs numeric addition vs. custom behavior for a custom class). Adding type hints (which is strongly recommended for all usage) resolves the ambiguity:
def sum(a: int, b: int):
return a + b
transpile(sum) # Works! Produces: function sum(a, b) { return (a + b); }
📜 License
Grompy is open-source under the MIT License.
Contributions to increase coverage of the Python library that Grompy can transpile are welcome! We welcome AI-generated PRs if the rationale is clear to follow, PRs are not too large in scope, and tests are included.
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 grompy-0.0.5.tar.gz.
File metadata
- Download URL: grompy-0.0.5.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2caeeecaf240d4b8b545fe67ff8e538ae23c50280b91dc6f2595ca67fb2a8336
|
|
| MD5 |
6e190639d8c3b9cd5f8c79f35ae2b558
|
|
| BLAKE2b-256 |
450ddb7e0bfea3fcacc55e9e8609f95b686a4d4afc422d363493fce2ac9285ed
|
File details
Details for the file grompy-0.0.5-py3-none-any.whl.
File metadata
- Download URL: grompy-0.0.5-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a2da0a3a7c646a3347d64a7c2db6925c9beab8351304e2435d5c8f78e7b3e58
|
|
| MD5 |
8e3c8ea4c0902a5ebab5bd5b8f3b324d
|
|
| BLAKE2b-256 |
887e6636f9770617bdffdc9efad664ca4c36959e2dea38231f103774d0cb35ff
|