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'', PyJsHoistedNonPyName)
Answer from Piotr Dabkowski on Stack Overflow
🌐
Gitloop
gitloop.com › tool › javascript-to-python
JavaScript to Python Code Converter
Effortlessly convert JavaScript code to Python with our AI-powered converter. Simply paste your code, and with a single click, transform JavaScript scripts into fully functional Python code. Ideal for developers looking to streamline their workflow, our tool ensures fast, accurate, and reliable ...
🌐
CodeConvert AI
codeconvert.ai › python-to-javascript-converter
Free Python to JavaScript 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 JavaScript to Python just as easily by using our JavaScript to Python converter.
Discussions

Conversion from JavaScript to Python code? - Stack Overflow
I've seen people on SO wanting to use regexes for lots of things they shouldn't be used for... converting python to js takes the cake though. ... I recommend reviewing the answer of @Piotr Dabkows, I believe my answer is now superseded and out of date. ... You can translate JavaScript to Python ... 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
Python to JavaScript converter - Stack Overflow
One use case for a converter is to implement the same logic on the server (Python) and the client (Javascript). In our case we use it for example for calculation the shipping cost: this isdone in the client for display purposes, but prone to manipulation. So final shipping costs are calculated ... 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
People also ask

Can I convert Python to JavaScript automatically?
Yes. DocuWriter.ai's AI-powered converter analyzes your Python code and generates equivalent JavaScript code. It handles syntax differences (Indentation-based to C-style), type system changes (Dynamic, strong to Dynamic, weak), and common library mappings. Always review the output — automated conversion is a starting point, not a finished product.
🌐
docuwriter.ai
docuwriter.ai › python-to-javascript-code-converter
python to javascript - Code Converter
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 | ...
Can I also convert Python back to JavaScript?
Yes! CodeConvert AI supports bidirectional conversion. You can convert Python to JavaScript just as easily by using our Python to JavaScript converter.
🌐
codeconvert.ai
codeconvert.ai › javascript-to-python-converter
Free JavaScript to Python Converter — AI Code Translation | ...
🌐
CodeConvert AI
codeconvert.ai › javascript-to-python-converter
Free JavaScript to Python Converter — AI Code Translation | CodeConvert AI
Instantly convert JavaScript to Python code with AI. Free, fast, and accurate code translation — 60+ languages supported, no signup required.
🌐
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 ...
🌐
Docuwriter
docuwriter.ai › python-to-javascript-code-converter
python to javascript - Code Converter
Open the converter above and paste your Python source code into the input editor. ... Select JavaScript as the target language and click Convert to start the AI translation.
Find elsewhere
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'', 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

🌐
CodingFleet
codingfleet.com › code-converter › javascript › python
Javascript to Python Converter - CodingFleet
Convert your Javascript Code to Python. This exceptional AI-powered tool converts your Javascript code into Python 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.
🌐
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%
🌐
Javainuse
javainuse.com › js2py
Online JavaScript to Python Converter
JavaScript, often abbreviated JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. Python is a high-level, interpreted, general-purpose programming language.
🌐
InfoWorld
infoworld.com › home › software development › programming languages › python
How to convert Python to JavaScript (and back again) | InfoWorld
March 21, 2023 - Note that the last commits to the JavaScripthon project were in July 2022, though it has been updated to support Python 3.10 as its latest version. The Jiphy name is an abbreviation of “JavaScript in, Python out.” In other words, Jiphy converts in both directions between the two languages.
🌐
geemap
geemap.org › notebooks › 15_convert_js_to_py
15 convert js to py - geemap
geemap.js_snippet_to_py( js_snippet, add_new_cell=True, import_ee=True, import_geemap=True, show_map=True )
🌐
GitHub
github.com › PiotrDabkowski › Js2Py
GitHub - PiotrDabkowski/Js2Py: JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:
JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online: - PiotrDabkowski/Js2Py
Starred by 2.6K users
Forked by 276 users
Languages   JavaScript 65.1% | Python 34.9%
🌐
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 ...
🌐
Codeporting
products.codeporting.ai › convert › python-to-js
AI-Powered Python to JavaScript Snippet Converter
Conversion Python to JavaScript using AI involves utilizing natural language processing (NLP) techniques and machine learning algorithms to analyze and understand the Python code, source-to-source code translation may save your time
🌐
Tooljet
docs.tooljet.com › translating javascript objects to python in runpy
Translating JavaScript Objects to Python in RunPy | ToolJet
Once the app is created, navigate to the Query Panel, click on the + Add button and choose Run Python Code as the Data Source. Use the code given below, in the runpy query code editor: import pyodide # Import the Pyodide library def to_py(js_object): # Define a function to convert JavaScript objects to Python dictionaries return dict(js_object) # Convert the JavaScript object to a Python dictionary my_js_object = {"name": "John", "age": 25, "country": "USA"} # Create a JavaScript object my_py_dict = to_py(my_js_object) # Convert the JavaScript object to a Python dictionary my_py_dict # Return the Python dictionary
🌐
DEV Community
dev.to › best_codes › i-made-a-simple-javascript-to-python-converter-with-ai-3069
I made a simple JavaScript to Python Converter with AI - DEV Community
May 5, 2025 - First things first — if you just clicked on this post so you could see my project, here's the link: https://ai-code-converter-best.vercel.app/convert/js-to-python
🌐
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 › 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).