Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Python from JavaScript

Is there a simple way to call Python libraries from JavaScript? Especially from the inside of a Firefox extension.

A good option to compile a pure Python library would also be great. I looked at Pyjamas, but it seems to offer only partial support for Python.

like image 838
Alex Brooks Avatar asked Dec 14 '09 14:12

Alex Brooks


People also ask

Can you call Python code from JavaScript?

Use ajax to Call Python From JavaScript. AJAX stands for Asynchronous JavaScript and XML. It utilizes the XMLHttpRequest object to communicate with servers. It can send and receive information in numerous formats, including HTML, XML, JSON, and text files.

Can I use Python and JavaScript together?

Yes, since js syntax is a bit familiar with python. If you want to do frontend with js, backend with python then learning both of them is okay. Btw, if you really want js, learn nodejs so that you can do both backend and frontend with it. If you want more backend power, you should learn python first.

How do you call a Python method in Java?

javabridge. CPython, that can be used to execute Python code. The class can be used within Java code called from the Python interpreter or it can be used within Java to run Python embedded in Java. The CPython class binds the Python interpreter to the JVM and provides the ability to execute Python scripts.


1 Answers

You may wish to look at the Titanium Desktop. It has a great API that allows you to call Python easily from within Javascript.

Eg:

<script type="text/python" src="myfile.py"/>

It uses the Kroll Python Bridge to extend and call the functions with simple <script> tags.

You can easily pass integers, floating point numbers, booleans, objects, it's all there.

The aforementioned link has several examples of its simple usage, and naturally it's available for download. :)

like image 170
Mark Mayo Avatar answered Oct 03 '22 07:10

Mark Mayo