You can actually run a Python interpreter directly in JS thanks to emscripten.

The project is called empythoned:

Empythoned is a build script that uses Emscripten to compile CPython for use in a browser. It attempts to compile the main interpreter as a single small executable and the whole standard library as dynamically loaded libraries.

but be warned:

The project is in its infancy. Right now the core interpreter works very well, but many of the libraries either don't work at all or contain various bugs.

Answer from DJG on Stack Overflow
🌐
CodeConvert AI
codeconvert.ai › python-to-javascript-converter
Free Python to JavaScript Converter — AI Code Translation | CodeConvert AI
Simply paste your Python code into the input box and click the Convert button. Our AI will analyze your Python code and produce equivalent JavaScript code in seconds, preserving the original logic and structure.
🌐
InfoWorld
infoworld.com › home › software development › programming languages › python
How to convert Python to JavaScript (and back again) | InfoWorld
March 21, 2023 - Thus RapydScript provides the best of both worlds, bringing Python’s clean syntax to JavaScript capabilities like anonymous functions, DOM manipulation, and the ability to leverage JavaScript libraries like jQuery or Node.js.
Discussions

Python to JavaScript converter - Stack Overflow
We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations. Closed 8 years ago. ... I want to convert some basic snippets to JavaScript, just pure Python I ... More on stackoverflow.com
🌐 stackoverflow.com
Conversion from JavaScript to Python code? - Stack Overflow
Is there a relatively quick program out there to accomplish at least the basics of this? Just a few regexes? I'm willing to do some manual conversion, but this is a pretty big set of scripts. More on stackoverflow.com
🌐 stackoverflow.com
node.js - How do I convert Python Code to JavaScript - Stack Overflow
I was trying to convert my code from Python to JS, because I want to use HTML with my JavaScript code. My question is, how do I convert this code from Python to JavaScript without parsing Python. S... More on stackoverflow.com
🌐 stackoverflow.com
Converting Python to Javascript
Honestly, "translation" tools are usually bad. It would probably be better for you and your project to learn the language and do it yourself :) More on reddit.com
🌐 r/Python
7
0
January 30, 2018
People also ask

Is the Python to JavaScript converter free?
Yes. You can convert Python to JavaScript for free without creating an account for up to 2 conversions per day. For more conversions and higher limits, sign in for free — every account gets 5 credits per day with support for up to 25,000 characters per conversion.
🌐
codeconvert.ai
codeconvert.ai › python-to-javascript-converter
Free Python to JavaScript Converter — AI Code Translation | ...
Can I also convert JavaScript back to Python?
Yes! CodeConvert AI supports bidirectional conversion. You can convert JavaScript to Python just as easily by using our JavaScript to Python converter.
🌐
codeconvert.ai
codeconvert.ai › python-to-javascript-converter
Free Python to JavaScript Converter — AI Code Translation | ...
How do I convert Python to JavaScript using CodeConvert AI?
Simply paste your Python code into the input box and click the Convert button. Our AI will analyze your Python code and produce equivalent JavaScript code in seconds, preserving the original logic and structure.
🌐
codeconvert.ai
codeconvert.ai › python-to-javascript-converter
Free Python to JavaScript Converter — AI Code Translation | ...
🌐
Gitloop
gitloop.com › tool › python-to-javascript
Python to JavaScript Code Converter
Effortlessly convert Python code to JavaScript with our AI-powered converter. Simply paste your code, and with a single click, transform Python scripts into fully functional JavaScript code. Ideal for developers looking to streamline their workflow, our tool ensures fast, accurate, and reliable ...
🌐
Transcrypt
transcrypt.org
Transcrypt - Python in the browser - Lean, fast, open!
The Transcrypt Python to JavaScript compiler makes it possible to program lean and fast browser applications in Python. Transcrypt applications can use any JavaScript library and can also run on top of Node.js or be used in combination with Django.
🌐
GitHub
github.com › majwilson › python-to-javascript
GitHub - majwilson/python-to-javascript: A tool that allows programmers to convert code written in Python into the equivalent code written in Javascript. · GitHub
A tool that allows programmers to convert code written in Python into the equivalent code written in Javascript. - majwilson/python-to-javascript
Starred by 27 users
Forked by 5 users
Languages   Python 94.3% | JavaScript 5.7%
Find elsewhere
🌐
GitHub
github.com › timothycrosley › jiphy
GitHub - timothycrosley/jiphy: Your client side done in a jiphy. Python to JavaScript 2-way converter.
Write your client side code in a Jiphy! Jiphy is a two-way Python->JavaScript converter. It's not meant to create executable Python code from complex JavaScript files, or runnable JavaScript from complex Python projects.
Starred by 586 users
Forked by 73 users
Languages   Python 98.7% | Shell 1.3% | Python 98.7% | Shell 1.3%
🌐
PyPI
pypi.org › project › javascripthon
javascripthon · PyPI
Usually it is used with tools like ... from the source code to the bundle are the following: JavaScripthon converts your Python 3.5+ code to ES6 JavaScript modules;...
      » pip install javascripthon
    
Published   Jul 04, 2024
Version   0.13
Top answer
1 of 4
39

You can translate JavaScript to Python using Js2Py. It supports whole JavaScript and you can use it to translate large JavaScript modules like esprima.js (a JavaScript 6 parser).


Short demo:

>>> import js2py
>>> f = js2py.eval_js( "function $(a) {return a + arguments[1]}" )
>>> f
function $(a) { [python code] }
>>> f(1, 2, 3)
3

