Can you run Transcrypt and JavaScript at the same time?

93 views Asked by At

I need to create a program that is able to do things possible in python only (I.E. Editing local files) while also using javascript API's

Would i be able to:

A. access variables defined in Transcrypt and access them in Javascript and vice versa or

B. run functions from javascript in Transcrypt and vice versa

1

There are 1 answers

0
John S On

As far as your A & B questions, yes transpiled Python code can access JavaScript functions/variables and JavaScript can call transpiled Python code and access its variables. This actually works really well. I would recommend utilizing npm and Parcel or Webpack with the respective Transcrypt plug-in to manage the build process if you are using more than just one or two JavaScript libraries.

Note that Transcrypt is primarily intended to run code in a web browser, so you are limited to what programs can generally do in that environment - including limitations on local file access. If you are running the Javascript code in Node then, maybe.

Lastly, third party libraries are generally NOT supported (Numpy excepted via the NumScrypt project), and not all of the standard libraries have been ported yet. The exception to this, is if the third party library you want to use is pure python AND all of it's dependencies are pure python as well. There are not many that meet this qualification, as most have some dependency on a C-library somewhere in the dependency stack. Most of the Python built-ins and language constructs are available though.