Pythonmonkey

Latest version: v0.6.0

Safety actively analyzes 623642 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 2

2.0

print(next(myit)) StopIteration exception

using a python iterator in JS:
py
import pythonmonkey as pm

myit = iter((1,2))
pm.eval("""
(myit) => {
console.log([...myit]); // [1, 2]
}
""")(myit)

1.0

0.6.0

- significant performance improvements, particularly in memory usage
- improved build system and build time, including making building the docs optional, and the following build types:
- **Release**: stripped symbols, maximum optimizations (default, what gets published on pip)
- **DRelease**: same as **Release**, except symbols are not stripped
- **Debug**: minimal optimizations
- **Profile**: same as **Debug**, except profiling is enabled
- fixed a bug where users with particularly old versions of PythonMonkey were unable to update to the latest release using pip unless they completely uninstalled PythonMonkey first

0.5.0

- fixed a bug where `pmjs -e` / `pmjs -p` was not able to call functions that require the event loop
- implemented [setInterval](https://developer.mozilla.org/en-US/docs/Web/API/setInterval) and [clearInterval](https://developer.mozilla.org/en-US/docs/Web/API/clearInterval)
- implemented further cross-language support for iterators (more widespread use of iterators, such as the for-of loop for arrays, was already working in previous versions)

using a JS iterator in python:
py
import pythonmonkey as pm

myit = pm.eval('(function* () { yield 1; yield 2; })')()

0.4.0

- fixed a bug where methods called on proxied JS objects would use `globalThis` for the value of `this`
- implemented proxying of arbitrary python objects in JavaScript, like so:
py
import pythonmonkey as pm

class Counter:
def __init__(self):
self.count = 0
def increment(self):
self.count = self.count + 1

counter = Counter()

pm.eval("""
(pyObject) => {
console.log(pyObject.count); // 0
pyObject.increment();
console.log(pyObject.count); // 1
}
""")(counter)

- implemented a new type called JSMethodProxy, which can be used to implement methods on python objects in JavaScript, like so:
py
import pythonmonkey as pm

jsFunc = pm.eval("(function() { this.count++; })")

class Counter:
def __init__(self):
self.count = 0
self.increment = pm.JSMethodProxy(jsFunc, self)

counter = Counter()
print(counter.count) 0
counter.increment()
print(counter.count) 1

- various garbage collection optimizations
- various memory leak fixes
- implemented complete cross-language stack traces
- `pm.eval` can now accept a file object as its first argument (such as an object returned by the `open()` python built-in), which is expected to be a javascript file
- when calling `pm.require` (or other requires created by `pm.createRequire`), .py CommonJS modules now have precedence over .js modules when there is a namespace collision
- `setTimeout` now returns a Node.js-style `Timeout` class for the timeout id, with `.ref()` and `.unref()` methods
- implemented `XMLHttpRequest.withCredentials`
- implemented `"json"` support for `XMLHttpRequest.responseType`
- implemented remaining standard `console` methods

0.3.0

Our JS Proxies now implement all Array and Object methods on Python Lists and Dicts, and our Python List and Dict subtypes implements operators and methods on JS Arrays and Objects.

One can now do
py
items = [1, 2, 3, 4, 5]
result = [None]
pm.eval("(result, arr) => {result[0] = arr.some((element) => element % 2 === 0)}")(result, items)
-> result[0] == True

and going the other way
py
a = pm.eval("([1,2,3,4,5,6])")
b = a[1:5]
-> b == [2,3,4,5]

We also have all the iterators returned by such methods as values() now working without making copies of the object being iterated upon

Page 1 of 2

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.