This is how the translated function looks like internally (it's rather ugly):

>>> print js2py.translate_js( "function $(a) {return a + arguments[1]}" )
from js2py.pyjs import *
var = Scope( JS_BUILTINS )
set_global_object(var)
# Code follows:
var.registers([u'$'])
@Js
def PyJsHoistedNonPyName(a, this, arguments, var=var):
    var = Scope({u'a':a, u'this':this, u'arguments':arguments}, var)
    var.registers([u'a'])
    return (var.get(u'a')+var.get(u'arguments').get(u'1'))
PyJsHoistedNonPyName.func_name = u'$'
var.put(u'$', PyJsHoistedNonPyName)
2 of 4
20

Updated

Now several (4) years later this (almost certainly) can be done; though certainly not with RegEx. I suggest future readers look to @Piotr Dabkowski's answer.. Or some of the other answers. (I don't know having not tried them)


Original Answer

Hm this is a hard one. The definition of a compiler is translates from a higher level language to a lower level language. eg python to machine-code. or java to javascript (google has a rather famous compiler for this somewhere - its' what makes google doc easier to make) Python to javascript compilers abound. technically javascript to python would be a decompiler. (afaik)

I found some speculation about a javascript-python converter here: follow the tread through. it mostly speaks of how it wouldn't be too hard to do. I can't find anything , but that doesn't mean it's no out there.

Regex is not suitable, regex is suitable only for regular languages. programming languages are not normally regular languages. see this

🌐
ExtendsClass
extendsclass.com › python-to-javascript.html
Python to javascript converter
This tool allows you to convert your python source code into javascript code. For this conversion it uses JavaScripthon, a Python 3 to ES6 JavaScript translator.
🌐
Stack Overflow
stackoverflow.com › questions › 59021845 › how-do-i-convert-python-code-to-javascript
node.js - How do I convert Python Code to JavaScript - Stack Overflow
#Python Code import requests import json import datetime url = https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=jpmf&interval=60min&apikey=testkey response = requests.get(url) assert response.status_code == 200 data =json.loads(response.text) ... Check out fetch in JavaScript. ... @Phix She/He needs to convert python codes so the target is backend js engine ( like node).
🌐
CodeConvert AI
codeconvert.ai › javascript-to-python-converter
Free JavaScript to Python Converter — AI Code Translation | CodeConvert AI
For complex or performance-critical code, we recommend reviewing and testing the output. ... Yes! CodeConvert AI supports bidirectional conversion. You can convert Python to JavaScript just as easily by using our Python to JavaScript converter.
🌐
Javainuse
javainuse.com › py2js
Online Python to JavaScript Converter
Python is a high-level, interpreted, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. JavaScript, often abbreviated JS, is a programming language that is one of the core technologies of the World Wide Web, alongside ...
🌐
GitHub
github.com › PiotrDabkowski › Js2Py
GitHub - PiotrDabkowski/Js2Py: JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:
JavaScript 6 support was achieved by using Js2Py to translate javascript library called Babel. Babel translates JS 6 to JS 5 and afterwards Js2Py translates JS 5 to Python.
Starred by 2.6K users
Forked by 278 users
Languages   JavaScript 65.1% | Python 34.9%
🌐
Cafeto Website
cafetosoftware.com › home › resources › blogs › tools to convert python code to javascript (and vice versa)
Tools to Convert Python Code to JavaScript (and vice versa) - Cafeto Website
July 10, 2023 - In this blog, we give you a list of tools that will allow you to convert Python programming code to JavaScript (and vice versa). One of the promises that WebAssembly makes is to allow us to use whatever language we choose to develop for the web, although this is still a distant goal. The philosophy behind Brython, at least regarding Python 3, is why wait? Brython implements a version of Python 3 for client-side web programming through a JavaScript library that emulates all of the keywords and most of the built-in Python 3 functions.
🌐
CodingFleet
codingfleet.com › code-converter › python › javascript
Python to Javascript Converter - CodingFleet
Convert your Python Code to Javascript. This exceptional AI-powered tool converts your Python code into Javascript code easily, eliminating the need for manual re-coding. Save your precious time and unlock cross-platform development like never before with our converter tool.
🌐
Stack Overflow
stackoverflow.com › questions › 75683667 › brython-python-to-javascript-converter
Brython python to javascript converter - Stack Overflow
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <textarea name="input" id="input" cols="30" rows="10">Here write your python code...</textarea> <button id="convert" onclick="convert()">Convert</button> <textarea name="output" id="output" cols="30" rows="10">Here you will receive your javascript code...</textarea> <script> function convert(content) { var input = document.getElementById("input"); var output = document.g
🌐
Medium
medium.com › @techrobot45 › how-to-convert-python-to-javascript-and-back-again-3db7a143e49f
How to convert Python to JavaScript (and back again) | by The Tech Robot | Medium
December 13, 2023 - How to convert Python to JavaScript (and back again) RapydScript, Transcrypt, and Pyjs are among the tools available for translating Python code to JavaScript. These tools take Python code as input …
🌐
Quora
quora.com › Is-there-a-way-to-convert-Python-code-into-JavaScript
Is there a way to convert Python code into JavaScript? - Quora
Answer (1 of 9): Absolutely, and I’ve done it on a lot of projects myself. It’s a pretty straightforward process. 1. Learn Python 2. Learn JavaScript 3. Read the Python code 4. Write JavaScript that does the same thing There are tools to automate parts of that of course.