Releases: Distributive-Network/PythonMonkey
v0.7.0
- added a new build type:
- Sanitize: same as Debug, except with AddressSanitizer enabled
- added a new tool inspired by wtfnode called WTFPythonMonkey to track down any hanging
setTimeout/setIntervaltimers that are still ref'd when you hit ctrl-C.- When using
pmjs, to enable it you can simply pass the--wtfflag, like so:
pmjs --wtf <filename>.js
- When using pythonmonkey from python, it can be enabled by using a context manager (
with-statement) around the entry point of the event loop, like so:
import asyncio import pythonmonkey as pm from pythonmonkey.lib.wtfpm import WTF async def pythonmonkey_main(): pm.eval("setInterval(() => console.log(new Date), 500)") await pm.wait() with WTF(): asyncio.run(pythonmonkey_main())
- When using
- implemented JS-like function calling for python functions in JS. Similar to JS functions, you can now call python functions with too few or too many arguments without throwing an error.
- When too many arguments are supplied, those beyond the function's parameter count are ignored, e.g.:
def f(a, b): return [a, b] assert [1, 2] == pm.eval("(f) => f(1, 2, 3)")(f)
- When too few arguments are supplied, those beyond the number of supplied arguments are passed as
Noneto match JS's behaviour of passingundefined, e.g.:
def f(a, b): return [a, b] assert [1, None] == pm.eval("(f) => f(1)")(f)
- This also works for functions with default arguments, or varargs, e.g.:
def f(a, b, c=42, d=43, *args): return [a, b, c, d, *args] assert [1, 2, 3, 4, 5] == pm.eval("(f) => f(1, 2, 3, 4, 5)")(f) assert [1, 2, 3, 4 ] == pm.eval("(f) => f(1, 2, 3, 4)" )(f) assert [1, 2, 3, 43 ] == pm.eval("(f) => f(1, 2, 3)" )(f) assert [1, 2, 42, 43 ] == pm.eval("(f) => f(1, 2)" )(f) assert [1, None, 42, 43 ] == pm.eval("(f) => f(1)" )(f) assert [None, None, 42, 43 ] == pm.eval("(f) => f()" )(f)
- implemented the copy protocol (both
copy.copyandcopy.deepcopy) for JSStringProxies - using the aforementioned WTFPythonMonkey, we've fixed several bugs related to timers, including:
- the
Future object is not initializederror and following segfault - heap-use-after-free in
timerJobWrapper - hitting ctrl-C in
pmjsprinting out the entire PythonKeyboardInterrupttraceback - intervals from
setIntervalwere not being unref'd correctly
- the
- fixed a bug where uncaught JS Promise rejections would result in a
Future exception was never retrievedPython error, rather than the actual JS error - added support for
HTTP-Keep-Alivein our implementation ofXMLHttpRequest - fixed a memory leak related to cross-language strings
- fixed a bug where attempting to install Pythonmonkey from source failed on Ubuntu 24.04
- PythonMonkey now uses the bleeding edge version of SpiderMonkey on this and all future releases
- we now build and distribute binaries for python 3.8 on amd64 Mac OS
v0.6.0
PythonMonkey v0.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
v0.5.0
PythonMonkey v0.5.0
- fixed a bug where
pmjs -e/pmjs -pwas not able to call functions that require the event loop - implemented setInterval and 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:
import pythonmonkey as pm
myit = pm.eval('(function* () { yield 1; yield 2; })')()
print(next(myit)) # 1.0
print(next(myit)) # 2.0
print(next(myit)) # StopIteration exceptionusing a python iterator in JS:
import pythonmonkey as pm
myit = iter((1,2))
pm.eval("""
(myit) => {
console.log([...myit]); // [1, 2]
}
""")(myit)v0.4.0
PythonMonkey v0.4.0
- fixed a bug where methods called on proxied JS objects would use
globalThisfor the value ofthis - implemented proxying of arbitrary python objects in JavaScript, like so:
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:
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.evalcan now accept a file object as its first argument (such as an object returned by theopen()python built-in), which is expected to be a javascript file- when calling
pm.require(or other requires created bypm.createRequire), .py CommonJS modules now have precedence over .js modules when there is a namespace collision setTimeoutnow returns a Node.js-styleTimeoutclass for the timeout id, with.ref()and.unref()methods- implemented
XMLHttpRequest.withCredentials - implemented
"json"support forXMLHttpRequest.responseType - implemented remaining standard
consolemethods
v0.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
items = [1, 2, 3, 4, 5]
result = [None]
pm.eval("(result, arr) => {result[0] = arr.some((element) => element % 2 === 0)}")(result, items)
-> result[0] == Trueand going the other way
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
v0.2.3
This release adds a new type, JSArrayProxy, a subtype of list, to properly proxy JavaScript Arrays as python lists, including having all of the appropriate methods.
This release also adds new methods to JSObjectProxy to more closely match dict. It now has all the same methods as dict except for the following: keys(), items(), update(), and values(). These will be added soon in a future release.
v0.2.2
This release includes implementations for URLSearchParams, XMLHttpRequest, atob, btoa, setTimeout, and clearTimeout. It also adds python 3.12 compatibility, better stringification for cross-language objects, and adds an event loop to pmjs. Finally, it fixes a bug preventing some users from installing pythonmonkey from source distributions.
Debugger
First release!
Our first public release.
Check out here to see how to install and use the library, or here if you would like to compile a local version and/or contribute to the project!
Basic examples can be found in the /examples directory.
More advanced examples can be found in the dedicated repository https://github.com/Distributive-Network/PythonMonkey-examples
Example of a fullstack AES encryption and decryption app that uses the crypto-js NPM package can be found at https://github.com/Distributive-Network/PythonMonkey-Crypto-JS-Fullstack-Example
🐍🐒