You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PythonMonkey is a Mozilla [SpiderMonkey](https://firefox-source-docs.mozilla.org/js/index.html) JavaScript engine embedded into the Python VM,
6
+
[PythonMonkey](https://pythonmonkey.io) is a Mozilla [SpiderMonkey](https://firefox-source-docs.mozilla.org/js/index.html) JavaScript engine embedded into the Python VM,
7
7
using the Python engine to provide the JS host environment.
8
8
9
-
This product is in an early stage, approximately 80% to MVP as of July 2023. It is under active development by Distributive Corp.,
10
-
https://distributive.network/. External contributions and feedback are welcome and encouraged.
9
+
This product is in an early stage, approximately 80% to MVP as of July 2023. It is under active development by [Distributive](https://distributive.network/).
10
+
External contributions and feedback are welcome and encouraged.
11
11
12
-
The goal is to make writing code in either JS or Python a developer preference, with libraries commonly used in either language
13
-
available eveywhere, with no significant data exchange or transformation penalties. For example, it should be possible to use NumPy
14
-
methods from a JS library, or to refactor a slow "hot loop" written in Python to execute in JS instead, taking advantage of
15
-
SpiderMonkey's JIT for near-native speed, rather than writing a C-language module for Python. At Distributive, we intend to use
16
-
this package to execute our complex `dcp-client` library, which is written in JS and enables distributed computing on the web stack.
12
+
### tl;dr
13
+
```bash
14
+
$ pip install pythonmonkey
15
+
```
16
+
```python
17
+
from pythonmonkey importevalas js_eval
18
+
19
+
js_eval("console.log")('hello, world')
20
+
```
21
+
22
+
### Goals
23
+
-**Fast** and memory-efficient
24
+
- Make writing code in either JS or Python a developer preference
25
+
- Use JavaScript libraries from Python
26
+
- Use Python libraries from JavaScript
27
+
- Same process runs both JS and Python VMs - no serialization, pipes, etc
17
28
18
29
### Data Interchange
19
30
- Strings share immutable backing stores whenever possible (when allocating engine choses UCS-2 or Latin-1 internal string representation) to keep memory consumption under control, and to make it possible to move very large strings between JS and Python library code without memory-copy overhead.
from datetime import date # You can use Python libraries.
296
+
exports['today'] = date.today()
297
+
```
298
+
299
+
# Troubleshooting Tips
250
300
251
301
## CommonJS (require)
252
302
If you are having trouble with the CommonJS require function, set environment variable DEBUG='ctx-module*'and you can see the filenames it tries to laod.
303
+
304
+
## pmjs
305
+
- there is a `.help` menu in the REPL
306
+
- there is a `--help` command-line option
307
+
- the `-r` option can be used to load a module before your program or the REPL runs
308
+
- the `-e` option can be used evaluate code -- e.g. define global variables -- before your program or the REPL runs
309
+
- The REPL can evaluate Python expressions, storing them in variables named `$1`, `$2`, etc. ```
0 commit comments